source: products/quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/testCanonicalURL.py @ 1958

Last change on this file since 1958 was 1958, checked in by liebster, 14 years ago

Clean-up code http://codereview.corp.quintagroup.com/40241/show

  • Property svn:eol-style set to native
File size: 4.3 KB
Line 
1from quintagroup.canonicalpath.interfaces import ICanonicalLink
2from base import *
3
4class TestCanonicalURL(FunctionalTestCase):
5
6    def afterSetUp(self):
7        self.basic_auth = ':'.join((portal_owner,default_password))
8        self.loginAsPortalOwner()
9        # Preparation for functional testing
10        self.portal.invokeFactory('Document', id='mydoc')
11        self.mydoc = self.portal['mydoc']
12        self.mydoc_path = "/%s" % self.mydoc.absolute_url(1)
13        self.curl = re.compile('<link\srel\s*=\s*"canonical"\s+' \
14            '[^>]*href\s*=\s*\"([^\"]*)\"[^>]*>', re.S|re.M)
15
16    def test_CanonicalURL(self):
17        html = self.publish(self.mydoc_path, self.basic_auth).getBody()
18        foundcurls = self.curl.findall(html)
19        mydoc_url = self.mydoc.absolute_url()
20
21        self.assertTrue([1 for curl in foundcurls if curl==mydoc_url],
22           "Wrong CANONICAL URL for document: %s, all must be: %s" % (
23           foundcurls, mydoc_url))
24
25    def test_updateCanonicalURL(self):
26        mydoc_url_new = self.mydoc.absolute_url() + '.new'
27        # Update canonical url property
28        self.publish(self.mydoc_path + '/@@seo-context-properties?' \
29           'seo_canonical_override=checked&seo_canonical=%s&' \
30           'form.submitted=1' % mydoc_url_new, self.basic_auth)
31        # Test updated canonical url
32        html = self.publish(self.mydoc_path, self.basic_auth).getBody()
33        foundcurls = self.curl.findall(html)
34
35        qseo_url = ICanonicalLink(self.mydoc).canonical_link
36        self.assertTrue(qseo_url == mydoc_url_new,
37           "Not set 'qSEO_canonical' property")
38        self.assertTrue([1 for curl in foundcurls if curl==mydoc_url_new],
39           "Wrong CANONICAL URL for document: %s, all must be: %s" % (
40           foundcurls, mydoc_url_new))
41
42    def test_defaultCanonical(self):
43        expect = self.mydoc.absolute_url()
44        cpath = ICanonicalLink(self.mydoc).canonical_link
45        self.assertTrue(cpath == expect,
46            "Default canonical link adapter return: '%s', must be: '%s'" % (
47             cpath, expect))
48
49    def testCatalogUpdated(self):
50        purl = getToolByName(self.portal, 'portal_url')
51        catalog = getToolByName(self.portal, 'portal_catalog')
52        catalog.addColumn('canonical_link')
53
54        # get catalog data before update
55        mydoc_catalog_canonical = catalog(id="mydoc")[0].canonical_link
56        self.assertTrue(not mydoc_catalog_canonical)
57
58        # Update canonical url property
59        mydoc_url_new = self.mydoc.absolute_url() + '.new'
60        self.publish(self.mydoc_path + '/@@seo-context-properties?' \
61            'seo_canonical_override=checked&seo_canonical=%s' \
62            '&form.submitted=1' % mydoc_url_new, self.basic_auth)
63
64        newcpath = ICanonicalLink(self.mydoc).canonical_link
65        mydoc_catalog_canonical = catalog(id="mydoc")[0].canonical_link
66        self.assertTrue(newcpath == mydoc_catalog_canonical,
67            "canonical path get by adapter: '%s' not equals to cataloged one: '%s'" % (
68             newcpath, mydoc_catalog_canonical))
69
70    def test_canonicalValidation(self):
71        wrong_canonical = 'wrong   canonical'
72        # Update canonical url property
73        html = self.publish(self.mydoc_path + '/@@seo-context-properties?' \
74               'seo_canonical_override=checked&seo_canonical=%s&' \
75               'form.submitted=1' % wrong_canonical, self.basic_auth).getBody()
76        self.assertTrue("wrong canonical url" in html,
77                        "Canonical url not validated")
78
79    def test_delCanonical(self):
80        newcanonical = '/new_canonical'
81        ICanonicalLink(self.mydoc).canonical_link = newcanonical
82
83        assert ICanonicalLink(self.mydoc).canonical_link == newcanonical
84
85        # remove canonical url customization
86        self.publish(self.mydoc_path + '/@@seo-context-properties?' \
87           'seo_canonical=%s&seo_canonical_override=&form.submitted=1' % newcanonical,
88            self.basic_auth)
89
90        mydoc_canonical = ICanonicalLink(self.mydoc).canonical_link
91        self.assertTrue(mydoc_canonical == self.mydoc.absolute_url(),
92            "Steel customized canonical url after remove customization")
93
94
95def test_suite():
96    from unittest import TestSuite, makeSuite
97    suite = TestSuite()
98    suite.addTest(makeSuite(TestCanonicalURL))
99    return suite
Note: See TracBrowser for help on using the repository browser.