Ignore:
Timestamp:
Feb 9, 2010 12:59:27 PM (14 years ago)
Author:
mylan
Message:

Added ICanonicalPath adapter and appropriate tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/tests/testCanonicalURL.py

    r1670 r1671  
    11import re 
    22from zope.component import queryAdapter 
     3from Products.Archetypes.interfaces import IBaseContent 
     4 
     5from quintagroup.seoptimizer.interfaces import ICanonicalPath 
    36from base import getToolByName, FunctionalTestCase, newSecurityManager 
    47from config import * 
     
    2225        self.mydoc = self.portal['mydoc'] 
    2326        self.mydoc_path = "/%s" % self.mydoc.absolute_url(1) 
    24         self.curl = re.compile('<link\srel\s*=\s*"canonical"\s+[^>]*href\s*=\s*\"([^\"]*)\"[^>]*>', re.S|re.M) 
     27        self.curl = re.compile('<link\srel\s*=\s*"canonical"\s+' \ 
     28            '[^>]*href\s*=\s*\"([^\"]*)\"[^>]*>', re.S|re.M) 
    2529 
    2630 
     
    3034        mydoc_url = self.mydoc.absolute_url() 
    3135 
    32         self.assert_([1 for curl in foundcurls if curl==mydoc_url], 
    33            "Wrong CANONICAL URL for document: %s, all must be: %s" % (foundcurls, mydoc_url)) 
     36        self.assertTrue([1 for curl in foundcurls if curl==mydoc_url], 
     37           "Wrong CANONICAL URL for document: %s, all must be: %s" % ( 
     38           foundcurls, mydoc_url)) 
    3439 
    3540    def test_updateCanonicalURL(self): 
    3641        mydoc_url_new = self.mydoc.absolute_url() + '.new' 
    3742        # Update canonical url property 
    38         self.publish(self.mydoc_path + '/@@seo-context-properties?seo_canonical_override=checked' \ 
    39                      '&seo_canonical=%s&form.submitted=1' % mydoc_url_new, self.basic_auth) 
     43        self.publish(self.mydoc_path + '/@@seo-context-properties?' \ 
     44           'seo_canonical_override=checked&seo_canonical=%s&' \ 
     45           'form.submitted=1' % mydoc_url_new, self.basic_auth) 
    4046        # Test updated canonical url 
    4147        html = self.publish(self.mydoc_path, self.basic_auth).getBody() 
    4248        foundcurls = self.curl.findall(html) 
    4349 
    44         self.assert_(self.mydoc.getProperty('qSEO_canonical','') == mydoc_url_new, 
    45                      "Not set 'qSEO_canonical' property") 
    46         self.assert_([1 for curl in foundcurls if curl==mydoc_url_new], 
    47            "Wrong CANONICAL URL for document: %s, all must be: %s" % (foundcurls, mydoc_url_new)) 
     50        qseo_url = self.mydoc.getProperty('qSEO_canonical','') 
     51        self.assertTrue(qseo_url == mydoc_url_new, 
     52           "Not set 'qSEO_canonical' property") 
     53        self.assertTrue([1 for curl in foundcurls if curl==mydoc_url_new], 
     54           "Wrong CANONICAL URL for document: %s, all must be: %s" % ( 
     55           foundcurls, mydoc_url_new)) 
    4856 
     57    def test_canonicalAdapterRegistration(self): 
     58        canonical = queryAdapter(self.mydoc, interface=ICanonicalPath, 
     59            name='qseo_canonical') 
     60        self.assertTrue(canonical is not None, 
     61            "Not registered 'qseo_canonical' adapter") 
     62 
     63    def test_canonicalAdapter(self): 
     64        purl = getToolByName(self.portal, 'portal_url') 
     65        mydoc_path_rel = '/'+'/'.join(purl.getRelativeContentPath(self.mydoc)) 
     66 
     67        canonical = queryAdapter(self.mydoc, ICanonicalPath, name='qseo_canonical') 
     68        cpath = canonical.canonical_path() 
     69        self.assertTrue(cpath == mydoc_path_rel, 
     70            "By canonical path adapter got: '%s', must be: '%s'" % ( 
     71             cpath, mydoc_path_rel)) 
     72         
     73        # Update canonical url property 
     74        mydoc_url_new = self.mydoc.absolute_url() + '.new' 
     75        self.publish(self.mydoc_path + '/@@seo-context-properties?' \ 
     76            'seo_canonical_override=checked&seo_canonical=%s' \ 
     77            '&form.submitted=1' % mydoc_url_new, self.basic_auth) 
     78 
     79        mydoc_path_rel_new = mydoc_path_rel + '.new' 
     80        newcpath = canonical.canonical_path() 
     81        self.assertTrue(newcpath == mydoc_path_rel_new, 
     82            "By canonical path adapter got: '%s', must be: '%s'" % ( 
     83             newcpath, mydoc_path_rel_new)) 
     84        
    4985 
    5086def test_suite(): 
Note: See TracChangeset for help on using the changeset viewer.