Changeset 3152 in products for quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/tests/testSitemaps.py
- Timestamp:
- Apr 20, 2011 8:20:36 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/tests/testSitemaps.py
r3002 r3152 11 11 12 12 from quintagroup.plonegooglesitemaps.browser.sitemapview import SitemapView 13 from quintagroup.plonegooglesitemaps.browser.newssitemapview import NewsSitemapView 14 from quintagroup.plonegooglesitemaps.browser.mobilesitemapview import MobileSitemapView 13 from quintagroup.plonegooglesitemaps.browser.newssitemapview \ 14 import NewsSitemapView 15 from quintagroup.plonegooglesitemaps.browser.mobilesitemapview \ 16 import MobileSitemapView 15 17 16 18 … … 19 21 def afterSetUp(self): 20 22 super(TestSitemapType, self).afterSetUp() 21 self.contentSM = _createObjectByType('Sitemap', self.portal, id='google-sitemaps') 23 self.contentSM = _createObjectByType('Sitemap', self.portal, 24 id='google-sitemaps') 22 25 23 26 def testFields(self): 24 field_ids = map(lambda x:x.getName(), self.contentSM.Schema().fields()) 27 field_ids = map(lambda x: x.getName(), 28 self.contentSM.Schema().fields()) 25 29 # test old Sitemap settings fields 26 30 self.assert_('id' in field_ids) … … 34 38 35 39 def testSitemapTypes(self): 36 sitemap_types = self.contentSM.getField('sitemapType').Vocabulary().keys() 40 sm_vocabulary = self.contentSM.getField('sitemapType').Vocabulary() 41 sitemap_types = sm_vocabulary.keys() 37 42 self.assert_('content' in sitemap_types) 38 43 self.assert_('mobile' in sitemap_types) … … 40 45 41 46 def testAutoSetLayout(self): 42 response = self.publish('/%s/createObject?type_name=Sitemap' %\43 self.portal.absolute_url(1), basic=self.auth)47 response = self.publish('/%s/createObject?type_name=Sitemap' \ 48 % self.portal.absolute_url(1), basic=self.auth) 44 49 location = response.getHeader('location') 45 newurl = location[location.find('/' +self.portal.absolute_url(1)):]50 newurl = location[location.find('/' + self.portal.absolute_url(1)):] 46 51 47 52 msm_id = 'mobile_sitemap' 48 53 form = {'id': msm_id, 49 'sitemapType': 'mobile',50 'portalTypes': ['Document',],51 'states': ['published'],52 'form_submit': 'Save',53 'form.submitted': 1,54 'sitemapType': 'mobile', 55 'portalTypes': ['Document', ], 56 'states': ['published'], 57 'form_submit': 'Save', 58 'form.submitted': 1, 54 59 } 55 60 post_data = StringIO(urlencode(form)) 56 response = self.publish(newurl, request_method='POST', stdin=post_data, basic=self.auth) 61 response = self.publish(newurl, request_method='POST', stdin=post_data, 62 basic=self.auth) 57 63 msitemap = getattr(self.portal, msm_id) 58 64 … … 64 70 65 71 self.contentSM.setPingTransitions(('plone_workflow#publish',)) 66 self.assertEqual(self.contentSM.getPingTransitions(), ('plone_workflow#publish',)) 67 self.assert_(ping_googlesitemap in pwf.scripts.keys(),"Not add wf script") 72 self.assertEqual(self.contentSM.getPingTransitions(), 73 ('plone_workflow#publish',)) 74 self.assert_(ping_googlesitemap in pwf.scripts.keys(), 75 "Not add wf script") 68 76 69 77 def testWorkflowStates(self): … … 75 83 wftrans = self.contentSM.getWorkflowTransitions() 76 84 self.assertEqual(isinstance(wftrans, atapi.DisplayList), True) 77 self.assertEqual("simple_publication_workflow#publish" in wftrans.keys(), True) 85 self.assertEqual("simple_publication_workflow#publish" in \ 86 wftrans.keys(), True) 78 87 79 88 def testSettingBlackout(self): 80 bolist = ["path:./el1 ", " ",""," id:index.html ","index_html"]81 expect = ("path:./el1", "id:index.html","index_html")89 bolist = ["path:./el1 ", " ", "", " id:index.html ", "index_html"] 90 expect = ("path:./el1", "id:index.html", "index_html") 82 91 self.contentSM.edit(blackout_list=bolist) 83 92 value = self.contentSM.getBlackout_list() … … 90 99 def afterSetUp(self): 91 100 super(TestSettings, self).afterSetUp() 92 self.gsm_props = self.portal.portal_properties['googlesitemap_properties'] 93 self.contentSM = _createObjectByType('Sitemap', self.portal, id='google-sitemaps') 94 self.sitemapUrl = '/'+self.portal.absolute_url(1) + '/google-sitemaps' 101 gsm_properties = 'googlesitemap_properties' 102 self.gsm_props = self.portal.portal_properties[gsm_properties] 103 self.contentSM = _createObjectByType('Sitemap', self.portal, 104 id='google-sitemaps') 105 self.sitemapUrl = '/' + self.portal.absolute_url(1) + \ 106 '/google-sitemaps' 95 107 # Add testing document to portal 96 108 self.my_doc = _createObjectByType('Document', self.portal, id='my_doc') … … 141 153 self.assert_(not hasURL(sitemap, self.portal.absolute_url())) 142 154 143 regexp = "s/\/%s//" %self.my_doc.getId()155 regexp = "s/\/%s//" % self.my_doc.getId() 144 156 self.contentSM.setReg_exp([regexp]) 145 157 … … 163 175 def afterSetUp(self): 164 176 super(TestPinging, self).afterSetUp() 165 self.workflow.setChainForPortalTypes(pt_names=('News Item','Document'), 166 chain="simple_publication_workflow") 167 self.gsm_props = self.portal.portal_properties['googlesitemap_properties'] 177 self.workflow.setChainForPortalTypes(pt_names=('News Item', 178 'Document'), chain="simple_publication_workflow") 179 gsm_properties = 'googlesitemap_properties' 180 self.gsm_props = self.portal.portal_properties[gsm_properties] 168 181 # Add sitemaps 169 self.contentSM = _createObjectByType('Sitemap', self.portal, id='google-sitemaps') 170 self.contentSM.setPingTransitions(('simple_publication_workflow#publish',)) 171 self.newsSM = _createObjectByType('Sitemap', self.portal, id='news-sitemaps') 172 self.newsSM.setPortalTypes(('News Item','Document')) 173 self.newsSM.setPingTransitions(('simple_publication_workflow#publish',)) 174 self.sitemapUrl = '/'+self.portal.absolute_url(1) + '/google-sitemaps' 182 self.contentSM = _createObjectByType('Sitemap', self.portal, 183 id='google-sitemaps') 184 spw_publish = 'simple_publication_workflow#publish' 185 self.contentSM.setPingTransitions((spw_publish,)) 186 self.newsSM = _createObjectByType('Sitemap', self.portal, 187 id='news-sitemaps') 188 self.newsSM.setPortalTypes(('News Item', 'Document')) 189 self.newsSM.setPingTransitions((spw_publish,)) 190 self.sitemapUrl = '/' + self.portal.absolute_url(1) + \ 191 '/google-sitemaps' 175 192 # Add testing document to portal 176 193 self.my_doc = _createObjectByType('Document', self.portal, id='my_doc') 177 self.my_news = _createObjectByType('News Item', self.portal, id='my_news') 194 self.my_news = _createObjectByType('News Item', self.portal, 195 id='my_news') 178 196 179 197 def testAutomatePinging(self): … … 188 206 sys.stdout = back_out 189 207 190 self.assert_('Pinged %s sitemap to Google' % self.contentSM.absolute_url() in data, 208 self.assert_('Pinged %s sitemap to Google' \ 209 % self.contentSM.absolute_url() in data, 191 210 "Not pinged %s: '%s'" % (self.contentSM.id, data)) 192 self.assert_('Pinged %s sitemap to Google' % self.newsSM.absolute_url() in data, 211 self.assert_('Pinged %s sitemap to Google' \ 212 % self.newsSM.absolute_url() in data, 193 213 "Not pinged %s: '%s'" % (self.newsSM.id, data)) 194 214 … … 203 223 sys.stdout = back_out 204 224 205 self.assert_('Pinged %s sitemap to Google' % self.newsSM.absolute_url() in data, 225 self.assert_('Pinged %s sitemap to Google' \ 226 % self.newsSM.absolute_url() in data, 206 227 "Not pinged %s: '%s'" % (self.newsSM.id, data)) 207 self.assert_(not 'Pinged %s sitemap to Google' % self.contentSM.absolute_url() in data, 228 self.assert_(not 'Pinged %s sitemap to Google' \ 229 % self.contentSM.absolute_url() in data, 208 230 "Pinged %s on news: '%s'" % (self.contentSM.id, data)) 209 231 210 232 def testPingingWithSetupForm(self): 211 233 # Ping news and content sitemaps 212 formUrl = '/' +self.portal.absolute_url(1) + '/prefs_gsm_settings'213 qs = 'smselected:list=%s&smselected:list=%s&form.button.Ping=1 &form.submitted=1' %\214 (self.contentSM.id, self.newsSM.id)234 formUrl = '/' + self.portal.absolute_url(1) + '/prefs_gsm_settings' 235 qs = 'smselected:list=%s&smselected:list=%s&form.button.Ping=1' \ 236 '&form.submitted=1' % (self.contentSM.id, self.newsSM.id) 215 237 216 238 back_out, myout = sys.stdout, StringIO() … … 223 245 sys.stdout = back_out 224 246 225 self.assert_('Pinged %s sitemap to Google' % self.contentSM.absolute_url() in data, 247 self.assert_('Pinged %s sitemap to Google' \ 248 % self.contentSM.absolute_url() in data, 226 249 "Not pinged %s: '%s'" % (self.contentSM.id, data)) 227 self.assert_('Pinged %s sitemap to Google' % self.newsSM.absolute_url() in data, 250 self.assert_('Pinged %s sitemap to Google' \ 251 % self.newsSM.absolute_url() in data, 228 252 "Not pinged %s: '%s'" % (self.newsSM.id, data)) 229 253 … … 241 265 self.sm.at_post_create_script() 242 266 # Add content in root and in the test folder 243 pubdate = (DateTime()+1).strftime("%Y-%m-%d") 244 root_content = _createObjectByType(ptypes[0], self.portal, id='root-content') 245 inner_content = _createObjectByType(ptypes[0], tfolder, id='inner-content') 267 pubdate = (DateTime() + 1).strftime("%Y-%m-%d") 268 root_content = _createObjectByType(ptypes[0], self.portal, 269 id='root-content') 270 inner_content = _createObjectByType(ptypes[0], tfolder, 271 id='inner-content') 246 272 for obj in (root_content, inner_content): 247 273 self.workflow.doActionFor(obj, 'publish') 248 274 if ifaces: 249 275 alsoProvides(obj, ifaces) 250 obj.edit(effectiveDate=pubdate) # this also reindex object276 obj.edit(effectiveDate=pubdate) # this also reindex object 251 277 self.inner_path = '/'.join(inner_content.getPhysicalPath()) 252 278 253 279 def testGoogleSitemap(self): 254 280 self.prepareTestContent("content", ("Document",)) 255 281 filtered = SitemapView(self.sm, TestRequest()).getFilteredObjects() 256 self.assertEqual(map(lambda x:x.getPath(), filtered), [self.inner_path,]) 282 self.assertEqual(map(lambda x: x.getPath(), filtered), 283 [self.inner_path, ]) 257 284 258 285 def testNewsSitemap(self): 259 286 self.prepareTestContent("news", ("News Item",)) 260 287 filtered = NewsSitemapView(self.sm, TestRequest()).getFilteredObjects() 261 self.assertEqual(map(lambda x:x.getPath(), filtered), [self.inner_path,]) 288 self.assertEqual(map(lambda x: x.getPath(), filtered), 289 [self.inner_path, ]) 262 290 263 291 def testMobileSitemap(self): 264 292 self.patchMobile() 265 293 self.prepareTestContent("content", ("Document",), (IMobileMarker,)) 266 filtered = MobileSitemapView(self.sm, TestRequest()).getFilteredObjects() 267 self.assertEqual(map(lambda x:x.getPath(), filtered), [self.inner_path,]) 294 filtered = MobileSitemapView(self.sm, 295 TestRequest()).getFilteredObjects() 296 self.assertEqual(map(lambda x: x.getPath(), filtered), 297 [self.inner_path, ]) 268 298 269 299
Note: See TracChangeset
for help on using the changeset viewer.