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

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

#161: Extend 'Expose DC metatags' tests

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