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

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

#133: fix typo

  • Property svn:eol-style set to native
File size: 3.2 KB
RevLine 
[782]1import unittest
2
3from zope.testing import doctestunit
4from zope.component import testing
[1700]5from zope.component import queryAdapter
[782]6from Testing import ZopeTestCase as ztc
7
[1699]8from Products.Five import zcml
9from Products.Five import fiveconfigure
[1700]10from Products.CMFCore.utils import getToolByName
[1699]11from Products.PloneTestCase import PloneTestCase as ptc
12from Products.PloneTestCase.layer import PloneSite
13
[1702]14from Products.Archetypes.tests.utils import makeContent
15
[1700]16from quintagroup.canonicalpath.interfaces import ICanonicalPath
[1699]17
18class TestCase(ptc.PloneTestCase):
19    class layer(PloneSite):
20        @classmethod
21        def setUp(cls):
[1700]22            import quintagroup.canonicalpath
[1699]23            fiveconfigure.debug_mode = True
[1700]24            zcml.load_config('configure.zcml', quintagroup.canonicalpath)
[1699]25            fiveconfigure.debug_mode = False
26
[1700]27ptc.setupPloneSite()
[1699]28
[1700]29class TestAdapter(TestCase):
[1699]30
[1700]31    def afterSetUp(self):
32        self.purl = getToolByName(self.portal, 'portal_url')
[782]33
[1700]34    def testAdapter4Portal(self):
35        cpadapter = queryAdapter(self.portal, ICanonicalPath)
36        self.assertFalse(cpadapter is None,
37            "Can't get canonical path adapter for the plone site object")
[782]38
39
[1700]40        portal_cp = '/'+'/'.join(self.purl.getRelativeContentPath(self.portal))
41        adcp = cpadapter.canonical_path()
42        self.assertTrue(adcp == portal_cp, "Canonical path adapter return '%s' "\
43            "for portal, must be: '%s'" % (adcp, portal_cp) )
[1699]44
[782]45
[1700]46    def testAdapter4AT(self):
47        self.loginAsPortalOwner()
[1702]48        my_doc = makeContent(self.portal, portal_type='Document', id='my_doc')
[1700]49        self.logout()
[782]50
[1700]51        cpadapter = queryAdapter(my_doc, ICanonicalPath)
52        self.assertFalse(cpadapter is None,
53            "Can't get canonical path adapter for the Document object")
54
55        mydoc_cp = '/'+'/'.join(self.purl.getRelativeContentPath(my_doc))
56        adcp = cpadapter.canonical_path()
57        self.assertTrue(adcp == mydoc_cp, "Canonical path adapter return '%s' "\
58            "for document, must be: '%s'" % (adcp, mydoc_cp) )
59
[1701]60class TestInstallation(TestCase):
61
62    def afterSetUp(self):
63        self.qi = self.portal.portal_quickinstaller
64        self.qi.installProduct("quintagroup.canonicalpath")
65
66        self.purl = getToolByName(self.portal, 'portal_url')
67        self.catalog = getToolByName(self.portal, 'portal_catalog')
68
69    def testCatalogMetadata(self):
70        self.assertTrue('canonical_path' in self.catalog._catalog.names,
71            "'canonical_path' metadata not added to catalog.")
72
[1702]73    def testIndexer(self):
74        self.loginAsPortalOwner()
75        my_doc = makeContent(self.portal, portal_type='Document', id='my_doc')
76        my_doc.update(title='My document')
[1701]77
[1702]78        cpadapter = queryAdapter(my_doc, ICanonicalPath)
79        cpmydoc = cpadapter.canonical_path()
80        cpbrain = self.catalog(path='/'+my_doc.absolute_url(1))[0].canonical_path
81        self.assertTrue(cpmydoc == cpbrain,
82            "Canonical Path from adapter: '%s' not equals with brains data: '%s'" % (
[1703]83             cpmydoc, cpbrain))
[1701]84
[1702]85        self.logout()
86
87
[1700]88def test_suite():
89    return unittest.TestSuite([
90        unittest.makeSuite(TestAdapter),
[1701]91        unittest.makeSuite(TestInstallation),
[782]92        ])
93
94if __name__ == '__main__':
95    unittest.main(defaultTest='test_suite')
Note: See TracBrowser for help on using the repository browser.