Ignore:
Timestamp:
May 20, 2010 4:54:07 PM (14 years ago)
Author:
mylan
Message:

Added tests for Convertor

File:
1 edited

Legend:

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

    r2043 r2366  
    1616 
    1717 
     18from OFS.PropertyManager import PropertyManager 
     19from OFS.Traversable import Traversable 
     20 
    1821from Testing import ZopeTestCase as ztc 
    1922 
     
    3033from quintagroup.canonicalpath.adapters import PROPERTY_PATH 
    3134from quintagroup.canonicalpath.adapters import PROPERTY_LINK 
     35from quintagroup.canonicalpath.upgrades import CanonicalConvertor 
    3236 
    3337class TestCase(ptc.PloneTestCase): 
     
    290294            "default value for the portal") 
    291295 
    292  
     296## 
     297## Dummy object for converter tests 
     298## 
     299class PortalURL: 
     300    def __call__(self): 
     301        return "http://nohost/plone" 
     302    def getRelativeContentPath(self, context): 
     303        return "/plone/" + context.getId() 
     304 
     305class BaseItem: 
     306    portal_url = PortalURL() 
     307 
     308    def __init__(self, id): 
     309        self.id = id 
     310 
     311    def getId(self): 
     312        return self.id 
     313 
     314    def absolute_url(self): 
     315        return self.portal_url() + '/'+ self.getId() 
     316 
     317class GoodItem(BaseItem, PropertyManager, Traversable): 
     318    """Property provider.""" 
     319 
     320class NotProperyProviderItem(BaseItem, Traversable): 
     321    """Not property provider.""" 
     322 
     323class NotAdaptableItem(BaseItem): 
     324    """Not adaptable object.""" 
     325 
     326class TestConvertor(unittest.TestCase): 
     327 
     328    def setUp(self): 
     329        self.convertor = CanonicalConvertor("http://domain.com") 
     330 
     331    def test_convertPathToLink(self): 
     332        item = GoodItem("item") 
     333        item._setProperty(PROPERTY_PATH, "/www/some/path") 
     334        self.convertor.convertPathToLink(item) 
     335        result = ICanonicalLink(item).canonical_link 
     336        expect = "http://domain.com/www/some/path" 
     337        self.assertEqual(result, expect, "Got %s canonical link, " \ 
     338                         "expect: %s" % (result, expect)) 
     339         
     340    def test_convertBadItems(self): 
     341        bad = NotProperyProviderItem("item") 
     342        self.convertor.convertPathToLink(bad) 
     343        result = self.convertor.getLogs() 
     344        expect = "ERROR: exceptions.AttributeError: " \ 
     345                 "NotProperyProviderItem instance has no attribute 'hasProperty'" 
     346        self.assertEqual(expect in result, True, "Wrong log: %s" % result) 
     347 
     348        bad = NotAdaptableItem("item") 
     349        self.convertor.convertPathToLink(bad) 
     350        result = self.convertor.getLogs() 
     351        expect = "ERROR: zope.component.interfaces.ComponentLookupError: " 
     352        self.assertEqual(expect in result, True, "Wrong log: %s" % result) 
     353 
     354    def test_loggingSuccess(self): 
     355        good = GoodItem("item") 
     356        self.convertor.convertPathToLink(good) 
     357        result = self.convertor.getLogs() 
     358        expect = "SUCCESS" 
     359        self.assertEqual(expect in result, True, "Wrong log: %s" % result) 
     360 
     361    def test_loggingGet(self): 
     362        # log must collect new errors 
     363        # and return full log anytime 
     364        bad = NotProperyProviderItem("item") 
     365        self.convertor.convertPathToLink(bad) 
     366        logs = self.convertor.getLogs() 
     367        logs2 = self.convertor.getLogs() 
     368        assert logs != "" 
     369        self.assertEqual(logs == logs2, True, 
     370             "logs not equal: \"%s\" != \"%s\"" % (logs, logs2)) 
     371        self.convertor.convertPathToLink(bad) 
     372        logs3 = self.convertor.getLogs() 
     373        self.assertEqual(logs3 > logs2, True, 
     374             "Log was not updated - last: \"%s\", previous: \"%s\"" % (logs3, logs2)) 
     375         
     376 
     377    def test_loggingCleanup(self): 
     378        bad = NotProperyProviderItem("item") 
     379        self.convertor.convertPathToLink(bad) 
     380        assert self.convertor.getLogs() != "" 
     381        self.convertor.cleanupLogs() 
     382        logs = self.convertor.getLogs() 
     383        self.assertEqual(logs, "", "Log not cleand-up: \"%s\"" % logs) 
     384 
     385  
    293386def test_suite(): 
    294387    return unittest.TestSuite([ 
     
    296389        unittest.makeSuite(TestDefaultCanonicalPathAdapter), 
    297390        unittest.makeSuite(TestDefaultCanonicalLinkAdapter), 
     391        unittest.makeSuite(TestConvertor), 
    298392        ]) 
    299393 
Note: See TracChangeset for help on using the changeset viewer.