Changeset 3145 in products for quintagroup.canonicalpath/trunk/quintagroup
- Timestamp:
- Apr 19, 2011 12:05:38 PM (13 years ago)
- Location:
- quintagroup.canonicalpath/trunk/quintagroup/canonicalpath
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/adapters.py
r2369 r3145 55 55 """ 56 56 if self.context.hasProperty(self.prop): 57 self.context.manage_delProperties(ids=[self.prop, ])57 self.context.manage_delProperties(ids=[self.prop, ]) 58 58 59 59 … … 86 86 def __init__(self, context): 87 87 super(DefaultCanonicalPathAdapter, self).__init__(context) 88 self.purl = getToolByName(self.context, 'portal_url')88 self.purl = getToolByName(self.context, 'portal_url') 89 89 90 90 def getDefault(self): 91 return '/' +'/'.join(self.purl.getRelativeContentPath(self.context))91 return '/' + '/'.join(self.purl.getRelativeContentPath(self.context)) 92 92 93 93 canonical_path = property(DefaultCanonicalAdapter.getProp, -
quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/catalog.py
r2125 r3145 2 2 from zope.component import queryAdapter 3 3 4 #for compatibility with older plone versions 4 #for compatibility with older plone versions 5 5 try: 6 from plone.indexer.decorator import indexer 6 from plone.indexer.decorator import indexer 7 7 IS_NEW = True 8 8 except: 9 9 IS_NEW = False 10 class IDummyInterface:pass 10 11 class IDummyInterface: 12 pass 13 11 14 class indexer: 12 15 13 16 def __init__(self, *interfaces): 14 17 self.interfaces = IDummyInterface, 15 18 16 17 18 19 20 19 def __call__(self, callable): 20 callable.__component_adapts__ = self.interfaces 21 callable.__implemented__ = Interface 22 return callable 23 21 24 from interfaces import ICanonicalPath 22 25 from interfaces import ICanonicalLink 26 23 27 24 28 @indexer(Interface) … … 31 35 return None 32 36 37 33 38 @indexer(Interface) 34 39 def canonical_link(obj, **kwargs): … … 40 45 return None 41 46 42 #for compatibility with older plone versions 47 #for compatibility with older plone versions 43 48 if not IS_NEW: 44 49 from Products.CMFPlone.CatalogTool import registerIndexableAttribute -
quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/interfaces.py
r1927 r3145 1 1 from zope.interface import Interface, Attribute 2 2 3 3 4 class ICanonicalPath(Interface): … … 9 10 "*setter* and *getter* for the attribute") 10 11 12 11 13 class ICanonicalLink(Interface): 12 14 """canonical_link provider interface … … 16 18 "canonical_link - for the object. Adapter must implement " 17 19 "*setter* and *getter* for the attribute") 18 -
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 -
quintagroup.canonicalpath/trunk/quintagroup/canonicalpath/upgrades.py
r2371 r3145 12 12 from quintagroup.canonicalpath.adapters import PROPERTY_PATH 13 13 from quintagroup.canonicalpath.adapters import DefaultPropertyAdapter 14 14 15 15 16 class CanonicalConvertor(object): … … 65 66 Log results in logger. 66 67 """ 67 src_msg = type(src_iface) in StringTypes and src_iface or src_iface.__name__ 68 src_msg = type(src_iface) in StringTypes and src_iface \ 69 or src_iface.__name__ 68 70 msg = "Migrate %s into %s for %s object: " \ 69 71 % (src_msg, dst_iface.__name__, obj.absolute_url()) … … 84 86 msg += "SUCCESS" 85 87 self._logger.log(lev, msg) 86 88 87 89 return lev == INFO and True or False 88 90 89 91 def _getOrMakeAdapter(self, obj, arg): 90 92 """Function return adapter for process of the property. 91 Adapter get by interface 93 Adapter get by interface(if arg is not a string - interface assumed) 92 94 OR if arg is string - adapter created from DefaultCanonicalAdapter. 93 95 """ … … 120 122 self._logger = Logger("quintagroup.canonicalpath", NOTSET) 121 123 self._logger.addHandler(handler) 122
Note: See TracChangeset
for help on using the changeset viewer.