source: products/quintagroup.plonegooglesitemaps/branches/blacklist/quintagroup/plonegooglesitemaps/tests/testBlackoutList.py @ 2911

Last change on this file since 2911 was 2911, checked in by mylan, 14 years ago

#228: Added tests for default id and path filters

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1#
2# Tests related to general Sitemap type.
3#
4from base import *
5from types import ListType, TupleType
6from zope.component import queryUtility
7
8from Products.CMFPlone.utils import _createObjectByType
9from quintagroup.plonegooglesitemaps.config import BLACKOUT_PREFIX
10from quintagroup.plonegooglesitemaps.interfaces import IBlackoutFilterUtility
11
12idfname = BLACKOUT_PREFIX + "id"
13pathfname = BLACKOUT_PREFIX + "path"
14
15class TestBOFilterUtilities(TestCase):
16
17    def testDefaultIdUtility(self):
18        self.assertTrue(queryUtility(IBlackoutFilterUtility, name=idfname) is not None,
19            "Not registered default '%s' IBlackoutFilterUtility" % idfname)
20
21    def testDefaultPathUtility(self):
22        self.assertTrue(queryUtility(IBlackoutFilterUtility, name=pathfname) is not None,
23            "Not registered default '%s' IBlackoutFilterUtility" % pathfname)
24
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       
65
66def test_suite():
67    from unittest import TestSuite, makeSuite
68    suite = TestSuite()
69    suite.addTest(makeSuite(TestBOFilterUtilities))
70    suite.addTest(makeSuite(TestDefaultFilters))
71    return suite
72
73if __name__ == '__main__':
74    unittest.main(defaultTest='test_suite')
75#    framework()
Note: See TracBrowser for help on using the repository browser.