Changeset 1936 in products for quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer
- Timestamp:
- Mar 18, 2010 10:07:37 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/testCanonicalURL.py
r1879 r1936 1 1 import re 2 from zope.interface import alsoProvides 2 3 from zope.component import queryAdapter 3 4 from zope.component import provideAdapter 5 from zope.component import queryMultiAdapter 4 6 from plone.indexer.decorator import indexer 5 6 try:7 from plone.indexer.decorator import indexer8 except ImportError:9 IS_NEW = False10 from Products.CMFPlone.CatalogTool import registerIndexableAttribute11 else:12 IS_NEW = True13 7 14 8 from Products.CMFCore.interfaces import IContentish 15 9 from Products.Archetypes.interfaces import IBaseContent 16 10 17 from quintagroup.canonicalpath.interfaces import ICanonicalPath 18 from quintagroup.seoptimizer.interfaces import ISEOCanonicalPath 11 from quintagroup.canonicalpath.interfaces import ICanonicalLink 12 from quintagroup.canonicalpath.adapters import PROPERTY_LINK as CANONICAL_PROPERTY 13 from quintagroup.seoptimizer.browser.interfaces import IPloneSEOLayer 14 # from quintagroup.seoptimizer.interfaces import ISEOCanonicalPath 19 15 from base import * 20 16 … … 51 47 foundcurls = self.curl.findall(html) 52 48 53 qseo_url = self.mydoc.getProperty('qSEO_canonical','')49 qseo_url = ICanonicalLink(self.mydoc).canonical_link 54 50 self.assertTrue(qseo_url == mydoc_url_new, 55 51 "Not set 'qSEO_canonical' property") … … 58 54 foundcurls, mydoc_url_new)) 59 55 60 def test_SEOCanonicalAdapterRegistration(self): 61 portal_seocanonical = queryAdapter(self.portal, interface=ISEOCanonicalPath) 62 self.assertTrue(portal_seocanonical is not None, 63 "Not registered ISEOCanonicalPath adapter") 64 65 mydoc_seocanonical = queryAdapter(self.mydoc, interface=ISEOCanonicalPath) 66 self.assertTrue(mydoc_seocanonical is not None, 67 "Not registered ISEOCanonicalPath adapter") 68 69 def test_canonicalAdapterRegistration(self): 70 canonical_portal = queryAdapter(self.portal, interface=ICanonicalPath) 71 self.assertTrue(canonical_portal is not None, 72 "Not registered ICanonicalPath adapter for portal root") 73 74 canonical_mydoc = queryAdapter(self.mydoc, interface=ICanonicalPath) 75 self.assertTrue(canonical_mydoc is not None, 76 "Not registered ICanonicalPath adapter for the documnent") 77 78 def test_canonicalAdapter(self): 79 purl = getToolByName(self.portal, 'portal_url') 80 mydoc_path_rel = '/'+'/'.join(purl.getRelativeContentPath(self.mydoc)) 81 82 canonical = queryAdapter(self.mydoc, ISEOCanonicalPath) 83 cpath = canonical.canonical_path() 84 self.assertTrue(cpath == mydoc_path_rel, 85 "By canonical path adapter got: '%s', must be: '%s'" % ( 86 cpath, mydoc_path_rel)) 87 88 # Update canonical url property 89 mydoc_url_new = self.mydoc.absolute_url() + '.new' 90 self.publish(self.mydoc_path + '/@@seo-context-properties?' \ 91 'seo_canonical_override=checked&seo_canonical=%s' \ 92 '&form.submitted=1' % mydoc_url_new, self.basic_auth) 93 94 mydoc_path_rel_new = mydoc_path_rel + '.new' 95 newcpath = canonical.canonical_path() 96 self.assertTrue(newcpath == mydoc_path_rel_new, 97 "By canonical path adapter got: '%s', must be: '%s'" % ( 98 newcpath, mydoc_path_rel_new)) 99 100 101 def addIndexerOld(self): 102 def canonical_path(obj, **kwargs): 103 """Return canonical_path property for the object. 104 """ 105 cpath = queryAdapter(obj, interface=ISEOCanonicalPath) 106 if cpath: 107 return cpath.canonical_path() 108 return None 109 registerIndexableAttribute("canonical_path", test_column) 110 111 def addIndexerNew(self): 112 @indexer(IContentish) 113 def canonical_path(obj, **kwargs): 114 """Return canonical_path property for the object. 115 """ 116 cpath = queryAdapter(obj, interface=ISEOCanonicalPath) 117 if cpath: 118 return cpath.canonical_path() 119 return None 120 121 provideAdapter(canonical_path, name='canonical_path') 56 def test_defaultCanonical(self): 57 expect = self.mydoc.absolute_url() 58 cpath = ICanonicalLink(self.mydoc).canonical_link 59 self.assertTrue(cpath == expect, 60 "Default canonical link adapter return: '%s', must be: '%s'" % ( 61 cpath, expect)) 122 62 123 63 def testCatalogUpdated(self): 124 64 purl = getToolByName(self.portal, 'portal_url') 125 65 catalog = getToolByName(self.portal, 'portal_catalog') 126 if IS_NEW: 127 self.addIndexerNew() 128 else: 129 self.addIndexerOld() 130 catalog.addColumn('canonical_path') 131 132 canonical = queryAdapter(self.mydoc, ISEOCanonicalPath) 133 cpath = canonical.canonical_path() 66 catalog.addColumn('canonical_link') 134 67 135 68 # get catalog data before update 136 mydoc_catalog_canonical = catalog(id="mydoc")[0].canonical_ path69 mydoc_catalog_canonical = catalog(id="mydoc")[0].canonical_link 137 70 self.assertTrue(not mydoc_catalog_canonical) 138 71 … … 143 76 '&form.submitted=1' % mydoc_url_new, self.basic_auth) 144 77 145 newcpath = canonical.canonical_path()146 mydoc_catalog_canonical = catalog(id="mydoc")[0].canonical_ path78 newcpath = ICanonicalLink(self.mydoc).canonical_link 79 mydoc_catalog_canonical = catalog(id="mydoc")[0].canonical_link 147 80 self.assertTrue(newcpath == mydoc_catalog_canonical, 148 81 "canonical path get by adapter: '%s' not equals to cataloged one: '%s'" % ( 149 82 newcpath, mydoc_catalog_canonical)) 150 83 84 def test_canonicalValidation(self): 85 wrong_canonical = 'wrong canonical' 86 # Update canonical url property 87 html = self.publish(self.mydoc_path + '/@@seo-context-properties?' \ 88 'seo_canonical_override=checked&seo_canonical=%s&' \ 89 'form.submitted=1' % wrong_canonical, self.basic_auth).getBody() 90 self.assertTrue("wrong canonical url" in html, 91 "Canonical url not validated") 92 93 def test_delCanonical(self): 94 newcanonical = '/new_canonical' 95 ICanonicalLink(self.mydoc).canonical_link = newcanonical 151 96 152 def testSEOCanonicalAdapter4OFSFolder(self): 153 atct_tool = self.portal.portal_atct 154 seocan = queryAdapter(self.mydoc, ISEOCanonicalPath) 155 self.assertTrue(seocan is not None, 156 "seo canonical adapter not found for 'ATCT Tool'") 97 assert ICanonicalLink(self.mydoc).canonical_link == newcanonical 157 98 99 # remove canonical url customization 100 self.publish(self.mydoc_path + '/@@seo-context-properties?' \ 101 'seo_canonical=%s&seo_canonical_override=&form.submitted=1' % newcanonical, 102 self.basic_auth) 103 104 mydoc_canonical = ICanonicalLink(self.mydoc).canonical_link 105 self.assertTrue(mydoc_canonical == self.mydoc.absolute_url(), 106 "Steel customized canonical url after remove customization") 107 158 108 159 109 def test_suite():
Note: See TracChangeset
for help on using the changeset viewer.