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 | |
---|
71 | # class TestInstallation(TestCase): |
---|
72 | |
---|
73 | # def afterSetUp(self): |
---|
74 | # self.qi = self.portal.portal_quickinstaller |
---|
75 | # self.qi.installProduct("quintagroup.canonicalpath") |
---|
76 | |
---|
77 | # self.purl = getToolByName(self.portal, 'portal_url') |
---|
78 | # self.catalog = getToolByName(self.portal, 'portal_catalog') |
---|
79 | |
---|
80 | # def testCatalogMetadata(self): |
---|
81 | # self.assertTrue('canonical_path' in self.catalog._catalog.names, |
---|
82 | # "'canonical_path' metadata not added to catalog.") |
---|
83 | |
---|
84 | # def testIndexer(self): |
---|
85 | # self.loginAsPortalOwner() |
---|
86 | # my_doc = makeContent(self.portal, portal_type='Document', id='my_doc') |
---|
87 | # my_doc.update(title='My document') |
---|
88 | |
---|
89 | # cpadapter = queryAdapter(my_doc, ICanonicalPath) |
---|
90 | # cpmydoc = cpadapter.canonical_path() |
---|
91 | # cpbrain = self.catalog(path='/'+my_doc.absolute_url(1))[0].canonical_path |
---|
92 | # self.assertTrue(cpmydoc == cpbrain, |
---|
93 | # "Canonical Path from adapter: '%s' not equals with brains data: '%s'" % ( |
---|
94 | # cpmydoc, cpbrain)) |
---|
95 | |
---|
96 | # self.logout() |
---|
97 | |
---|
98 | # def testCatalogUpdateOnInstallation(self): |
---|
99 | # self.loginAsPortalOwner() |
---|
100 | # fp = self.portal['front-page'] |
---|
101 | # cpadapter = queryAdapter(fp, ICanonicalPath) |
---|
102 | # cpfp = cpadapter.canonical_path() |
---|
103 | # cpbrain = self.catalog(path='/'+fp.absolute_url(1))[0].canonical_path |
---|
104 | # self.assertTrue(cpfp == cpbrain, |
---|
105 | # "Catalog not updated on installation: canonical path from adapter: " \ |
---|
106 | # "'%s' not equal to brain data: '%s'" % (cpfp, cpbrain)) |
---|
107 | |
---|
108 | # self.logout() |
---|
109 | |
---|
110 | |
---|
111 | def test_suite(): |
---|
112 | return unittest.TestSuite([ |
---|
113 | unittest.makeSuite(TestAdapter), |
---|
114 | #unittest.makeSuite(TestInstallation), |
---|
115 | ]) |
---|
116 | |
---|
117 | if __name__ == '__main__': |
---|
118 | unittest.main(defaultTest='test_suite') |
---|