Changeset 1671 in products for quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/tests/testCanonicalURL.py
- Timestamp:
- Feb 9, 2010 12:59:27 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/tests/testCanonicalURL.py
r1670 r1671 1 1 import re 2 2 from zope.component import queryAdapter 3 from Products.Archetypes.interfaces import IBaseContent 4 5 from quintagroup.seoptimizer.interfaces import ICanonicalPath 3 6 from base import getToolByName, FunctionalTestCase, newSecurityManager 4 7 from config import * … … 22 25 self.mydoc = self.portal['mydoc'] 23 26 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) 25 29 26 30 … … 30 34 mydoc_url = self.mydoc.absolute_url() 31 35 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)) 34 39 35 40 def test_updateCanonicalURL(self): 36 41 mydoc_url_new = self.mydoc.absolute_url() + '.new' 37 42 # 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) 40 46 # Test updated canonical url 41 47 html = self.publish(self.mydoc_path, self.basic_auth).getBody() 42 48 foundcurls = self.curl.findall(html) 43 49 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)) 48 56 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 49 85 50 86 def test_suite():
Note: See TracChangeset
for help on using the changeset viewer.