Ignore:
Timestamp:
Feb 10, 2010 7:42:42 PM (14 years ago)
Author:
mylan
Message:

#133: Added adapter tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/tests.py

    r1699 r1700  
    33from zope.testing import doctestunit 
    44from zope.component import testing 
     5from zope.component import queryAdapter 
    56from Testing import ZopeTestCase as ztc 
    67 
    78from Products.Five import zcml 
    89from Products.Five import fiveconfigure 
     10from Products.CMFCore.utils import getToolByName 
    911from Products.PloneTestCase import PloneTestCase as ptc 
    1012from Products.PloneTestCase.layer import PloneSite 
    11 ptc.setupPloneSite() 
    1213 
    13 import quintagroup.canonicalpath 
     14from quintagroup.canonicalpath.interfaces import ICanonicalPath 
    1415 
    1516class TestCase(ptc.PloneTestCase): 
     
    1718        @classmethod 
    1819        def setUp(cls): 
     20            import quintagroup.canonicalpath 
    1921            fiveconfigure.debug_mode = True 
    20             zcml.load_config('configure.zcml', 
    21                              quintagroup.canonicalpath) 
     22            zcml.load_config('configure.zcml', quintagroup.canonicalpath) 
    2223            fiveconfigure.debug_mode = False 
    2324 
    24         @classmethod 
    25         def tearDown(cls): 
    26             pass 
     25ptc.setupPloneSite() 
    2726 
     27class 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) ) 
    2858 
    2959def test_suite(): 
    3060    return unittest.TestSuite([ 
    31  
    32         # Unit tests 
    33         #doctestunit.DocFileSuite( 
    34         #    'README.txt', package='quintagroup.canonicalpath', 
    35         #    setUp=testing.setUp, tearDown=testing.tearDown), 
    36  
    37         #doctestunit.DocTestSuite( 
    38         #    module='quintagroup.canonicalpath.mymodule', 
    39         #    setUp=testing.setUp, tearDown=testing.tearDown), 
    40  
    41  
    42         # Integration tests that use PloneTestCase 
    43         #ztc.ZopeDocFileSuite( 
    44         #    'README.txt', package='quintagroup.canonicalpath', 
    45         #    test_class=TestCase), 
    46  
    47         #ztc.FunctionalDocFileSuite( 
    48         #    'browser.txt', package='quintagroup.canonicalpath', 
    49         #    test_class=TestCase), 
    50  
     61        unittest.makeSuite(TestAdapter), 
    5162        ]) 
    5263 
Note: See TracChangeset for help on using the changeset viewer.