Changeset 1890 in products for quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/testResponse.py
- Timestamp:
- Mar 11, 2010 3:51:07 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.seoptimizer/branches/refactoring2.3.0/quintagroup/seoptimizer/tests/testResponse.py
r1889 r1890 15 15 ] 16 16 17 FORM _DATA= {17 FORM = { 18 18 'seo_robots': 'ALL', 19 19 'form.submitted:int': 1, … … 31 31 'seo_description': 'it is description, test keyword1', 32 32 } 33 34 METATAG = '.*(<meta\s+(?:(?:name="%s"\s*)|(?:content="%s"\s*)){2}/>)' 33 35 34 36 class TestResponse(FunctionalTestCase): … … 58 60 self.publish(path=self.abs_path+'/@@seo-context-properties', 59 61 basic=self.basic_auth, request_method='POST', 60 stdin=StringIO(urllib.urlencode(FORM _DATA)+st))62 stdin=StringIO(urllib.urlencode(FORM)+st)) 61 63 self.wf.doActionFor(my_doc, 'publish') 62 64 # get html view of test document … … 73 75 """ 74 76 # setup page with title equal to plone site's title 75 my_doc2 = self.portal.invokeFactory('Document', id='my_doc2', title=self.portal.Title()) 77 my_doc2 = self.portal.invokeFactory('Document', id='my_doc2', 78 title=self.portal.Title()) 76 79 my_doc2 = self.portal['my_doc2'] 77 80 self.wf.doActionFor(my_doc2, 'publish') … … 82 85 83 86 def testDescription(self): 84 m = re.match( '.*(<meta\s+(?:(?:name="description"\s*)|(?:content="it is description, test keyword1"\s*)){2}/>)', self.html, re.S|re.M)87 m = re.match(METATAG % ("description", FORM['seo_description']), self.html, re.S|re.M) 85 88 self.assert_(m, 'Description not set in') 86 89 87 90 def testRobots(self): 88 m = re.match( '.*(<meta\s+(?:(?:name="robots"\s*)|(?:content="ALL"\s*)){2}/>)', self.html, re.S|re.M)91 m = re.match(METATAG % ("robots", FORM['seo_robots']), self.html, re.S|re.M) 89 92 self.assert_(m, 'Robots not set in') 90 93 91 94 def testDistribution(self): 92 m = re.match( '.*(<meta\s+(?:(?:name="distribution"\s*)|(?:content="Global"\s*)){2}/>)', self.html, re.S|re.M)95 m = re.match(METATAG % ("distribution", FORM['seo_distribution']), self.html, re.S|re.M) 93 96 self.assert_(m, 'Distribution not set in') 94 97 … … 98 101 99 102 def testTagsOrder(self): 103 def is_match(html, mtorder): 104 return re.search('.*'.join(['<meta.*name="%s".*/>' %t \ 105 for t in mtorder]), html, re.S|re.M) 106 100 107 metatags_order = [t for t in self.sp.getProperty('metatags_order') if t in VIEW_METATAGS] 101 m = re.search('.*'.join(['<meta.*name="%s".*/>' %t for t in metatags_order]), self.html, re.S|re.M) 102 self.assert_(m, "Meta tags order not supported.") 108 self.assert_(is_match(self.html, metatags_order), "Meta tags order not supported.") 103 109 104 110 metatags_order.reverse() 105 m = re.search('.*'.join(['<meta.*name="%s".*/>' %t for t in metatags_order]), self.html, re.S|re.M) 106 self.assertFalse(m, "Meta tags order not supported.") 111 self.assertFalse(is_match(self.html, metatags_order), "Meta tags order not supported.") 107 112 108 self.sp.manage_changeProperties(**{'metatags_order':metatags_order}) 113 self.sp.manage_changeProperties(metatags_order = metatags_order) 114 self.assertFalse(is_match(self.html, metatags_order), "Meta tags order not supported.") 115 109 116 html = self.publish(self.abs_path, self.basic_auth).getBody() 110 m = re.search('.*'.join(['<meta.*name="%s".*/>' %t for t in metatags_order]), self.html, re.S|re.M) 111 self.assertFalse(m, "Meta tags order not supported.") 112 113 m = re.search('.*'.join(['<meta.*name="%s".*/>' %t for t in metatags_order]), html, re.S|re.M) 114 self.assert_(m, "Meta tags order not supported.") 117 self.assert_(is_match(html, metatags_order), "Meta tags order not supported.") 115 118 116 119 117 120 def testCustomMetaTags(self): 118 121 for tag in CUSTOM_METATAGS: 119 m = re.match('.*(<meta\s+(?:(?:name="%(meta_name)s"\s*)|(?:content="%(meta_content)s"\s*)){2}/>)' % tag, self.html, re.S|re.M) 122 m = re.match(METATAG % (tag['meta_name'], tag['meta_content']), 123 self.html, re.S|re.M) 120 124 if tag['meta_content']: 121 125 self.assert_(m, "Custom meta tag %s not applied." % tag['meta_name']) 122 126 else: 123 self.assert_(not m, "Meta tag %s has no content, but is present in the page." % tag['meta_name']) 124 m = re.match('.*(<meta\s+(?:(?:name="metatag4"\s*)|(?:content="global_metatag4value"\s*)){2}/>)', self.html, re.S|re.M) 127 self.assert_(not m, "Meta tag %s has no content, but is present:" \ 128 " in the page." % tag['meta_name']) 129 130 m = re.match(METATAG % ("metatag4", "global_metatag4value"), self.html, re.S|re.M) 125 131 self.assert_(m, "Global custom meta tag %s not applied." % 'metatag4') 126 132 127 133 def testDeleteCustomMetaTags(self): 128 self.sp.manage_changeProperties(**{'default_custom_metatags':'metatag1|global_metatag1value'}) 134 self.sp.manage_changeProperties( 135 default_custom_metatags = 'metatag1|global_metatag1value') 129 136 form_data = {'seo_custommetatags': CUSTOM_METATAGS, 130 137 'seo_custommetatags_override:int': 0, … … 133 140 basic=self.basic_auth, request_method='POST', 134 141 stdin=StringIO(urllib.urlencode(form_data))) 135 self.html = self.publish(self.abs_path, self.basic_auth).getBody() 136 m = re.match('.*(<meta\s+(?:(?:name="metatag4"\s*)|(?:content="global_metatag4value"\s*)){2}/>)', self.html, re.S|re.M) 142 html = self.publish(self.abs_path, self.basic_auth).getBody() 143 144 m = re.match(METATAG % ("metatag4", "global_metatag4value"), html, re.S|re.M) 137 145 self.assert_(not m, "Global custom meta tag %s is prosent in the page." % 'metatag4') 138 m = re.match('.*(<meta\s+(?:(?:name="metatag1"\s*)|(?:content="global_metatag1value"\s*)){2}/>)', self.html, re.S|re.M) 146 147 m = re.match(METATAG % ("metatag1", "global_metatag1value"), html, re.S|re.M) 139 148 self.assert_(m, "Global custom meta tag %s not applied." % 'metatag1') 140 149
Note: See TracChangeset
for help on using the changeset viewer.