Changeset 2917 in products
- Timestamp:
- Oct 22, 2010 12:17:40 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.plonegooglesitemaps/branches/blacklist/quintagroup/plonegooglesitemaps/tests/testBlackoutList.py
r2915 r2917 24 24 25 25 26 def createTestContent(self): 27 # Add testing content to portal 28 for cont in [self.portal, self.folder]: 29 for i in range(1,4): 30 doc = _createObjectByType('Document', cont, id='doc%i' % i) 31 doc.edit(text_format='plain', text='hello world %i' % i) 32 self.workflow.doActionFor(doc, 'publish') 33 34 class TestDefaultFilters(TestCase): 26 class TestFilterMixin(TestCase): 35 27 36 28 def afterSetUp(self): 37 super(TestDefaultFilters, self).afterSetUp() 38 createTestContent(self) 29 super(TestFilterMixin, self).afterSetUp() 30 self.createTestContent() 31 self.sm = _createObjectByType('Sitemap', self.portal, id='google-sitemaps') 39 32 self.catres = self.portal.portal_catalog(portal_type=["Document",]) 40 33 self.logout() 41 34 35 def createTestContent(self): 36 # Add testing content to portal 37 for cont in [self.portal, self.folder]: 38 for i in range(1,4): 39 doc = _createObjectByType('Document', cont, id='doc%i' % i) 40 doc.edit(text_format='plain', text='hello world %i' % i) 41 self.workflow.doActionFor(doc, 'publish') 42 43 44 class TestDefaultFilters(TestFilterMixin): 45 46 def getPreparedLists(self, fname, fargs, checkindex): 47 futil = queryUtility(IBlackoutFilterUtility, name=fname) 48 filtered = [f.getPath() for f in futil.filterOut(self.catres, fkey=fargs)] 49 catpaths = [c.getPath() for c in self.catres] 50 excluded = [c.getPath() for c in self.catres if checkindex(c) == fargs] 51 map(lambda l:l.sort(), [catpaths, filtered, excluded]) 52 return catpaths, filtered, excluded 53 42 54 def testIdFilter(self): 43 idfilter = queryUtility(IBlackoutFilterUtility, name=idfname) 44 catpaths = [c.getPath() for c in self.catres] 45 filtered = [f.getPath() for f in idfilter.filterOut(self.catres, fkey="doc1")] 46 excluded = [c.getPath() for c in self.catres if c.id == "doc1"] 47 map(lambda l:l.sort(), [catpaths, filtered, excluded]) 55 catpaths, filtered, excluded = self.getPreparedLists(idfname, "doc1", 56 lambda b: b.id) 48 57 self.assertTrue(type(filtered) in [ListType, TupleType], 49 58 'Object type, returned by filteredOut method of "%s" utility '\ … … 54 63 55 64 def testPathFilter(self): 56 pathfilter = queryUtility(IBlackoutFilterUtility, name=pathfname) 57 catpaths = [c.getPath() for c in self.catres] 58 filtered = [f.getPath() for f in pathfilter.filterOut(self.catres, fkey="/plone/doc1")] 59 excluded = [c.getPath() for c in self.catres if c.getPath() == "/plone/doc1"] 60 map(lambda l:l.sort(), [catpaths, filtered, excluded]) 65 catpaths, filtered, excluded = self.getPreparedLists(pathfname, 66 "/plone/doc1", lambda b: b.getPath()) 61 67 self.assertTrue(type(filtered) in [ListType, TupleType], 62 68 'Object type, returned by filteredOut method of "%s" utility '\ … … 67 73 68 74 69 class TestFormDataProcessing(Test Case):75 class TestFormDataProcessing(TestFilterMixin): 70 76 71 77 def afterSetUp(self): 72 78 super(TestFormDataProcessing, self).afterSetUp() 73 createTestContent(self) 74 # Add sitemap object 75 self.sm = _createObjectByType('Sitemap', self.portal, id='google-sitemaps') 79 self.loginAsPortalOwner() 76 80 self.smview = queryMultiAdapter((self.sm, self.app.REQUEST), name="sitemap.xml") 77 self.catres = self.portal.portal_catalog(portal_type=["Document",]) 81 82 def getPreparedLists(self, bl, fargs, checkindex): 83 self.sm.edit(blackout_list=bl) 84 filtered = [f['url'] for f in self.smview.results()] 85 catpaths = [c.getURL() for c in self.catres] 86 excluded = [c.getURL() for c in self.catres if checkindex(c) == fargs] 87 map(lambda l:l.sort(), [catpaths, filtered, excluded]) 88 return catpaths, filtered, excluded 78 89 79 90 def testGetNamedFilterUtility(self): 80 self.sm.edit(blackout_list="path:/plone/doc1") 81 filtered = [f['url'] for f in self.smview.results()] 82 catpaths = [c.getURL() for c in self.catres] 83 excluded = [c.getURL() for c in self.catres \ 84 if c.getPath() == "/plone/doc1"] 85 map(lambda l:l.sort(), [catpaths, filtered, excluded]) 91 catpaths, filtered, excluded = self.getPreparedLists("path:/plone/doc1", 92 "/plone/doc1", lambda b: b.getPath()) 86 93 self.assertTrue(set(catpaths)-set(filtered) == set(excluded), 87 94 'Wrong filtered-out by "%s" filter:\nsrc %s\nres %s\nexcluded %s' % ( … … 89 96 90 97 def testDefaultFilterUtility(self): 91 self.sm.edit(blackout_list="id:doc1") 92 filtered = [f['url'] for f in self.smview.results()] 93 catpaths = [c.getURL() for c in self.catres] 94 excluded = [c.getURL() for c in self.catres if c.id == "doc1"] 95 map(lambda l:l.sort(), [catpaths, filtered, excluded]) 98 catpaths, filtered, excluded = self.getPreparedLists("id:doc1", 99 "doc1", lambda b: b.id) 96 100 self.assertTrue(set(catpaths)-set(filtered) == set(excluded), 97 101 'Wrong filtered-out by "%s" filter:\nsrc %s\nres %s\nexcluded %s' % ( 98 102 idfname, catpaths, filtered, excluded)) 99 103 # Now check is output of unnamed filter same to id-named one. 100 self.sm.edit(blackout_list=" id:doc1")104 self.sm.edit(blackout_list="doc1") 101 105 filtered_def = [f['url'] for f in self.smview.results()] 102 106 filtered_def.sort()
Note: See TracChangeset
for help on using the changeset viewer.