1 | import unittest |
---|
2 | |
---|
3 | from zope.testing import doctestunit |
---|
4 | from zope.component import testing |
---|
5 | from zope.component import queryAdapter |
---|
6 | from Testing import ZopeTestCase as ztc |
---|
7 | |
---|
8 | from Products.Five import zcml |
---|
9 | from Products.Five import fiveconfigure |
---|
10 | from Products.CMFCore.utils import getToolByName |
---|
11 | from Products.PloneTestCase import PloneTestCase as ptc |
---|
12 | from Products.PloneTestCase.layer import PloneSite |
---|
13 | |
---|
14 | from quintagroup.canonicalpath.interfaces import ICanonicalPath |
---|
15 | |
---|
16 | class 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 | |
---|
25 | ptc.setupPloneSite() |
---|
26 | |
---|
27 | class 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 | |
---|
59 | class 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 | |
---|
74 | def test_suite(): |
---|
75 | return unittest.TestSuite([ |
---|
76 | unittest.makeSuite(TestAdapter), |
---|
77 | unittest.makeSuite(TestInstallation), |
---|
78 | ]) |
---|
79 | |
---|
80 | if __name__ == '__main__': |
---|
81 | unittest.main(defaultTest='test_suite') |
---|