source: products/quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/testMetaTagsDuplication.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

File size: 2.2 KB
Line 
1from base import *
2
3GENERATOR = re.compile('.*(<meta\s+(?:(?:name="generator"\s*)|' \
4                       '(?:content=".*?"\s*)){2}/>)', re.S|re.M)
5DESCRIPTION = re.compile('.*(<meta\s+(?:(?:name="description"\s*)|' \
6                         '(?:content=".*?"\s*)){2}/>)', re.S|re.M)
7
8class InstallMixin:
9
10    def prepare(self):
11        # Preparation for functional testing
12        self.loginAsPortalOwner()
13        self.my_doc = self.portal.invokeFactory('Document', id='my_doc')
14        self.my_doc = self.portal['my_doc']
15        self.my_doc.update(description="Document description")
16        self.portal.portal_workflow.doActionFor(self.my_doc, 'publish')
17        self.logout()
18        # Get document without customized canonical url
19        self.abs_path = "/%s" % self.my_doc.absolute_url(1)
20        self.html = self.publish(self.abs_path).getBody()
21
22
23class TestTagsDuplicationInstalled(InstallMixin, FunctionalTestCase):
24
25    def afterSetUp(self):
26        self.prepare()
27
28    def test_GeneratorMetaSEOInstalled(self):
29        lengen = len(GENERATOR.findall(self.html))
30        self.assert_(lengen==1, "There is %d generator meta tag(s) " \
31           "when seoptimizer installed" % lengen)
32 
33    def test_DescriptionMetaSEOInstalled(self):
34        lendesc = len(DESCRIPTION.findall(self.html))
35        self.assert_(lendesc==1, "There is %d DESCRIPTION meta tag(s) " \
36           "when seoptimizer installed" % lendesc)
37
38
39class TestTagsDuplicationNotInstalled(InstallMixin,
40                                      FunctionalTestCaseNotInstalled):
41
42    def afterSetUp(self):
43        self.prepare()
44
45    def test_GeneratorMetaSEOUninstalled(self):
46        lengen = len(GENERATOR.findall(self.html))
47        self.assert_(lengen<=1, "There is %d generator meta tag(s) " \
48            "when seoptimizer uninstalled" % lengen)
49
50    def test_DescriptionMetaSEOUninstalled(self):
51        lendesc = len(DESCRIPTION.findall(self.html))
52        self.assert_(lendesc==1, "There is %d DESCRIPTION meta tag(s) " \
53           "when seoptimizer uninstalled" % lendesc)
54
55
56def test_suite():
57    from unittest import TestSuite, makeSuite
58    suite = TestSuite()
59    suite.addTest(makeSuite(TestTagsDuplicationInstalled))
60    suite.addTest(makeSuite(TestTagsDuplicationNotInstalled))
61    return suite
Note: See TracBrowser for help on using the repository browser.