Changeset 2911 in products


Ignore:
Timestamp:
Oct 22, 2010 8:58:53 AM (14 years ago)
Author:
mylan
Message:

#228: Added tests for default id and path filters

Location:
quintagroup.plonegooglesitemaps/branches/blacklist/quintagroup/plonegooglesitemaps/tests
Files:
2 edited

Legend:

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

    r2841 r2911  
    8181 
    8282    def beforeTearDown(self): 
    83         if self.orig_mobile_ifaces is not None: 
     83        if getattr(self, 'orig_mobile_ifaces', None) is not None: 
    8484            mobilesitemapview.MOBILE_INTERFACES = self.orig_mobile_ifaces 
    8585 
  • quintagroup.plonegooglesitemaps/branches/blacklist/quintagroup/plonegooglesitemaps/tests/testBlackoutList.py

    r2909 r2911  
    33# 
    44from base import * 
     5from types import ListType, TupleType 
    56from zope.component import queryUtility 
    67 
     8from Products.CMFPlone.utils import _createObjectByType 
    79from quintagroup.plonegooglesitemaps.config import BLACKOUT_PREFIX 
    810from quintagroup.plonegooglesitemaps.interfaces import IBlackoutFilterUtility 
    911 
     12idfname = BLACKOUT_PREFIX + "id" 
     13pathfname = BLACKOUT_PREFIX + "path" 
    1014 
    1115class TestBOFilterUtilities(TestCase): 
    1216 
    1317    def testDefaultIdUtility(self): 
    14         uname = BLACKOUT_PREFIX + "id" 
    15         self.assertTrue(queryUtility(IBlackoutFilterUtility, name=uname) is not None, 
    16             "Not registered default '%s' IBlackoutFilterUtility" % uname) 
     18        self.assertTrue(queryUtility(IBlackoutFilterUtility, name=idfname) is not None, 
     19            "Not registered default '%s' IBlackoutFilterUtility" % idfname) 
    1720 
    1821    def testDefaultPathUtility(self): 
    19         uname = BLACKOUT_PREFIX + "path" 
    20         self.assertTrue(queryUtility(IBlackoutFilterUtility, name=uname) is not None, 
    21             "Not registered default '%s' IBlackoutFilterUtility" % uname) 
     22        self.assertTrue(queryUtility(IBlackoutFilterUtility, name=pathfname) is not None, 
     23            "Not registered default '%s' IBlackoutFilterUtility" % pathfname) 
    2224 
     25 
     26class TestDefaultFilters(TestCase): 
     27 
     28    def afterSetUp(self): 
     29        self.loginAsPortalOwner() 
     30        # Add testing content to portal 
     31        for cont in [self.portal, self.folder]: 
     32            for i in range(1,4): 
     33                doc = _createObjectByType('Document', cont, id='my_doc%i' % i) 
     34                doc.edit(text_format='plain', text='hello world %i' % i) 
     35        self.catres = self.portal.portal_catalog(portal_type=["Document",]) 
     36        self.logout() 
     37 
     38    def testIdFilter(self): 
     39        idfilter = queryUtility(IBlackoutFilterUtility, name=idfname) 
     40        catpaths = [c.getPath() for c in self.catres] 
     41        filtered = [f.getPath() for f in idfilter.filterOut(self.catres, fkey="my_doc1")] 
     42        excluded = [c.getPath() for c in self.catres if c.id == "my_doc1"] 
     43        map(lambda l:l.sort(), [catpaths, filtered, excluded]) 
     44        self.assertTrue(type(filtered) in [ListType, TupleType], 
     45            'Object type, returned by filteredOut method of "%s" utility '\ 
     46            'not list nor tuple' % idfname) 
     47        self.assertTrue(set(catpaths)-set(filtered) == set(excluded), 
     48            'Wrong filtered-out by "%s" filter:\nsrc %s\nres %s\nexcluded %s' % ( 
     49             idfname, catpaths, filtered, excluded)) 
     50 
     51    def testPathFilter(self): 
     52        pathfilter = queryUtility(IBlackoutFilterUtility, name=pathfname) 
     53        catpaths = [c.getPath() for c in self.catres] 
     54        filtered = [f.getPath() for f in pathfilter.filterOut(self.catres, fkey="/plone/my_doc1")] 
     55        excluded = [c.getPath() for c in self.catres if c.getPath() == "/plone/my_doc1"] 
     56        map(lambda l:l.sort(), [catpaths, filtered, excluded]) 
     57        self.assertTrue(type(filtered) in [ListType, TupleType], 
     58            'Object type, returned by filteredOut method of "%s" utility '\ 
     59            'not list nor tuple' % pathfname) 
     60        self.assertTrue(set(catpaths)-set(filtered) == set(excluded), 
     61            'Wrong filtered-out by "%s" filter:\nsrc %s\nres %s\nexcluded %s' % ( 
     62             pathfname, catpaths, filtered, excluded)) 
     63         
     64         
    2365 
    2466def test_suite(): 
     
    2668    suite = TestSuite() 
    2769    suite.addTest(makeSuite(TestBOFilterUtilities)) 
     70    suite.addTest(makeSuite(TestDefaultFilters)) 
    2871    return suite 
    2972 
Note: See TracChangeset for help on using the changeset viewer.