Changeset 2917 in products


Ignore:
Timestamp:
Oct 22, 2010 12:17:40 PM (14 years ago)
Author:
mylan
Message:

#228: Simplify blacklists filter utility tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.plonegooglesitemaps/branches/blacklist/quintagroup/plonegooglesitemaps/tests/testBlackoutList.py

    r2915 r2917  
    2424 
    2525 
    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): 
     26class TestFilterMixin(TestCase): 
    3527 
    3628    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') 
    3932        self.catres = self.portal.portal_catalog(portal_type=["Document",]) 
    4033        self.logout() 
    4134 
     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 
     44class 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 
    4254    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) 
    4857        self.assertTrue(type(filtered) in [ListType, TupleType], 
    4958            'Object type, returned by filteredOut method of "%s" utility '\ 
     
    5463 
    5564    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()) 
    6167        self.assertTrue(type(filtered) in [ListType, TupleType], 
    6268            'Object type, returned by filteredOut method of "%s" utility '\ 
     
    6773 
    6874 
    69 class TestFormDataProcessing(TestCase): 
     75class TestFormDataProcessing(TestFilterMixin): 
    7076 
    7177    def afterSetUp(self): 
    7278        super(TestFormDataProcessing, self).afterSetUp() 
    73         createTestContent(self) 
    74         # Add sitemap object 
    75         self.sm = _createObjectByType('Sitemap', self.portal, id='google-sitemaps') 
     79        self.loginAsPortalOwner() 
    7680        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 
    7889 
    7990    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()) 
    8693        self.assertTrue(set(catpaths)-set(filtered) == set(excluded), 
    8794            'Wrong filtered-out by "%s" filter:\nsrc %s\nres %s\nexcluded %s' % ( 
     
    8996 
    9097    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) 
    96100        self.assertTrue(set(catpaths)-set(filtered) == set(excluded), 
    97101            'Wrong filtered-out by "%s" filter:\nsrc %s\nres %s\nexcluded %s' % ( 
    98102             idfname, catpaths, filtered, excluded)) 
    99103        # 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") 
    101105        filtered_def = [f['url'] for f in self.smview.results()] 
    102106        filtered_def.sort() 
Note: See TracChangeset for help on using the changeset viewer.