1 | import unittest |
---|
2 | |
---|
3 | from zope.testing import doctestunit |
---|
4 | from zope.component import testing |
---|
5 | from zope.component import queryAdapter, queryMultiAdapter |
---|
6 | from plone.indexer.interfaces import IIndexableObject |
---|
7 | from Testing import ZopeTestCase as ztc |
---|
8 | |
---|
9 | from Products.Five import zcml |
---|
10 | from Products.Five import fiveconfigure |
---|
11 | from Products.CMFCore.utils import getToolByName |
---|
12 | from Products.PloneTestCase import PloneTestCase as ptc |
---|
13 | from Products.PloneTestCase.layer import PloneSite |
---|
14 | |
---|
15 | from Products.Archetypes.tests.utils import makeContent |
---|
16 | |
---|
17 | from quintagroup.canonicalpath.interfaces import ICanonicalPath |
---|
18 | |
---|
19 | class TestCase(ptc.PloneTestCase): |
---|
20 | class layer(PloneSite): |
---|
21 | @classmethod |
---|
22 | def setUp(cls): |
---|
23 | import quintagroup.canonicalpath |
---|
24 | fiveconfigure.debug_mode = True |
---|
25 | zcml.load_config('configure.zcml', quintagroup.canonicalpath) |
---|
26 | fiveconfigure.debug_mode = False |
---|
27 | |
---|
28 | ptc.setupPloneSite() |
---|
29 | |
---|
30 | class TestAdapter(TestCase): |
---|
31 | |
---|
32 | def afterSetUp(self): |
---|
33 | self.loginAsPortalOwner() |
---|
34 | self.my_doc = makeContent(self.portal, portal_type='Document', id='my_doc') |
---|
35 | self.purl = getToolByName(self.portal, 'portal_url') |
---|
36 | self.catalog = getToolByName(self.portal, 'portal_catalog') |
---|
37 | self.logout() |
---|
38 | |
---|
39 | def testAdapter4Portal(self): |
---|
40 | cpadapter = queryAdapter(self.portal, ICanonicalPath) |
---|
41 | self.assertFalse(cpadapter is None, |
---|
42 | "Can't get canonical path adapter for the plone site object") |
---|
43 | |
---|
44 | |
---|
45 | portal_cp = '/'+'/'.join(self.purl.getRelativeContentPath(self.portal)) |
---|
46 | adcp = cpadapter.canonical_path() |
---|
47 | self.assertTrue(adcp == portal_cp, "Canonical path adapter return '%s' "\ |
---|
48 | "for portal, must be: '%s'" % (adcp, portal_cp) ) |
---|
49 | |
---|
50 | |
---|
51 | def testAdapter4AT(self): |
---|
52 | cpadapter = queryAdapter(self.my_doc, ICanonicalPath) |
---|
53 | self.assertFalse(cpadapter is None, |
---|
54 | "Can't get canonical path adapter for the Document object") |
---|
55 | |
---|
56 | mydoc_cp = '/'+'/'.join(self.purl.getRelativeContentPath(self.my_doc)) |
---|
57 | adcp = cpadapter.canonical_path() |
---|
58 | self.assertTrue(adcp == mydoc_cp, "Canonical path adapter return '%s' "\ |
---|
59 | "for document, must be: '%s'" % (adcp, mydoc_cp) ) |
---|
60 | |
---|
61 | |
---|
62 | def testIndexerRegistration(self): |
---|
63 | wrapper = queryMultiAdapter((self.portal, self.catalog), IIndexableObject) |
---|
64 | self.assertFalse(wrapper is None, "No indexer registered for portal object") |
---|
65 | |
---|
66 | wrapper = queryMultiAdapter((self.my_doc, self.catalog), IIndexableObject) |
---|
67 | self.assertFalse(wrapper is None, "No indexer registered for document object") |
---|
68 | |
---|
69 | |
---|
70 | def test_suite(): |
---|
71 | return unittest.TestSuite([ |
---|
72 | unittest.makeSuite(TestAdapter), |
---|
73 | ]) |
---|
74 | |
---|
75 | if __name__ == '__main__': |
---|
76 | unittest.main(defaultTest='test_suite') |
---|