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

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

#133: Added installation tests: canonical_path metadata adding

  • Property svn:eol-style set to native
File size: 2.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 quintagroup.canonicalpath.interfaces import ICanonicalPath
15
16class TestCase(ptc.PloneTestCase):
17    class layer(PloneSite):
18        @classmethod
19        def setUp(cls):
20            import quintagroup.canonicalpath
21            fiveconfigure.debug_mode = True
22            zcml.load_config('configure.zcml', quintagroup.canonicalpath)
23            fiveconfigure.debug_mode = False
24
25ptc.setupPloneSite()
26
27class TestAdapter(TestCase):
28
29    def afterSetUp(self):
30        self.purl = getToolByName(self.portal, 'portal_url')
31
32    def testAdapter4Portal(self):
33        cpadapter = queryAdapter(self.portal, ICanonicalPath)
34        self.assertFalse(cpadapter is None,
35            "Can't get canonical path adapter for the plone site object")
36
37
38        portal_cp = '/'+'/'.join(self.purl.getRelativeContentPath(self.portal))
39        adcp = cpadapter.canonical_path()
40        self.assertTrue(adcp == portal_cp, "Canonical path adapter return '%s' "\
41            "for portal, must be: '%s'" % (adcp, portal_cp) )
42
43
44    def testAdapter4AT(self):
45        self.loginAsPortalOwner()
46        self.portal.invokeFactory('Document', id='my_doc')
47        self.logout()
48        my_doc = self.portal['my_doc']
49
50        cpadapter = queryAdapter(my_doc, ICanonicalPath)
51        self.assertFalse(cpadapter is None,
52            "Can't get canonical path adapter for the Document object")
53
54        mydoc_cp = '/'+'/'.join(self.purl.getRelativeContentPath(my_doc))
55        adcp = cpadapter.canonical_path()
56        self.assertTrue(adcp == mydoc_cp, "Canonical path adapter return '%s' "\
57            "for document, must be: '%s'" % (adcp, mydoc_cp) )
58
59class TestInstallation(TestCase):
60
61    def afterSetUp(self):
62        self.qi = self.portal.portal_quickinstaller
63        self.qi.installProduct("quintagroup.canonicalpath")
64
65        self.purl = getToolByName(self.portal, 'portal_url')
66        self.catalog = getToolByName(self.portal, 'portal_catalog')
67
68    def testCatalogMetadata(self):
69        self.assertTrue('canonical_path' in self.catalog._catalog.names,
70            "'canonical_path' metadata not added to catalog.")
71
72
73
74def test_suite():
75    return unittest.TestSuite([
76        unittest.makeSuite(TestAdapter),
77        unittest.makeSuite(TestInstallation),
78        ])
79
80if __name__ == '__main__':
81    unittest.main(defaultTest='test_suite')
Note: See TracBrowser for help on using the repository browser.