Changeset 2366 in products for quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/tests.py
- Timestamp:
- May 20, 2010 4:54:07 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/tests.py
r2043 r2366 16 16 17 17 18 from OFS.PropertyManager import PropertyManager 19 from OFS.Traversable import Traversable 20 18 21 from Testing import ZopeTestCase as ztc 19 22 … … 30 33 from quintagroup.canonicalpath.adapters import PROPERTY_PATH 31 34 from quintagroup.canonicalpath.adapters import PROPERTY_LINK 35 from quintagroup.canonicalpath.upgrades import CanonicalConvertor 32 36 33 37 class TestCase(ptc.PloneTestCase): … … 290 294 "default value for the portal") 291 295 292 296 ## 297 ## Dummy object for converter tests 298 ## 299 class PortalURL: 300 def __call__(self): 301 return "http://nohost/plone" 302 def getRelativeContentPath(self, context): 303 return "/plone/" + context.getId() 304 305 class 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 317 class GoodItem(BaseItem, PropertyManager, Traversable): 318 """Property provider.""" 319 320 class NotProperyProviderItem(BaseItem, Traversable): 321 """Not property provider.""" 322 323 class NotAdaptableItem(BaseItem): 324 """Not adaptable object.""" 325 326 class 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 293 386 def test_suite(): 294 387 return unittest.TestSuite([ … … 296 389 unittest.makeSuite(TestDefaultCanonicalPathAdapter), 297 390 unittest.makeSuite(TestDefaultCanonicalLinkAdapter), 391 unittest.makeSuite(TestConvertor), 298 392 ]) 299 393
Note: See TracChangeset
for help on using the changeset viewer.