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