Ignore:
Timestamp:
Mar 16, 2010 3:59:17 PM (14 years ago)
Author:
mylan
Message:

#177: Updated tests

File:
1 edited

Legend:

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

    r1708 r1922  
    44from zope.component import testing 
    55from zope.component import queryAdapter, queryMultiAdapter 
     6from zope.schema.interfaces import InvalidValue 
    67from plone.indexer.interfaces import IIndexableObject 
    78from Testing import ZopeTestCase as ztc 
     
    1617 
    1718from quintagroup.canonicalpath.interfaces import ICanonicalPath 
     19from quintagroup.canonicalpath.adapters import PROPERTY 
    1820 
    1921class TestCase(ptc.PloneTestCase): 
     
    2830ptc.setupPloneSite() 
    2931 
    30 class TestAdapter(TestCase): 
     32class TestIndexerRegistration(TestCase): 
    3133 
    3234    def afterSetUp(self): 
    3335        self.loginAsPortalOwner() 
     36        self.catalog = getToolByName(self.portal, 'portal_catalog') 
    3437        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') 
    3738        self.logout() 
    3839 
    39     def testAdapter4Portal(self): 
     40    def testForPortal(self): 
     41        wrapper = queryMultiAdapter((self.portal, self.catalog), IIndexableObject) 
     42        self.assertFalse(wrapper is None, "No indexer registered for portal object") 
     43 
     44    def testForAT(self): 
     45        wrapper = queryMultiAdapter((self.my_doc, self.catalog), IIndexableObject) 
     46        self.assertFalse(wrapper is None, "No indexer registered for document object") 
     47         
     48         
     49class TestDefaultAdapter(TestCase): 
     50 
     51 
     52    def afterSetUp(self): 
     53        self.loginAsPortalOwner() 
     54        self.purl = getToolByName(self.portal, 'portal_url') 
     55        self.my_doc = makeContent(self.portal, portal_type='Document', id='my_doc') 
     56        self.logout() 
     57 
     58        self.mydoc_cp = '/'+'/'.join(self.purl.getRelativeContentPath(self.my_doc)) 
     59        self.portal_cp = '/'+'/'.join(self.purl.getRelativeContentPath(self.portal)) 
     60 
     61    def testRegistration4Portal(self): 
    4062        cpadapter = queryAdapter(self.portal, ICanonicalPath) 
    4163        self.assertFalse(cpadapter is None, 
    4264            "Can't get canonical path adapter for the plone site object") 
    4365 
    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): 
     66    def testRegistration4AT(self): 
    5267        cpadapter = queryAdapter(self.my_doc, ICanonicalPath) 
    5368        self.assertFalse(cpadapter is None, 
    5469            "Can't get canonical path adapter for the Document object") 
     70         
    5571 
    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) ) 
     72    def testGetDefault4Portal(self): 
     73        cpadapter = queryAdapter(self.portal, ICanonicalPath) 
     74        self.assertTrue(cpadapter.canonical_path == self.portal_cp, 
     75            "Canonical path adapter return '%s' for portal, must be: '%s'" % ( 
     76            cpadapter.canonical_path, self.portal_cp) ) 
    6077 
    6178 
    62     def testIndexerRegistration(self): 
    63         wrapper = queryMultiAdapter((self.portal, self.catalog), IIndexableObject) 
    64         self.assertFalse(wrapper is None, "No indexer registered for portal object") 
     79    def testGetDefault4AT(self): 
     80        cpadapter = queryAdapter(self.my_doc, ICanonicalPath) 
     81        self.assertTrue(cpadapter.canonical_path == self.mydoc_cp, 
     82            "Canonical path adapter return '%s' for document, must be: '%s'" % ( 
     83            cpadapter.canonical_path, self.mydoc_cp) ) 
    6584 
    66         wrapper = queryMultiAdapter((self.my_doc, self.catalog), IIndexableObject) 
    67         self.assertFalse(wrapper is None, "No indexer registered for document object") 
    68          
    69          
     85 
     86    def testSet4Portal(self): 
     87        cpadapter = queryAdapter(self.portal, ICanonicalPath) 
     88        newcp = self.portal_cp + '/new_portal_canonical' 
     89 
     90        cpadapter.canonical_path = newcp 
     91        prop = self.portal.getProperty(PROPERTY, None) 
     92        self.assertTrue(prop == newcp, 
     93            "Canonical path adapter setter NOT SET new '%s' value to '%s' " \ 
     94            "propery for the portal" % (newcp, PROPERTY) ) 
     95 
     96        self.assertTrue(cpadapter.canonical_path == newcp, 
     97            "Canonical path adapter GET '%s' canonical_path, for portal, " \ 
     98            "must be: '%s'" % (cpadapter.canonical_path, newcp) ) 
     99 
     100 
     101    def testSet4AT(self): 
     102        cpadapter = queryAdapter(self.my_doc, ICanonicalPath) 
     103        newcp = self.mydoc_cp + '/new_mydoc_canonical' 
     104 
     105        cpadapter.canonical_path = newcp 
     106        prop = self.my_doc.getProperty(PROPERTY, None) 
     107        self.assertTrue(prop == newcp, 
     108            "Canonical path adapter setter NOT SET new '%s' value to '%s' " \ 
     109            "propery for the Document" % (newcp, PROPERTY) ) 
     110 
     111        self.assertTrue(cpadapter.canonical_path == newcp, 
     112            "Canonical path adapter GET '%s' canonical_path, for Document, " \ 
     113            "must be: '%s'" % (cpadapter.canonical_path, newcp) ) 
     114 
     115 
     116    def testValidation(self): 
     117        cpadapter = queryAdapter(self.my_doc, ICanonicalPath) 
     118        for wrong in ['new\nline','s p a c e','with\ttabs']: 
     119            try: 
     120                cpadapter.canonical_path = wrong 
     121            except InvalidValue: 
     122                continue 
     123            else: 
     124                raise self.failureException, "InvalidValue not raised when " \ 
     125                      "wrong value set" 
     126 
     127 
    70128def test_suite(): 
    71129    return unittest.TestSuite([ 
    72         unittest.makeSuite(TestAdapter), 
     130        unittest.makeSuite(TestIndexerRegistration), 
     131        unittest.makeSuite(TestDefaultAdapter), 
    73132        ]) 
    74133 
Note: See TracChangeset for help on using the changeset viewer.