Changeset 3134 in products for quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/tests/testContextForm.py
- Timestamp:
- Apr 18, 2011 2:32:21 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.seoptimizer/trunk/quintagroup/seoptimizer/tests/testContextForm.py
r3012 r3134 35 35 METATAG = '.*(<meta\s+(?:(?:name="%s"\s*)|(?:content="%s"\s*)){2}/>)' 36 36 37 37 38 class TestContextForm(FunctionalTestCase): 38 39 … … 42 43 self.wf = self.portal.portal_workflow 43 44 44 self.basic_auth = ':'.join((portal_owner, default_password))45 self.basic_auth = ':'.join((portal_owner, default_password)) 45 46 self.loginAsPortalOwner() 46 47 … … 51 52 self.abs_path = "/%s" % my_doc.absolute_url(1) 52 53 # prepare seo context form data 53 self.sp.manage_changeProperties( 54 default_custom_metatags = 'metatag1|global_metatag1value\n' \55 'metatag4|global_metatag4value')54 self.sp.manage_changeProperties(default_custom_metatags='metatag1|' \ 55 'global_metatag1value\nmetatag4|' \ 56 'global_metatag4value') 56 57 st = '' 57 58 for d in CUSTOM_METATAGS: 58 59 st += '&seo_custommetatags.meta_name:records=%s' % d['meta_name'] 59 st += '&seo_custommetatags.meta_content:records=%s' % d['meta_content'] 60 st += '&seo_custommetatags.meta_content:records=%s' \ 61 % d['meta_content'] 60 62 # update seo properties for the test document and publish it 61 self.publish(path=self.abs_path +'/@@seo-context-properties',63 self.publish(path=self.abs_path + '/@@seo-context-properties', 62 64 basic=self.basic_auth, request_method='POST', 63 stdin=StringIO(urllib.urlencode(FORM) +st))65 stdin=StringIO(urllib.urlencode(FORM) + st)) 64 66 self.wf.doActionFor(my_doc, 'publish') 65 67 # get html view of test document 66 68 self.html = self.publish(self.abs_path, self.basic_auth).getBody() 67 69 68 69 70 def testTitle(self): 70 m = re.match('.*<title>\\s*hello world\\s*</title>', self.html, re.S|re.M) 71 m = re.match('.*<title>\\s*hello world\\s*</title>', self.html, 72 re.S | re.M) 71 73 self.assert_(m, 'Title not set in') 72 74 73 75 def testTitleDuplication(self): 74 """If we are not overriding page title and current page title equals title of the plone site 75 then there should be no concatenation of both titles. Only one should be displayed. 76 """If we are not overriding page title and current page title equals 77 title of the plone site then there should be no concatenation of 78 both titles. Only one should be displayed. 76 79 """ 77 80 # setup page with title equal to plone site's title … … 80 83 my_doc2 = self.portal['my_doc2'] 81 84 self.wf.doActionFor(my_doc2, 'publish') 82 html2 = self.publish('/'+my_doc2.absolute_url(1), self.basic_auth).getBody() 85 html2 = self.publish('/' + my_doc2.absolute_url(1), 86 self.basic_auth).getBody() 83 87 84 m = re.match('.*<title>\\s*%s\\s*</title>' % self.portal.Title(), html2, re.S|re.M) 85 self.assert_(m, 'Title is not set correctly, perhaps it is duplicated with plone site title') 88 m = re.match('.*<title>\\s*%s\\s*</title>' % self.portal.Title(), 89 html2, re.S | re.M) 90 self.assert_(m, 'Title is not set correctly, perhaps it is ' \ 91 'duplicated with plone site title') 86 92 87 93 def testDescription(self): 88 m = re.match(METATAG % ("description", FORM['seo_description']), self.html, re.S|re.M) 94 m = re.match(METATAG % ("description", FORM['seo_description']), 95 self.html, re.S | re.M) 89 96 self.assert_(m, 'Description not set in') 90 97 91 98 def testRobots(self): 92 m = re.match(METATAG % ("robots", FORM['seo_robots']), self.html, re.S|re.M) 99 m = re.match(METATAG % ("robots", FORM['seo_robots']), self.html, 100 re.S | re.M) 93 101 self.assert_(m, 'Robots not set in') 94 102 95 103 def testDistribution(self): 96 m = re.match(METATAG % ("distribution", FORM['seo_distribution']), self.html, re.S|re.M) 104 m = re.match(METATAG % ("distribution", FORM['seo_distribution']), 105 self.html, re.S | re.M) 97 106 self.assert_(m, 'Distribution not set in') 98 107 99 108 def testHTMLComments(self): 100 m = re.match('.*<!--\\s*no comments\\s*-->', self.html, re.S |re.M)109 m = re.match('.*<!--\\s*no comments\\s*-->', self.html, re.S | re.M) 101 110 self.assert_(m, 'Comments not set in') 102 111 103 112 def testTagsOrder(self): 104 113 def is_match(html, mtorder): 105 return re.search('.*'.join(['<meta.*name="%s".*/>' % t \106 for t in mtorder]), html, re.S |re.M)114 return re.search('.*'.join(['<meta.*name="%s".*/>' % t \ 115 for t in mtorder]), html, re.S | re.M) 107 116 108 metatags_order = [t for t in self.sp.getProperty('metatags_order') if t in VIEW_METATAGS] 109 self.assert_(is_match(self.html, metatags_order), "Meta tags order not supported.") 117 metatags_order = [t for t in self.sp.getProperty('metatags_order') \ 118 if t in VIEW_METATAGS] 119 self.assert_(is_match(self.html, metatags_order), 120 "Meta tags order not supported.") 110 121 111 122 metatags_order.reverse() 112 self.assertFalse(is_match(self.html, metatags_order), "Meta tags order not supported.") 123 self.assertFalse(is_match(self.html, metatags_order), 124 "Meta tags order not supported.") 113 125 114 self.sp.manage_changeProperties(metatags_order = metatags_order) 115 self.assertFalse(is_match(self.html, metatags_order), "Meta tags order not supported.") 126 self.sp.manage_changeProperties(metatags_order=metatags_order) 127 self.assertFalse(is_match(self.html, metatags_order), 128 "Meta tags order not supported.") 116 129 117 130 html = self.publish(self.abs_path, self.basic_auth).getBody() 118 self.assert_(is_match(html, metatags_order), "Meta tags order not supported.")119 131 self.assert_(is_match(html, metatags_order), 132 "Meta tags order not supported.") 120 133 121 134 def testCustomMetaTags(self): 122 135 for tag in CUSTOM_METATAGS: 123 136 m = re.match(METATAG % (tag['meta_name'], tag['meta_content']), 124 self.html, re.S |re.M)137 self.html, re.S | re.M) 125 138 if tag['meta_content']: 126 self.assert_(m, "Custom meta tag %s not applied." % tag['meta_name']) 139 self.assert_(m, "Custom meta tag %s not applied." \ 140 % tag['meta_name']) 127 141 else: 128 self.assert_(not m, "Meta tag %s has no content, but is present:" \129 "in the page." % tag['meta_name'])142 self.assert_(not m, "Meta tag %s has no content, but is " \ 143 "present: in the page." % tag['meta_name']) 130 144 131 m = re.match(METATAG % ("metatag4", "global_metatag4value"), self.html, re.S|re.M) 145 m = re.match(METATAG % ("metatag4", "global_metatag4value"), self.html, 146 re.S | re.M) 132 147 self.assert_(m, "Global custom meta tag %s not applied." % 'metatag4') 133 148 134 149 def testDeleteCustomMetaTags(self): 135 self.sp.manage_changeProperties( 136 default_custom_metatags = 'metatag1|global_metatag1value')150 self.sp.manage_changeProperties(default_custom_metatags='metatag1|' \ 151 'global_metatag1value') 137 152 form_data = {'seo_custommetatags': CUSTOM_METATAGS, 138 153 'seo_custommetatags_override:int': 0, … … 143 158 getUtility(IRAMCache).invalidateAll() 144 159 145 self.publish(path=self.abs_path +'/@@seo-context-properties',160 self.publish(path=self.abs_path + '/@@seo-context-properties', 146 161 basic=self.basic_auth, request_method='POST', 147 162 stdin=StringIO(urllib.urlencode(form_data))) 148 163 html = self.publish(self.abs_path, self.basic_auth).getBody() 149 164 150 m = re.match(METATAG % ("metatag4", "global_metatag4value"), html, re.S|re.M) 151 self.assert_(not m, "Global custom meta tag %s is prosent in the page." % 'metatag4') 165 m = re.match(METATAG % ("metatag4", "global_metatag4value"), html, 166 re.S | re.M) 167 self.assert_(not m, "Global custom meta tag %s is prosent in the " \ 168 "page." % 'metatag4') 152 169 153 m = re.match(METATAG % ("metatag1", "global_metatag1value"), html, re.S|re.M) 170 m = re.match(METATAG % ("metatag1", "global_metatag1value"), html, 171 re.S | re.M) 154 172 self.assert_(m, "Global custom meta tag %s not applied." % 'metatag1') 173 155 174 156 175 def test_suite():
Note: See TracChangeset
for help on using the changeset viewer.