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

Last change on this file was 3547, checked in by ktarasz, 12 years ago

fix pep8

File size: 3.4 KB
RevLine 
[1876]1from DateTime import DateTime
[1493]2
[3140]3from quintagroup.seoptimizer.tests.base import FunctionalTestCase
4from Products.PloneTestCase.PloneTestCase import portal_owner, \
5    default_password
6import re
7
[3134]8METATAG = '.*(<meta\s+(?:(?:name="%s"\s*)|(?:content="(?P<tagcontent>.' \
9          '*?)"\s*)){2}/>)'
[1875]10
[3134]11
[1493]12class TestExposeDCMetaTags(FunctionalTestCase):
13
14    def afterSetUp(self):
15        self.sp = self.portal.portal_properties.site_properties
[3134]16        self.basic_auth = ':'.join((portal_owner, default_password))
[1875]17        self.loginAsPortalOwner()
18        # Preparation for functional testing
[1493]19        self.my_doc = self.portal.invokeFactory('Document', id='my_doc')
20        self.my_doc = self.portal['my_doc']
21
[1876]22    def test_propertyOff(self):
[3134]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)
[3547]28        self.assert_(not (m1 or m2), 'DC meta tags avaliable when '
[3134]29                     'exposeDCMetaTags=False')
[1493]30
[1876]31    def test_propertyOn(self):
[3134]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)
[3547]37        self.assert_(m1 and m2, 'DC meta tags not avaliable when '
[3134]38                     'createManager=True')
[1493]39
[1876]40    def test_descriptionInPropertyOff(self):
[3134]41        self.sp.manage_changeProperties(exposeDCMetaTags=False)
[1876]42        self.my_doc.setDescription("My document description")
[3134]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)
[3547]46        self.assert_(m, 'No "description" meta tag when expose DC meta tags '
[3134]47                     'is Off')
[1958]48
[1876]49    def test_descriptionInPropertyOn(self):
[3134]50        self.sp.manage_changeProperties(exposeDCMetaTags=True)
[1876]51        self.my_doc.setDescription("My document description")
[3134]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)
[3547]55        self.assert_(m, 'No "description" meta tag when expose DC meta tags '
[3134]56                     'is On')
[1958]57
[1876]58    def test_dateValidRange(self):
[3134]59        self.sp.manage_changeProperties(exposeDCMetaTags=True)
60        EFFDSTR, EXPDSTR = "2009/12/23", "2010/03/10"
[1876]61        self.my_doc.setExpirationDate(EXPDSTR)
62        self.my_doc.setEffectiveDate(EFFDSTR)
[3134]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)
[1876]66        content = m and m.group("tagcontent")
67        fact = content and map(DateTime, content.split("-"))
68        expect = map(DateTime, [EFFDSTR, EXPDSTR])
[3547]69        self.assert_(fact == expect, '"DC.date.valid_range" meta tags '
[3134]70                     'content="%s", but "%s" must be' % (fact, expect))
[1876]71
[3134]72
[1493]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.