Changeset 3145 in products for quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/tests.py
- Timestamp:
- Apr 19, 2011 12:05:38 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/tests.py
r2972 r3145 6 6 from zope.schema.interfaces import InvalidValue 7 7 8 #for compatibility with older plone versions 8 #for compatibility with older plone versions 9 9 try: 10 10 from plone.indexer.interfaces import IIndexableObject … … 35 35 from quintagroup.canonicalpath.upgrades import CanonicalConvertor 36 36 37 37 38 def registerCanonicalPathInReg(): 38 import quintagroup.canonicalpath, Products.Five 39 import quintagroup.canonicalpath 40 import Products.Five 39 41 fiveconfigure.debug_mode = True 40 42 zcml.load_config('meta.zcml', Products.Five) 41 43 zcml.load_config('configure.zcml', quintagroup.canonicalpath) 42 44 fiveconfigure.debug_mode = False 45 43 46 44 47 class TestCase(ptc.PloneTestCase): … … 54 57 ptc.setupPloneSite() 55 58 59 56 60 class TestIndexerRegistration(TestCase): 57 61 … … 59 63 self.loginAsPortalOwner() 60 64 self.catalog = getToolByName(self.portal, 'portal_catalog') 61 self.my_doc = makeContent(self.portal, portal_type='Document', id='my_doc') 65 self.my_doc = makeContent(self.portal, portal_type='Document', 66 id='my_doc') 62 67 self.logout() 63 68 … … 66 71 wrapper = None 67 72 if not IIndexableObject.providedBy(obj): 68 wrapper = queryMultiAdapter((obj, self.catalog), IIndexableObject) 73 wrapper = queryMultiAdapter((obj, self.catalog), 74 IIndexableObject) 69 75 else: 70 76 wf = getattr(self.portal, 'portal_workflow', None) … … 73 79 else: 74 80 vars = {} 75 wrapper = getMultiAdapter((obj, self.portal), _old_IIndexableObjectWrapper) 81 wrapper = getMultiAdapter((obj, self.portal), 82 _old_IIndexableObjectWrapper) 76 83 wrapper.update(vars) 77 84 78 85 return wrapper and wrapper or obj 79 86 80 87 def testForAT(self): 81 88 wrapper = self.get_indexable_wrapper(self.my_doc) 82 self.assertFalse(wrapper is None, "No indexer registered for document object") 89 self.assertFalse(wrapper is None, 90 "No indexer registered for document object") 83 91 84 92 def testCanonicalPathForAT(self): 85 93 wrapper = self.get_indexable_wrapper(self.my_doc) 86 94 self.assertTrue(hasattr(wrapper, 'canonical_path'), 87 "'canonical_path' attribute not accessible with indexer wrapper for Document object") 95 "'canonical_path' attribute not accessible with "\ 96 "indexer wrapper for Document object") 88 97 89 98 def testCanonicalLinkForAT(self): 90 99 wrapper = self.get_indexable_wrapper(self.my_doc) 91 100 self.assertTrue(hasattr(wrapper, 'canonical_link'), 92 "'canonical_link' attribute not accessible with indexer wrapper for Document object")93 94 95 101 "'canonical_link' attribute not accessible with "\ 102 "indexer wrapper for Document object") 103 104 96 105 class TestDefaultCanonicalPathAdapter(TestCase): 97 106 … … 99 108 self.loginAsPortalOwner() 100 109 self.purl = getToolByName(self.portal, 'portal_url') 101 self.my_doc = makeContent(self.portal, portal_type='Document', id='my_doc') 110 self.my_doc = makeContent(self.portal, portal_type='Document', 111 id='my_doc') 102 112 self.logout() 103 113 104 self.mydoc_cp = '/'+'/'.join(self.purl.getRelativeContentPath(self.my_doc)) 105 self.portal_cp = '/'+'/'.join(self.purl.getRelativeContentPath(self.portal)) 114 self.mydoc_cp = '/' + '/'.join(self.purl.getRelativeContentPath( 115 self.my_doc)) 116 self.portal_cp = '/' + '/'.join(self.purl.getRelativeContentPath( 117 self.portal)) 106 118 107 119 def testRegistration4Portal(self): … … 114 126 self.assertFalse(cpadapter is None, 115 127 "Can't get canonical path adapter for the Document object") 116 117 128 118 129 def testGetDefault4Portal(self): … … 120 131 self.assertTrue(cpadapter.canonical_path == self.portal_cp, 121 132 "Canonical path adapter return '%s' for portal, must be: '%s'" % ( 122 cpadapter.canonical_path, self.portal_cp) ) 123 133 cpadapter.canonical_path, self.portal_cp)) 124 134 125 135 def testGetDefault4AT(self): 126 136 cpadapter = queryAdapter(self.my_doc, ICanonicalPath) 127 137 self.assertTrue(cpadapter.canonical_path == self.mydoc_cp, 128 "Canonical path adapter return '%s' for document, must be: '%s'" % ( 129 cpadapter.canonical_path, self.mydoc_cp) ) 130 138 "Canonical path adapter return '%s' for document, "\ 139 "must be: '%s'" % (cpadapter.canonical_path, self.mydoc_cp)) 131 140 132 141 def testSet4Portal(self): … … 138 147 self.assertTrue(prop == newcp, 139 148 "Canonical path adapter setter NOT SET new '%s' value to '%s' " \ 140 "propery for the portal" % (newcp, PROPERTY_PATH) 149 "propery for the portal" % (newcp, PROPERTY_PATH)) 141 150 142 151 self.assertTrue(cpadapter.canonical_path == newcp, 143 152 "Canonical path adapter GET '%s' canonical_path, for portal, " \ 144 "must be: '%s'" % (cpadapter.canonical_path, newcp) ) 145 153 "must be: '%s'" % (cpadapter.canonical_path, newcp)) 146 154 147 155 def testSet4AT(self): … … 153 161 self.assertTrue(prop == newcp, 154 162 "Canonical path adapter setter NOT SET new '%s' value to '%s' " \ 155 "propery for the Document" % (newcp, PROPERTY_PATH) 163 "propery for the Document" % (newcp, PROPERTY_PATH)) 156 164 157 165 self.assertTrue(cpadapter.canonical_path == newcp, 158 166 "Canonical path adapter GET '%s' canonical_path, for Document, " \ 159 "must be: '%s'" % (cpadapter.canonical_path, newcp) ) 160 167 "must be: '%s'" % (cpadapter.canonical_path, newcp)) 161 168 162 169 def testValidationWrong(self): 163 170 cpadapter = queryAdapter(self.my_doc, ICanonicalPath) 164 for wrong in ['new\nline', 's p a c e','with\ttabs']:171 for wrong in ['new\nline', 's p a c e', 'with\ttabs']: 165 172 try: 166 173 cpadapter.canonical_path = wrong … … 170 177 raise self.failureException, "InvalidValue not raised when " \ 171 178 "'%s' wrong value try to set" % wrong 172 179 173 180 def testValidationGood(self): 174 181 cpadapter = queryAdapter(self.my_doc, ICanonicalPath) 175 for good in ['./good', '../good','/good', 'good']:182 for good in ['./good', '../good', '/good', 'good']: 176 183 cpadapter.canonical_path = good 177 178 184 179 185 def testDeleteProperty(self): … … 187 193 "Not deleted Canonical path customization property for the portal") 188 194 189 190 195 def testDelCustomization(self): 191 196 cpadapter = queryAdapter(self.portal, ICanonicalPath) … … 204 209 self.loginAsPortalOwner() 205 210 self.purl = getToolByName(self.portal, 'portal_url') 206 self.my_doc = makeContent(self.portal, portal_type='Document', id='my_doc') 211 self.my_doc = makeContent(self.portal, portal_type='Document', 212 id='my_doc') 207 213 self.logout() 208 214 … … 218 224 self.assertFalse(cladapter is None, 219 225 "Can't get canonical link adapter for the Document object") 220 221 226 222 227 def testGetDefault4Portal(self): … … 224 229 self.assertTrue(cladapter.canonical_link == self.purl(), 225 230 "Canonical link adapter return '%s' for portal, must be: '%s'" % ( 226 cladapter.canonical_link, self.purl()) ) 227 231 cladapter.canonical_link, self.purl())) 228 232 229 233 def testGetDefault4AT(self): 230 234 cladapter = queryAdapter(self.my_doc, ICanonicalLink) 231 235 self.assertTrue(cladapter.canonical_link == self.mydoc_cl, 232 "Canonical link adapter return '%s' for document, must be: '%s'" % ( 233 cladapter.canonical_link, self.mydoc_cl) ) 234 236 "Canonical link adapter return '%s' for document, "\ 237 "must be: '%s'" % (cladapter.canonical_link, self.mydoc_cl)) 235 238 236 239 def testSet4Portal(self): … … 242 245 self.assertTrue(prop == newcl, 243 246 "Canonical link adapter setter NOT SET new '%s' value to '%s' " \ 244 "propery for the portal" % (newcl, PROPERTY_LINK) 247 "propery for the portal" % (newcl, PROPERTY_LINK)) 245 248 246 249 self.assertTrue(cladapter.canonical_link == newcl, 247 250 "Canonical link adapter GET '%s' canonical_link, for portal, " \ 248 "must be: '%s'" % (cladapter.canonical_link, newcl) ) 249 251 "must be: '%s'" % (cladapter.canonical_link, newcl)) 250 252 251 253 def testSet4AT(self): … … 257 259 self.assertTrue(prop == newcl, 258 260 "Canonical link adapter setter NOT SET new '%s' value to '%s' " \ 259 "propery for the Document" % (newcl, PROPERTY_LINK) 261 "propery for the Document" % (newcl, PROPERTY_LINK)) 260 262 261 263 self.assertTrue(cladapter.canonical_link == newcl, 262 264 "Canonical link adapter GET '%s' canonical_link, for Document, " \ 263 "must be: '%s'" % (cladapter.canonical_link, newcl) 265 "must be: '%s'" % (cladapter.canonical_link, newcl)) 264 266 265 267 def testValidationWrong(self): 266 268 cladapter = queryAdapter(self.my_doc, ICanonicalLink) 267 for wrong in ['http://new\nline', 's p a c e','with\ttabs']:269 for wrong in ['http://new\nline', 's p a c e', 'with\ttabs']: 268 270 try: 269 271 cladapter.canonical_link = wrong … … 273 275 raise self.failureException, "InvalidValue not raised when " \ 274 276 "'%s' wrong value try to set" % wrong 275 277 276 278 def testValidationGood(self): 277 279 cladapter = queryAdapter(self.my_doc, ICanonicalLink) 278 for good in ['http://', './good', '../good','/good', 'good']:280 for good in ['http://', './good', '../good', '/good', 'good']: 279 281 cladapter.canonical_link = good 280 281 282 282 283 def testDeleteProperty(self): … … 290 291 "Not deleted Canonical link customization property for the portal") 291 292 292 293 293 def test_DelCustomization(self): 294 294 cladapter = queryAdapter(self.portal, ICanonicalLink) … … 304 304 ## Dummy object for converter tests 305 305 ## 306 307 306 308 class PortalURL: 307 309 def __call__(self): 308 310 return "http://nohost/plone" 311 309 312 def getRelativeContentPath(self, context): 310 313 return ("plone", context.getId()) 311 314 315 312 316 class BaseItem: 313 317 portal_url = PortalURL() … … 320 324 321 325 def absolute_url(self): 322 return self.portal_url() + '/'+ self.getId() 326 return self.portal_url() + '/' + self.getId() 327 323 328 324 329 class GoodItem(BaseItem, PropertyManager, Traversable): 325 330 """Property provider.""" 326 331 332 327 333 class NotPropertyProviderItem(BaseItem, Traversable): 328 334 """Not property provider.""" 335 329 336 330 337 class NotAdaptableItem(BaseItem): … … 349 356 # 2. canonical path propery mast be delete from the object 350 357 self.assertEqual(item.hasProperty(ICanonicalPath(item).prop), False, 351 "canonical path 'property not deleted from the object")358 "canonical path property not deleted from the object") 352 359 353 360 def test_convertPPathToLink(self): … … 368 375 self.convertor.convertIPathToLink(bad) 369 376 result = self.convertor.getLogs() 370 expect = "NotPropertyProviderItem instance has no attribute 'hasProperty'" 377 expect = "NotPropertyProviderItem instance "\ 378 "has no attribute 'hasProperty'" 371 379 self.assertEqual(expect in result, True, "Wrong log: %s" % result) 372 380 … … 397 405 logs3 = self.convertor.getLogs() 398 406 self.assertEqual(logs3 > logs2, True, 399 "Log was not updated - last: \"%s\", previous: \"%s\"" % (logs3, logs2)) 400 407 "Log was not updated - last: \"%s\", previous: \"%s\"" % (logs3, 408 logs2)) 409 401 410 def test_loggingCleanup(self): 402 411 bad = NotPropertyProviderItem("item") … … 417 426 418 427 def test_PropertyManagerAndTraversable(self): 419 class ProperyAndTraverseProvider(BaseItem, PropertyManager, Traversable): 428 class ProperyAndTraverseProvider(BaseItem, PropertyManager, 429 Traversable): 420 430 """Property and Traversable provider.""" 421 431 item = ProperyAndTraverseProvider("test") 422 432 self.assertNotEqual(queryAdapter(item, ICanonicalLink), None, 423 self.cant % ICanonicalLink.__name__ + "IPropertyManager and ITraversable.") 433 self.cant % ICanonicalLink.__name__ + "IPropertyManager and "\ 434 "ITraversable.") 424 435 self.assertNotEqual(queryAdapter(item, ICanonicalPath), None, 425 self.cant % ICanonicalPath.__name__ + "IPropertyManager and ITraversable.") 436 self.cant % ICanonicalPath.__name__ + "IPropertyManager and "\ 437 "ITraversable.") 426 438 427 439 def test_Traversable(self): … … 452 464 item = NotProvider("test") 453 465 self.assertEqual(queryAdapter(item, ICanonicalLink), None, 454 self.doget % ICanonicalLink.__name__ + "nor ITraversabe not IPropertyManager.") 466 self.doget % ICanonicalLink.__name__ + "nor ITraversabe not "\ 467 "IPropertyManager.") 455 468 self.assertEqual(queryAdapter(item, ICanonicalPath), None, 456 self.doget % ICanonicalPath.__name__ + "nor ITraversabe not IPropertyManager.") 469 self.doget % ICanonicalPath.__name__ + "nor ITraversabe not "\ 470 "IPropertyManager.") 457 471 458 472
Note: See TracChangeset
for help on using the changeset viewer.