source: products/quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/tests.py @ 1704

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

#133: Added test for catalog updation on installation

  • Property svn:eol-style set to native
File size: 3.7 KB
Line 
1import unittest
2
3from zope.testing import doctestunit
4from zope.component import testing
5from zope.component import queryAdapter
6from Testing import ZopeTestCase as ztc
7
8from Products.Five import zcml
9from Products.Five import fiveconfigure
10from Products.CMFCore.utils import getToolByName
11from Products.PloneTestCase import PloneTestCase as ptc
12from Products.PloneTestCase.layer import PloneSite
13
14from Products.Archetypes.tests.utils import makeContent
15
16from quintagroup.canonicalpath.interfaces import ICanonicalPath
17
18class TestCase(ptc.PloneTestCase):
19    class layer(PloneSite):
20        @classmethod
21        def setUp(cls):
22            import quintagroup.canonicalpath
23            fiveconfigure.debug_mode = True
24            zcml.load_config('configure.zcml', quintagroup.canonicalpath)
25            fiveconfigure.debug_mode = False
26
27ptc.setupPloneSite()
28
29class TestAdapter(TestCase):
30
31    def afterSetUp(self):
32        self.purl = getToolByName(self.portal, 'portal_url')
33
34    def testAdapter4Portal(self):
35        cpadapter = queryAdapter(self.portal, ICanonicalPath)
36        self.assertFalse(cpadapter is None,
37            "Can't get canonical path adapter for the plone site object")
38
39
40        portal_cp = '/'+'/'.join(self.purl.getRelativeContentPath(self.portal))
41        adcp = cpadapter.canonical_path()
42        self.assertTrue(adcp == portal_cp, "Canonical path adapter return '%s' "\
43            "for portal, must be: '%s'" % (adcp, portal_cp) )
44
45
46    def testAdapter4AT(self):
47        self.loginAsPortalOwner()
48        my_doc = makeContent(self.portal, portal_type='Document', id='my_doc')
49        self.logout()
50
51        cpadapter = queryAdapter(my_doc, ICanonicalPath)
52        self.assertFalse(cpadapter is None,
53            "Can't get canonical path adapter for the Document object")
54
55        mydoc_cp = '/'+'/'.join(self.purl.getRelativeContentPath(my_doc))
56        adcp = cpadapter.canonical_path()
57        self.assertTrue(adcp == mydoc_cp, "Canonical path adapter return '%s' "\
58            "for document, must be: '%s'" % (adcp, mydoc_cp) )
59
60class TestInstallation(TestCase):
61
62    def afterSetUp(self):
63        self.qi = self.portal.portal_quickinstaller
64        self.qi.installProduct("quintagroup.canonicalpath")
65
66        self.purl = getToolByName(self.portal, 'portal_url')
67        self.catalog = getToolByName(self.portal, 'portal_catalog')
68
69    def testCatalogMetadata(self):
70        self.assertTrue('canonical_path' in self.catalog._catalog.names,
71            "'canonical_path' metadata not added to catalog.")
72
73    def testIndexer(self):
74        self.loginAsPortalOwner()
75        my_doc = makeContent(self.portal, portal_type='Document', id='my_doc')
76        my_doc.update(title='My document')
77
78        cpadapter = queryAdapter(my_doc, ICanonicalPath)
79        cpmydoc = cpadapter.canonical_path()
80        cpbrain = self.catalog(path='/'+my_doc.absolute_url(1))[0].canonical_path
81        self.assertTrue(cpmydoc == cpbrain,
82            "Canonical Path from adapter: '%s' not equals with brains data: '%s'" % (
83             cpmydoc, cpbrain))
84
85        self.logout()
86
87    def testCatalogUpdateOnInstallation(self):
88        self.loginAsPortalOwner()
89        fp = self.portal['front-page']
90        cpadapter = queryAdapter(fp, ICanonicalPath)
91        cpfp = cpadapter.canonical_path()
92        cpbrain = self.catalog(path='/'+fp.absolute_url(1))[0].canonical_path
93        self.assertTrue(cpfp == cpbrain,
94            "Catalog not updated on installation: canonical path from adapter: " \
95            "'%s' not equal to brain data: '%s'" % (cpfp, cpbrain))
96
97        self.logout()
98
99
100def test_suite():
101    return unittest.TestSuite([
102        unittest.makeSuite(TestAdapter),
103        unittest.makeSuite(TestInstallation),
104        ])
105
106if __name__ == '__main__':
107    unittest.main(defaultTest='test_suite')
Note: See TracBrowser for help on using the repository browser.