source: products/quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/tests/testExposeDCMetaTags.py @ 3223

Last change on this file since 3223 was 3141, checked in by zidane, 13 years ago

fixes pyflakes

File size: 3.4 KB
Line 
1from DateTime import DateTime
2
3from quintagroup.seoptimizer.tests.base import FunctionalTestCase
4from Products.PloneTestCase.PloneTestCase import portal_owner, \
5    default_password
6import re
7
8METATAG = '.*(<meta\s+(?:(?:name="%s"\s*)|(?:content="(?P<tagcontent>.' \
9          '*?)"\s*)){2}/>)'
10
11
12class TestExposeDCMetaTags(FunctionalTestCase):
13
14    def afterSetUp(self):
15        self.sp = self.portal.portal_properties.site_properties
16        self.basic_auth = ':'.join((portal_owner, default_password))
17        self.loginAsPortalOwner()
18        # Preparation for functional testing
19        self.my_doc = self.portal.invokeFactory('Document', id='my_doc')
20        self.my_doc = self.portal['my_doc']
21
22    def test_propertyOff(self):
23        self.sp.manage_changeProperties(exposeDCMetaTags=False)
24        self.html = str(self.publish(self.portal.id + '/my_doc',
25                                     self.basic_auth))
26        m1 = re.match(METATAG % "DC.format", self.html, re.S | re.M)
27        m2 = re.match(METATAG % "DC.distribution", self.html, re.S | re.M)
28        self.assert_(not (m1 or m2), 'DC meta tags avaliable when ' \
29                     'exposeDCMetaTags=False')
30
31    def test_propertyOn(self):
32        self.sp.manage_changeProperties(exposeDCMetaTags=True)
33        self.html = str(self.publish(self.portal.id + '/my_doc',
34                                     self.basic_auth))
35        m1 = re.match(METATAG % "DC.format", self.html, re.S | re.M)
36        m2 = re.match(METATAG % "DC.type", self.html, re.S | re.M)
37        self.assert_(m1 and m2, 'DC meta tags not avaliable when ' \
38                     'createManager=True')
39
40    def test_descriptionInPropertyOff(self):
41        self.sp.manage_changeProperties(exposeDCMetaTags=False)
42        self.my_doc.setDescription("My document description")
43        self.html = str(self.publish(self.portal.id + '/my_doc',
44                                     self.basic_auth))
45        m = re.match(METATAG % "description", self.html, re.S | re.M)
46        self.assert_(m, 'No "description" meta tag when expose DC meta tags ' \
47                     'is Off')
48
49    def test_descriptionInPropertyOn(self):
50        self.sp.manage_changeProperties(exposeDCMetaTags=True)
51        self.my_doc.setDescription("My document description")
52        self.html = str(self.publish(self.portal.id + '/my_doc',
53                                     self.basic_auth))
54        m = re.match(METATAG % "description", self.html, re.S | re.M)
55        self.assert_(m, 'No "description" meta tag when expose DC meta tags ' \
56                     'is On')
57
58    def test_dateValidRange(self):
59        self.sp.manage_changeProperties(exposeDCMetaTags=True)
60        EFFDSTR, EXPDSTR = "2009/12/23", "2010/03/10"
61        self.my_doc.setExpirationDate(EXPDSTR)
62        self.my_doc.setEffectiveDate(EFFDSTR)
63        self.html = str(self.publish(self.portal.id + '/my_doc',
64                                     self.basic_auth))
65        m = re.match(METATAG % "DC.date.valid_range", self.html, re.S | re.M)
66        content = m and m.group("tagcontent")
67        fact = content and map(DateTime, content.split("-"))
68        expect = map(DateTime, [EFFDSTR, EXPDSTR])
69        self.assert_(fact == expect, '"DC.date.valid_range" meta tags ' \
70                     'content="%s", but "%s" must be' % (fact, expect))
71
72
73def test_suite():
74    from unittest import TestSuite, makeSuite
75    suite = TestSuite()
76    suite.addTest(makeSuite(TestExposeDCMetaTags))
77    return suite
Note: See TracBrowser for help on using the repository browser.