Changeset 3437 in products for quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/test_controlpanel.py
- Timestamp:
- Apr 20, 2012 10:04:56 AM (12 years ago)
- Location:
- quintagroup.plonetabs/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.plonetabs/trunk
- Property svn:mergeinfo
-
old new 1 1 /quintagroup.plonetabs/branches/plone4:3076-3243 2 /quintagroup.plonetabs/branches/tests:3394-3436
-
- Property svn:mergeinfo
-
quintagroup.plonetabs/trunk/quintagroup/plonetabs/tests/test_controlpanel.py
r917 r3437 6 6 7 7 from Products.CMFCore.utils import getToolByName 8 from Products.CMFCore.ActionInformation import Action , ActionCategory8 from Products.CMFCore.ActionInformation import Action 9 9 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 75 from Products.CMFCore.Expression import getEngine 76 from Products.CMFCore.Expression import Expression 77 73 78 def __init__(self, text): 74 79 self.text = text 75 80 if text.strip(): 76 81 self._v_compiled = getEngine().compile(text) 77 from Products.CMFCore.Expression import Expression 82 78 83 optimized__init__ = Expression.__init__ 79 84 Expression.__init__ = __init__ … … 81 86 # rollback our patch 82 87 Expression.__init__ = optimized__init__ 83 88 84 89 self.assertEquals(len(errors.keys()), 4, 85 90 'validateActionFields method is not working properly.') 86 91 #### pyflakes.scripts.pyflakes ends. 92 87 93 def test_processErrors(self): 88 94 method = self.panel.processErrors 89 errors = {'error': 'error message'}95 errors = {'error': 'error message'} 90 96 self.assertEquals(method(errors), errors, 91 97 'processErrors method is not working properly.') … … 93 99 {'pre_error_post': 'error message'}, 94 100 'processErrors method is not working properly.') 95 101 96 102 def test_parseEditForm(self): 97 103 method = self.panel.parseEditForm … … 110 116 'visible': True}), 111 117 'parseEditForm method is not working properly.') 112 118 113 119 del form['orig_id'] 114 120 self.failUnlessRaises(KeyError, method, form) 115 121 116 122 def test_parseAddForm(self): 117 123 method = self.panel.parseAddForm … … 129 135 'available_expr': 'expr2'}), 130 136 'parseAddForm method is not working properly.') 131 137 132 138 del form['id'] 133 139 self.failUnlessRaises(KeyError, method, form) 134 140 135 141 def test_getActionCategory(self): 136 142 method = self.panel.getActionCategory 137 143 self.purgeActions() 138 144 self.failUnlessRaises(KeyError, method, 'portal_tabs') 139 145 140 146 self.setupActions(self.tool) 141 147 self.assertEquals(method('portal_tabs').id, 'portal_tabs', 142 148 'getActionCategory is not working properly.') 143 149 144 150 def test_getOrCreateCategory(self): 145 151 method = self.panel.getOrCreateCategory … … 147 153 self.assertEquals(method('portal_tabs').id, 'portal_tabs', 148 154 'getOrCreateCategory is not working properly.') 149 155 150 156 def test_setSiteProperties(self): 151 157 self.panel.setSiteProperties(title='Test Title') … … 153 159 self.assertEquals(sp.getProperty('title'), 'Test Title', 154 160 'setSiteProperties method is not working properly.') 155 161 156 162 def test_renderViewlet(self): 157 163 # register test viewlet and it's manager … … 161 167 from zope.publisher.interfaces.browser import IDefaultBrowserLayer 162 168 from zope.publisher.interfaces.browser import IBrowserView 169 163 170 class TestViewlet(ViewletBase): 164 171 def __of__(self, obj): 165 172 return self 173 166 174 def render(self): 167 175 return 'test viewlet' 176 168 177 provideAdapter( 169 178 TestViewlet, … … 176 185 IViewletManager, 177 186 name=u'test_manager') 178 187 179 188 self.assertEquals( 180 189 self.panel.renderViewlet('test_manager', 'test_viewlet'), 181 190 'test viewlet', 182 191 'renderViewlet method is not workig properly') 183 192 184 193 def test_addAction(self): 185 194 self.purgeActions() 186 self.panel.addAction('new_category', {'id': 'id1', 'title':'Test'})195 self.panel.addAction('new_category', {'id': 'id1', 'title': 'Test'}) 187 196 self.failUnless('id1' in self.tool.new_category.objectIds(), 188 197 'addAction method is not workig properly') 189 198 190 199 def test_updateAction(self): 191 200 method = self.panel.updateAction 192 193 self.purgeActions() 194 self.failUnlessRaises(KeyError, method, 'id1', 'cat1', {'id': 'new'})195 201 202 self.purgeActions() 203 self.failUnlessRaises(KeyError, method, 'id1', 'cat1', {'id': 'new'}) 204 196 205 self.setupActions(self.tool) 197 206 # we need to commit transaction because … … 199 208 import transaction 200 209 transaction.savepoint() 201 method('home', 'portal_tabs', {'id': 'new_home'})210 method('home', 'portal_tabs', {'id': 'new_home'}) 202 211 self.failUnless('new_home' in self.tool.portal_tabs.objectIds(), 203 212 'updateAction method is not workig properly') 204 213 205 214 def test_deleteAction(self): 206 215 self.purgeActions() … … 209 218 self.failIf('home' in self.tool.portal_tabs.objectIds(), 210 219 'deleteAction method is not workig properly') 211 220 212 221 def test_moveAction(self): 213 222 self.purgeActions() … … 223 232 class TestControlPanelAPIMethods(PloneTabsTestCase): 224 233 """Test here interface methods of control panel class""" 225 234 226 235 def afterSetUp(self): 227 236 super(TestControlPanelAPIMethods, self).afterSetUp() … … 232 241 self.panel = panel.__of__(self.portal) 233 242 self.tool = getToolByName(self.portal, 'portal_actions') 234 243 235 244 def test_interface(self): 236 245 self.failUnless(IPloneTabsControlPanel.implementedBy(ptp), … … 238 247 self.failUnless(verifyClass(IPloneTabsControlPanel, ptp), 239 248 'PloneTabs control panel does not implement required interface.') 240 249 241 250 def test_getPageTitle(self): 242 251 self.assertEquals(self.panel.getPageTitle(), … … 247 256 mapping={'cat_name': 'notexists'}), 248 257 'getPageTitle method is broken') 249 258 250 259 def test_hasActions(self): 251 260 method = self.panel.hasActions … … 254 263 self.failIf(method(), 255 264 'There should be no portal_tab actions in portal') 256 265 257 266 # setup our own actions 258 267 self.setupActions(self.tool) 259 268 self.failUnless(method(), 260 269 'There should be portal_tab actions in portal') 261 270 262 271 def test_getPortalActions(self): 263 272 method = self.panel.getPortalActions … … 266 275 self.assertEquals(len(method()), 0, 267 276 'There should be no actions in portal_tabs category.') 268 277 269 278 # setup our own actions 270 279 self.setupActions(self.tool) 271 280 self.assertEquals(len(method()), 2, 272 281 'There should be 2 actions in portal_tabs category.') 273 282 274 283 # marginal arguments 275 284 self.assertEquals(len(method('notexistent_category')), 0, 276 285 'There should be no actions for not existed category.') 277 286 278 287 def test_isGeneratedTabs(self): 279 288 method = self.panel.isGeneratedTabs … … 282 291 sp.manage_changeProperties(disable_folder_sections=True) 283 292 self.failIf(method(), 'But folder sections are disabled...') 284 293 285 294 def test_isNotFoldersGenerated(self): 286 295 method = self.panel.isNotFoldersGenerated … … 289 298 sp.manage_changeProperties(disable_nonfolderish_sections=True) 290 299 self.failIf(method(), 'But non folderish sections are disabled...') 291 300 292 301 def test_getActionsList(self): 293 302 method = self.panel.getActionsList … … 299 308 self.failUnless('class="editform"' in method(), 300 309 'There are no actions in actions list template.') 301 310 302 311 def test_getAutoGenereatedSection(self): 303 312 method = self.panel.getAutoGenereatedSection … … 308 317 'There should be form in autogenerated tabs template ' 309 318 'for portal_tabs category.') 310 319 311 320 def test_getGeneratedTabs(self): 312 321 self.panel.getGeneratedTabs() … … 316 325 'Mon, 26 Jul 1996 05:00:00 GMT', 317 326 'Expiration header is not set properly.') 318 327 319 328 def test_getRootTabs(self): 320 329 method = self.panel.getRootTabs … … 323 332 self.assertEquals(len(method()), 0, 324 333 'There should be no root elements for navigation.') 325 334 326 335 # now add some testing content 327 336 self.setupContent(self.portal) 328 337 self.assertEquals(len(method()), 2, 329 338 'There should be 2 elements in portal root for navigation.') 330 339 331 340 # now switch off autogeneration 332 341 sp = getToolByName(self.portal, 'portal_properties').site_properties … … 335 344 'There should be no root elements for navigation when ' 336 345 'tabs autogeneration is switched off.') 337 346 338 347 def test_getCategories(self): 339 348 method = self.panel.getCategories … … 342 351 self.assertEquals(len(method()), 0, 343 352 'There should be no categories in portal_actions tool.') 344 353 345 354 # now setup actions 346 355 self.setupActions(self.tool) 347 356 self.assertEquals(method(), ['portal_tabs', 'new_category'], 348 357 'There should be exactly 2 categories in portal_actions tool.') 349 358 350 359 def test_portal_tabs(self): 351 360 method = self.panel.portal_tabs … … 354 363 self.assertEquals(len(method()), 0, 355 364 'There should be no portal tabs.') 356 365 357 366 # cleanup memoize cache 358 367 # cause actions method of portal context state is caching it's 359 368 # results in request and we have the same request for every call 360 369 self.purgeCache(self.portal.REQUEST) 361 370 362 371 # add actions 363 372 self.setupActions(self.tool) 364 373 self.assertEquals(len(method()), 2, 365 374 'There should be 2 portal tabs.') 366 375 367 376 # add content 368 377 self.setupContent(self.portal) 369 378 self.assertEquals(len(method()), 4, 370 379 'There should be 4 portal tabs.') 371 380 372 381 def test_selected_portal_tab(self): 373 382 self.assertEquals(self.panel.selected_portal_tab(), 'index_html', … … 381 390 class TestControlPanelManageMethods(PloneTabsTestCase): 382 391 """Test here management methods of control panel class""" 383 392 384 393 def afterSetUp(self): 385 394 super(TestControlPanelManageMethods, self).afterSetUp() … … 390 399 self.panel = panel.__of__(self.portal) 391 400 self.tool = getToolByName(self.portal, 'portal_actions') 392 401 393 402 # purge standard set of actions and set our own testing ones 394 403 self.purgeActions() 395 404 self.setupActions(self.tool) 396 405 397 406 def test_manage_setAutogeneration(self): 398 407 self.setupContent(self.portal) … … 405 414 self.failIf(sp.disable_folder_sections) 406 415 self.failUnless(sp.disable_nonfolderish_sections) 407 416 408 417 def test_manage_addAction(self): 409 418 self.purgeActions() … … 418 427 self.failIf(postback, 419 428 'There should be redirect after successfull adding.') 420 429 421 430 def test_manage_editAction(self): 422 431 method = self.panel.manage_editAction … … 432 441 import transaction 433 442 transaction.savepoint() 434 443 435 444 postback = method(form, {}) 436 445 self.failUnless('id_new' in self.tool.portal_tabs.objectIds()) 437 446 self.failIf(postback, 438 447 'There should be redirect after successfull edition.') 439 448 440 449 form['category'] = 'non_existent' 441 450 self.failUnlessRaises(KeyError, method, form, {}) 442 451 443 452 def test_manage_deleteAction(self): 444 453 self.purgeActions() … … 453 462 self.panel.manage_deleteAction(form, {}) 454 463 self.failIf('home' in self.tool.portal_tabs.objectIds()) 455 464 456 465 def test_manage_moveUpAction(self): 457 466 self.purgeActions() … … 467 476 self.assertEquals( 468 477 self.tool.portal_tabs.getObjectPosition('quintagroup'), 0) 469 478 470 479 def test_manage_moveDownAction(self): 471 480 self.purgeActions() … … 487 496 suite.addTest(unittest.makeSuite(TestControlPanelAPIMethods)) 488 497 suite.addTest(unittest.makeSuite(TestControlPanelManageMethods)) 489 498 490 499 # these tests are implemented as Selenium KSS Tests 491 500 # using kss.demo package, and KSS plugins are tested by means of
Note: See TracChangeset
for help on using the changeset viewer.