source: products/quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/testExposeDCMetaTags.py @ 1877

Last change on this file since 1877 was 1877, checked in by mylan, 14 years ago

Remove config module from tests, move all constants into testInstallation and testResponce modules

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