Ignore:
Timestamp:
Mar 18, 2010 10:07:37 AM (14 years ago)
Author:
mylan
Message:

#180: Update tests for Canonical URL

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/testCanonicalURL.py

    r1879 r1936  
    11import re 
     2from zope.interface import alsoProvides 
    23from zope.component import queryAdapter 
    34from zope.component import provideAdapter 
     5from zope.component import queryMultiAdapter 
    46from plone.indexer.decorator import indexer 
    5  
    6 try: 
    7     from plone.indexer.decorator import indexer 
    8 except ImportError: 
    9     IS_NEW = False 
    10     from Products.CMFPlone.CatalogTool import registerIndexableAttribute 
    11 else: 
    12     IS_NEW = True 
    137 
    148from Products.CMFCore.interfaces import IContentish 
    159from Products.Archetypes.interfaces import IBaseContent 
    1610 
    17 from quintagroup.canonicalpath.interfaces import ICanonicalPath 
    18 from quintagroup.seoptimizer.interfaces import ISEOCanonicalPath 
     11from quintagroup.canonicalpath.interfaces import ICanonicalLink 
     12from quintagroup.canonicalpath.adapters import PROPERTY_LINK as CANONICAL_PROPERTY 
     13from quintagroup.seoptimizer.browser.interfaces import IPloneSEOLayer 
     14# from quintagroup.seoptimizer.interfaces import ISEOCanonicalPath 
    1915from base import * 
    2016 
     
    5147        foundcurls = self.curl.findall(html) 
    5248 
    53         qseo_url = self.mydoc.getProperty('qSEO_canonical','') 
     49        qseo_url = ICanonicalLink(self.mydoc).canonical_link 
    5450        self.assertTrue(qseo_url == mydoc_url_new, 
    5551           "Not set 'qSEO_canonical' property") 
     
    5854           foundcurls, mydoc_url_new)) 
    5955 
    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)) 
    12262 
    12363    def testCatalogUpdated(self): 
    12464        purl = getToolByName(self.portal, 'portal_url') 
    12565        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') 
    13467 
    13568        # get catalog data before update 
    136         mydoc_catalog_canonical = catalog(id="mydoc")[0].canonical_path 
     69        mydoc_catalog_canonical = catalog(id="mydoc")[0].canonical_link 
    13770        self.assertTrue(not mydoc_catalog_canonical) 
    13871 
     
    14376            '&form.submitted=1' % mydoc_url_new, self.basic_auth) 
    14477 
    145         newcpath = canonical.canonical_path() 
    146         mydoc_catalog_canonical = catalog(id="mydoc")[0].canonical_path 
     78        newcpath = ICanonicalLink(self.mydoc).canonical_link 
     79        mydoc_catalog_canonical = catalog(id="mydoc")[0].canonical_link 
    14780        self.assertTrue(newcpath == mydoc_catalog_canonical, 
    14881            "canonical path get by adapter: '%s' not equals to cataloged one: '%s'" % ( 
    14982             newcpath, mydoc_catalog_canonical)) 
    15083 
     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 
    15196 
    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 
    15798 
     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         
    158108 
    159109def test_suite(): 
Note: See TracChangeset for help on using the changeset viewer.