Changeset 3402 in products for quintagroup.plonetabs/branches/tests/quintagroup/plonetabs/tests/test_controlpanel.py
- Timestamp:
- Apr 2, 2012 1:04:35 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.plonetabs/branches/tests/quintagroup/plonetabs/tests/test_controlpanel.py
r917 r3402 10 10 from quintagroup.plonetabs import messageFactory as _ 11 11 from quintagroup.plonetabs.browser.interfaces import IPloneTabsControlPanel 12 from quintagroup.plonetabs.browser.plonetabs import PloneTabsControlPanel as ptp 12 from quintagroup.plonetabs.browser.plonetabs \ 13 import PloneTabsControlPanel as ptp 13 14 from quintagroup.plonetabs.tests.base import PloneTabsTestCase 14 15 from quintagroup.plonetabs.tests.data import PORTAL_ACTIONS 15 16 17 16 18 class TestControlPanelHelperMethods(PloneTabsTestCase): 17 19 """Test here configlet helper methods""" 18 19 20 def afterSetUp(self): 20 21 super(TestControlPanelHelperMethods, self).afterSetUp() … … 25 26 self.panel = panel.__of__(self.portal) 26 27 self.tool = getToolByName(self.portal, 'portal_actions') 27 28 28 29 def test_redirect(self): 29 30 response = self.portal.REQUEST.RESPONSE 30 31 method = self.panel.redirect 31 portal_url = 32 portal_url = getMultiAdapter((self.portal, self.portal.REQUEST), 32 33 name=u"plone_portal_state").portal_url() 33 34 url = '%s/@@plonetabs-controlpanel' % portal_url … … 35 36 self.assertEquals(response.headers.get('location', ''), url, 36 37 'Redirect method is not working properly.') 37 38 38 39 # check query string and anchor hash 39 40 method('http://quintagroup.com', 'q=test', 'hash_code') … … 41 42 'http://quintagroup.com?q=test#hash_code', 42 43 'Redirect method is not working properly.') 43 44 44 45 def test_fixExpression(self): 45 46 method = self.panel.fixExpression 46 47 self.assertEquals(method('/slash'), 'string:${portal_url}/slash') 47 self.assertEquals(method('https://test.com'), 'string:https://test.com') 48 self.assertEquals(method('https://test.com'), 49 'string:https://test.com') 48 50 self.assertEquals(method('python:True'), 'python:True') 49 51 self.assertEquals(method('hello'), 'string:${object_url}/hello') 50 52 51 53 def test_copyAction(self): 52 54 data = PORTAL_ACTIONS[0][1]['children'][0][1] … … 55 57 self.assertEquals(len(info.keys()), 6) 56 58 self.assertEquals(info['description'], 'The most important place') 57 59 58 60 def test_validateActionFields(self): 59 61 method = self.panel.validateActionFields … … 63 65 self.assertEquals(errors, {}, 64 66 'There should be no errors for valid data.') 65 66 bad_data = {'id': '',67 68 bad_data = {'id': '', 67 69 'title': ' ', 68 70 'available_expr': 'bad_type:test', 69 71 'url_expr': 'bad_type:test'} 70 72 71 73 # Revert PloneTestCase's optimization 72 74 # because this breaks our test … … 81 83 # rollback our patch 82 84 Expression.__init__ = optimized__init__ 83 85 84 86 self.assertEquals(len(errors.keys()), 4, 85 87 'validateActionFields method is not working properly.') 86 88 87 89 def test_processErrors(self): 88 90 method = self.panel.processErrors 89 errors = {'error': 'error message'}91 errors = {'error': 'error message'} 90 92 self.assertEquals(method(errors), errors, 91 93 'processErrors method is not working properly.') … … 93 95 {'pre_error_post': 'error message'}, 94 96 'processErrors method is not working properly.') 95 97 96 98 def test_parseEditForm(self): 97 99 method = self.panel.parseEditForm … … 110 112 'visible': True}), 111 113 'parseEditForm method is not working properly.') 112 114 113 115 del form['orig_id'] 114 116 self.failUnlessRaises(KeyError, method, form) 115 117 116 118 def test_parseAddForm(self): 117 119 method = self.panel.parseAddForm … … 129 131 'available_expr': 'expr2'}), 130 132 'parseAddForm method is not working properly.') 131 133 132 134 del form['id'] 133 135 self.failUnlessRaises(KeyError, method, form) 134 136 135 137 def test_getActionCategory(self): 136 138 method = self.panel.getActionCategory 137 139 self.purgeActions() 138 140 self.failUnlessRaises(KeyError, method, 'portal_tabs') 139 141 140 142 self.setupActions(self.tool) 141 143 self.assertEquals(method('portal_tabs').id, 'portal_tabs', 142 144 'getActionCategory is not working properly.') 143 145 144 146 def test_getOrCreateCategory(self): 145 147 method = self.panel.getOrCreateCategory … … 147 149 self.assertEquals(method('portal_tabs').id, 'portal_tabs', 148 150 'getOrCreateCategory is not working properly.') 149 151 150 152 def test_setSiteProperties(self): 151 153 self.panel.setSiteProperties(title='Test Title') … … 153 155 self.assertEquals(sp.getProperty('title'), 'Test Title', 154 156 'setSiteProperties method is not working properly.') 155 157 156 158 def test_renderViewlet(self): 157 159 # register test viewlet and it's manager … … 161 163 from zope.publisher.interfaces.browser import IDefaultBrowserLayer 162 164 from zope.publisher.interfaces.browser import IBrowserView 165 163 166 class TestViewlet(ViewletBase): 164 167 def __of__(self, obj): 165 168 return self 169 166 170 def render(self): 167 171 return 'test viewlet' 172 168 173 provideAdapter( 169 174 TestViewlet, … … 176 181 IViewletManager, 177 182 name=u'test_manager') 178 183 179 184 self.assertEquals( 180 185 self.panel.renderViewlet('test_manager', 'test_viewlet'), 181 186 'test viewlet', 182 187 'renderViewlet method is not workig properly') 183 188 184 189 def test_addAction(self): 185 190 self.purgeActions() 186 self.panel.addAction('new_category', {'id': 'id1', 'title':'Test'})191 self.panel.addAction('new_category', {'id': 'id1', 'title': 'Test'}) 187 192 self.failUnless('id1' in self.tool.new_category.objectIds(), 188 193 'addAction method is not workig properly') 189 194 190 195 def test_updateAction(self): 191 196 method = self.panel.updateAction 192 193 self.purgeActions() 194 self.failUnlessRaises(KeyError, method, 'id1', 'cat1', {'id': 'new'})195 197 198 self.purgeActions() 199 self.failUnlessRaises(KeyError, method, 'id1', 'cat1', {'id': 'new'}) 200 196 201 self.setupActions(self.tool) 197 202 # we need to commit transaction because … … 199 204 import transaction 200 205 transaction.savepoint() 201 method('home', 'portal_tabs', {'id': 'new_home'})206 method('home', 'portal_tabs', {'id': 'new_home'}) 202 207 self.failUnless('new_home' in self.tool.portal_tabs.objectIds(), 203 208 'updateAction method is not workig properly') 204 209 205 210 def test_deleteAction(self): 206 211 self.purgeActions() … … 209 214 self.failIf('home' in self.tool.portal_tabs.objectIds(), 210 215 'deleteAction method is not workig properly') 211 216 212 217 def test_moveAction(self): 213 218 self.purgeActions() … … 223 228 class TestControlPanelAPIMethods(PloneTabsTestCase): 224 229 """Test here interface methods of control panel class""" 225 230 226 231 def afterSetUp(self): 227 232 super(TestControlPanelAPIMethods, self).afterSetUp() … … 232 237 self.panel = panel.__of__(self.portal) 233 238 self.tool = getToolByName(self.portal, 'portal_actions') 234 239 235 240 def test_interface(self): 236 241 self.failUnless(IPloneTabsControlPanel.implementedBy(ptp), … … 238 243 self.failUnless(verifyClass(IPloneTabsControlPanel, ptp), 239 244 'PloneTabs control panel does not implement required interface.') 240 245 241 246 def test_getPageTitle(self): 242 247 self.assertEquals(self.panel.getPageTitle(), … … 247 252 mapping={'cat_name': 'notexists'}), 248 253 'getPageTitle method is broken') 249 254 250 255 def test_hasActions(self): 251 256 method = self.panel.hasActions … … 254 259 self.failIf(method(), 255 260 'There should be no portal_tab actions in portal') 256 261 257 262 # setup our own actions 258 263 self.setupActions(self.tool) 259 264 self.failUnless(method(), 260 265 'There should be portal_tab actions in portal') 261 266 262 267 def test_getPortalActions(self): 263 268 method = self.panel.getPortalActions … … 266 271 self.assertEquals(len(method()), 0, 267 272 'There should be no actions in portal_tabs category.') 268 273 269 274 # setup our own actions 270 275 self.setupActions(self.tool) 271 276 self.assertEquals(len(method()), 2, 272 277 'There should be 2 actions in portal_tabs category.') 273 278 274 279 # marginal arguments 275 280 self.assertEquals(len(method('notexistent_category')), 0, 276 281 'There should be no actions for not existed category.') 277 282 278 283 def test_isGeneratedTabs(self): 279 284 method = self.panel.isGeneratedTabs … … 282 287 sp.manage_changeProperties(disable_folder_sections=True) 283 288 self.failIf(method(), 'But folder sections are disabled...') 284 289 285 290 def test_isNotFoldersGenerated(self): 286 291 method = self.panel.isNotFoldersGenerated … … 289 294 sp.manage_changeProperties(disable_nonfolderish_sections=True) 290 295 self.failIf(method(), 'But non folderish sections are disabled...') 291 296 292 297 def test_getActionsList(self): 293 298 method = self.panel.getActionsList … … 299 304 self.failUnless('class="editform"' in method(), 300 305 'There are no actions in actions list template.') 301 306 302 307 def test_getAutoGenereatedSection(self): 303 308 method = self.panel.getAutoGenereatedSection … … 308 313 'There should be form in autogenerated tabs template ' 309 314 'for portal_tabs category.') 310 315 311 316 def test_getGeneratedTabs(self): 312 317 self.panel.getGeneratedTabs() … … 316 321 'Mon, 26 Jul 1996 05:00:00 GMT', 317 322 'Expiration header is not set properly.') 318 323 319 324 def test_getRootTabs(self): 320 325 method = self.panel.getRootTabs … … 323 328 self.assertEquals(len(method()), 0, 324 329 'There should be no root elements for navigation.') 325 330 326 331 # now add some testing content 327 332 self.setupContent(self.portal) 328 333 self.assertEquals(len(method()), 2, 329 334 'There should be 2 elements in portal root for navigation.') 330 335 331 336 # now switch off autogeneration 332 337 sp = getToolByName(self.portal, 'portal_properties').site_properties … … 335 340 'There should be no root elements for navigation when ' 336 341 'tabs autogeneration is switched off.') 337 342 338 343 def test_getCategories(self): 339 344 method = self.panel.getCategories … … 342 347 self.assertEquals(len(method()), 0, 343 348 'There should be no categories in portal_actions tool.') 344 349 345 350 # now setup actions 346 351 self.setupActions(self.tool) 347 352 self.assertEquals(method(), ['portal_tabs', 'new_category'], 348 353 'There should be exactly 2 categories in portal_actions tool.') 349 354 350 355 def test_portal_tabs(self): 351 356 method = self.panel.portal_tabs … … 354 359 self.assertEquals(len(method()), 0, 355 360 'There should be no portal tabs.') 356 361 357 362 # cleanup memoize cache 358 363 # cause actions method of portal context state is caching it's 359 364 # results in request and we have the same request for every call 360 365 self.purgeCache(self.portal.REQUEST) 361 366 362 367 # add actions 363 368 self.setupActions(self.tool) 364 369 self.assertEquals(len(method()), 2, 365 370 'There should be 2 portal tabs.') 366 371 367 372 # add content 368 373 self.setupContent(self.portal) 369 374 self.assertEquals(len(method()), 4, 370 375 'There should be 4 portal tabs.') 371 376 372 377 def test_selected_portal_tab(self): 373 378 self.assertEquals(self.panel.selected_portal_tab(), 'index_html', … … 381 386 class TestControlPanelManageMethods(PloneTabsTestCase): 382 387 """Test here management methods of control panel class""" 383 388 384 389 def afterSetUp(self): 385 390 super(TestControlPanelManageMethods, self).afterSetUp() … … 390 395 self.panel = panel.__of__(self.portal) 391 396 self.tool = getToolByName(self.portal, 'portal_actions') 392 397 393 398 # purge standard set of actions and set our own testing ones 394 399 self.purgeActions() 395 400 self.setupActions(self.tool) 396 401 397 402 def test_manage_setAutogeneration(self): 398 403 self.setupContent(self.portal) … … 405 410 self.failIf(sp.disable_folder_sections) 406 411 self.failUnless(sp.disable_nonfolderish_sections) 407 412 408 413 def test_manage_addAction(self): 409 414 self.purgeActions() … … 418 423 self.failIf(postback, 419 424 'There should be redirect after successfull adding.') 420 425 421 426 def test_manage_editAction(self): 422 427 method = self.panel.manage_editAction … … 432 437 import transaction 433 438 transaction.savepoint() 434 439 435 440 postback = method(form, {}) 436 441 self.failUnless('id_new' in self.tool.portal_tabs.objectIds()) 437 442 self.failIf(postback, 438 443 'There should be redirect after successfull edition.') 439 444 440 445 form['category'] = 'non_existent' 441 446 self.failUnlessRaises(KeyError, method, form, {}) 442 447 443 448 def test_manage_deleteAction(self): 444 449 self.purgeActions() … … 453 458 self.panel.manage_deleteAction(form, {}) 454 459 self.failIf('home' in self.tool.portal_tabs.objectIds()) 455 460 456 461 def test_manage_moveUpAction(self): 457 462 self.purgeActions() … … 467 472 self.assertEquals( 468 473 self.tool.portal_tabs.getObjectPosition('quintagroup'), 0) 469 474 470 475 def test_manage_moveDownAction(self): 471 476 self.purgeActions() … … 487 492 suite.addTest(unittest.makeSuite(TestControlPanelAPIMethods)) 488 493 suite.addTest(unittest.makeSuite(TestControlPanelManageMethods)) 489 494 490 495 # these tests are implemented as Selenium KSS Tests 491 496 # using kss.demo package, and KSS plugins are tested by means of
Note: See TracChangeset
for help on using the changeset viewer.