[775] | 1 | import unittest |
---|
| 2 | |
---|
[799] | 3 | from zope.interface import Interface |
---|
[775] | 4 | from zope.interface.verify import verifyClass |
---|
[799] | 5 | from zope.component import getMultiAdapter, provideAdapter |
---|
[775] | 6 | |
---|
| 7 | from Products.CMFCore.utils import getToolByName |
---|
[3403] | 8 | from Products.CMFCore.ActionInformation import Action |
---|
[775] | 9 | |
---|
[874] | 10 | from quintagroup.plonetabs import messageFactory as _ |
---|
[775] | 11 | from quintagroup.plonetabs.browser.interfaces import IPloneTabsControlPanel |
---|
[3402] | 12 | from quintagroup.plonetabs.browser.plonetabs \ |
---|
| 13 | import PloneTabsControlPanel as ptp |
---|
[775] | 14 | from quintagroup.plonetabs.tests.base import PloneTabsTestCase |
---|
[798] | 15 | from quintagroup.plonetabs.tests.data import PORTAL_ACTIONS |
---|
[775] | 16 | |
---|
[3402] | 17 | |
---|
[798] | 18 | class TestControlPanelHelperMethods(PloneTabsTestCase): |
---|
| 19 | """Test here configlet helper methods""" |
---|
[775] | 20 | def afterSetUp(self): |
---|
[865] | 21 | super(TestControlPanelHelperMethods, self).afterSetUp() |
---|
[775] | 22 | self.loginAsPortalOwner() |
---|
[865] | 23 | panel = getMultiAdapter((self.portal, self.portal.REQUEST), |
---|
| 24 | name='plonetabs-controlpanel') |
---|
| 25 | # we need this to apply zope2 security (got from zope2 traverse method) |
---|
| 26 | self.panel = panel.__of__(self.portal) |
---|
[775] | 27 | self.tool = getToolByName(self.portal, 'portal_actions') |
---|
[3402] | 28 | |
---|
[798] | 29 | def test_redirect(self): |
---|
| 30 | response = self.portal.REQUEST.RESPONSE |
---|
| 31 | method = self.panel.redirect |
---|
[3402] | 32 | portal_url = getMultiAdapter((self.portal, self.portal.REQUEST), |
---|
[798] | 33 | name=u"plone_portal_state").portal_url() |
---|
[865] | 34 | url = '%s/@@plonetabs-controlpanel' % portal_url |
---|
[798] | 35 | method() |
---|
| 36 | self.assertEquals(response.headers.get('location', ''), url, |
---|
| 37 | 'Redirect method is not working properly.') |
---|
[3402] | 38 | |
---|
[798] | 39 | # check query string and anchor hash |
---|
| 40 | method('http://quintagroup.com', 'q=test', 'hash_code') |
---|
| 41 | self.assertEquals(response.headers.get('location', ''), |
---|
| 42 | 'http://quintagroup.com?q=test#hash_code', |
---|
| 43 | 'Redirect method is not working properly.') |
---|
[3402] | 44 | |
---|
[798] | 45 | def test_fixExpression(self): |
---|
| 46 | method = self.panel.fixExpression |
---|
| 47 | self.assertEquals(method('/slash'), 'string:${portal_url}/slash') |
---|
[3402] | 48 | self.assertEquals(method('https://test.com'), |
---|
| 49 | 'string:https://test.com') |
---|
[798] | 50 | self.assertEquals(method('python:True'), 'python:True') |
---|
| 51 | self.assertEquals(method('hello'), 'string:${object_url}/hello') |
---|
[3402] | 52 | |
---|
[798] | 53 | def test_copyAction(self): |
---|
| 54 | data = PORTAL_ACTIONS[0][1]['children'][0][1] |
---|
| 55 | action = Action('act1', **data) |
---|
| 56 | info = self.panel.copyAction(action) |
---|
| 57 | self.assertEquals(len(info.keys()), 6) |
---|
| 58 | self.assertEquals(info['description'], 'The most important place') |
---|
[3402] | 59 | |
---|
[798] | 60 | def test_validateActionFields(self): |
---|
| 61 | method = self.panel.validateActionFields |
---|
| 62 | good_data = PORTAL_ACTIONS[0][1]['children'][0][1].copy() |
---|
| 63 | good_data['id'] = 'new_one' |
---|
| 64 | errors = method('new_category', good_data) |
---|
| 65 | self.assertEquals(errors, {}, |
---|
| 66 | 'There should be no errors for valid data.') |
---|
[3402] | 67 | |
---|
| 68 | bad_data = {'id': '', |
---|
[798] | 69 | 'title': ' ', |
---|
| 70 | 'available_expr': 'bad_type:test', |
---|
| 71 | 'url_expr': 'bad_type:test'} |
---|
[3402] | 72 | |
---|
[801] | 73 | # Revert PloneTestCase's optimization |
---|
| 74 | # because this breaks our test |
---|
[3403] | 75 | #### pyflakes.scripts.pyflakes, modified: |
---|
| 76 | ## - return array of warnings instead of printing them |
---|
| 77 | ## - honour pyflakes:ignore comments |
---|
[801] | 78 | def __init__(self, text): |
---|
| 79 | self.text = text |
---|
| 80 | if text.strip(): |
---|
| 81 | self._v_compiled = getEngine().compile(text) |
---|
| 82 | from Products.CMFCore.Expression import Expression |
---|
[3403] | 83 | |
---|
[801] | 84 | optimized__init__ = Expression.__init__ |
---|
| 85 | Expression.__init__ = __init__ |
---|
[798] | 86 | errors = method('new_category', bad_data) |
---|
[801] | 87 | # rollback our patch |
---|
| 88 | Expression.__init__ = optimized__init__ |
---|
[3402] | 89 | |
---|
[798] | 90 | self.assertEquals(len(errors.keys()), 4, |
---|
[801] | 91 | 'validateActionFields method is not working properly.') |
---|
[3403] | 92 | #### pyflakes.scripts.pyflakes ends. |
---|
[3402] | 93 | |
---|
[798] | 94 | def test_processErrors(self): |
---|
[799] | 95 | method = self.panel.processErrors |
---|
[3402] | 96 | errors = {'error': 'error message'} |
---|
[799] | 97 | self.assertEquals(method(errors), errors, |
---|
| 98 | 'processErrors method is not working properly.') |
---|
| 99 | self.assertEquals(method(errors, 'pre_', '_post'), |
---|
| 100 | {'pre_error_post': 'error message'}, |
---|
| 101 | 'processErrors method is not working properly.') |
---|
[3402] | 102 | |
---|
[798] | 103 | def test_parseEditForm(self): |
---|
[799] | 104 | method = self.panel.parseEditForm |
---|
| 105 | form = {'orig_id': 'id1', |
---|
| 106 | 'category': 'cat1', |
---|
| 107 | 'visible_id1': True, |
---|
| 108 | 'id_id1': 'id_new', |
---|
| 109 | 'title_id1': 'title1', |
---|
| 110 | 'url_expr_id1': 'expr1', |
---|
| 111 | 'available_expr_id1': 'expr2'} |
---|
| 112 | self.assertEquals(method(form), |
---|
| 113 | ('id1', 'cat1', {'id': 'id_new', |
---|
| 114 | 'title': 'title1', |
---|
| 115 | 'url_expr': 'expr1', |
---|
| 116 | 'available_expr': 'expr2', |
---|
| 117 | 'visible': True}), |
---|
| 118 | 'parseEditForm method is not working properly.') |
---|
[3402] | 119 | |
---|
[799] | 120 | del form['orig_id'] |
---|
| 121 | self.failUnlessRaises(KeyError, method, form) |
---|
[3402] | 122 | |
---|
[798] | 123 | def test_parseAddForm(self): |
---|
[799] | 124 | method = self.panel.parseAddForm |
---|
| 125 | form = {'id': 'id1', |
---|
| 126 | 'category': 'cat1', |
---|
| 127 | 'visible': True, |
---|
| 128 | 'title': 'title1', |
---|
| 129 | 'url_expr': 'string:expr1', |
---|
| 130 | 'available_expr': 'expr2'} |
---|
| 131 | self.assertEquals(method(form), |
---|
| 132 | ('id1', 'cat1', {'id': 'id1', |
---|
| 133 | 'visible': True, |
---|
| 134 | 'title': 'title1', |
---|
| 135 | 'url_expr': 'string:expr1', |
---|
| 136 | 'available_expr': 'expr2'}), |
---|
| 137 | 'parseAddForm method is not working properly.') |
---|
[3402] | 138 | |
---|
[799] | 139 | del form['id'] |
---|
| 140 | self.failUnlessRaises(KeyError, method, form) |
---|
[3402] | 141 | |
---|
[798] | 142 | def test_getActionCategory(self): |
---|
[799] | 143 | method = self.panel.getActionCategory |
---|
| 144 | self.purgeActions() |
---|
| 145 | self.failUnlessRaises(KeyError, method, 'portal_tabs') |
---|
[3402] | 146 | |
---|
[799] | 147 | self.setupActions(self.tool) |
---|
| 148 | self.assertEquals(method('portal_tabs').id, 'portal_tabs', |
---|
| 149 | 'getActionCategory is not working properly.') |
---|
[3402] | 150 | |
---|
[798] | 151 | def test_getOrCreateCategory(self): |
---|
[799] | 152 | method = self.panel.getOrCreateCategory |
---|
| 153 | self.purgeActions() |
---|
| 154 | self.assertEquals(method('portal_tabs').id, 'portal_tabs', |
---|
| 155 | 'getOrCreateCategory is not working properly.') |
---|
[3402] | 156 | |
---|
[798] | 157 | def test_setSiteProperties(self): |
---|
[799] | 158 | self.panel.setSiteProperties(title='Test Title') |
---|
| 159 | sp = getToolByName(self.portal, 'portal_properties').site_properties |
---|
| 160 | self.assertEquals(sp.getProperty('title'), 'Test Title', |
---|
| 161 | 'setSiteProperties method is not working properly.') |
---|
[3402] | 162 | |
---|
[798] | 163 | def test_renderViewlet(self): |
---|
[799] | 164 | # register test viewlet and it's manager |
---|
| 165 | from zope.viewlet.interfaces import IViewlet, IViewletManager |
---|
| 166 | from zope.viewlet.viewlet import ViewletBase |
---|
| 167 | from zope.viewlet.manager import ViewletManagerBase |
---|
| 168 | from zope.publisher.interfaces.browser import IDefaultBrowserLayer |
---|
| 169 | from zope.publisher.interfaces.browser import IBrowserView |
---|
[3402] | 170 | |
---|
[799] | 171 | class TestViewlet(ViewletBase): |
---|
| 172 | def __of__(self, obj): |
---|
| 173 | return self |
---|
[3402] | 174 | |
---|
[799] | 175 | def render(self): |
---|
| 176 | return 'test viewlet' |
---|
[3402] | 177 | |
---|
[799] | 178 | provideAdapter( |
---|
| 179 | TestViewlet, |
---|
| 180 | (Interface, IDefaultBrowserLayer, IBrowserView, IViewletManager), |
---|
| 181 | IViewlet, |
---|
| 182 | name=u'test_viewlet') |
---|
| 183 | provideAdapter( |
---|
| 184 | ViewletManagerBase, |
---|
| 185 | (Interface, IDefaultBrowserLayer, IBrowserView), |
---|
| 186 | IViewletManager, |
---|
| 187 | name=u'test_manager') |
---|
[3402] | 188 | |
---|
[799] | 189 | self.assertEquals( |
---|
| 190 | self.panel.renderViewlet('test_manager', 'test_viewlet'), |
---|
| 191 | 'test viewlet', |
---|
| 192 | 'renderViewlet method is not workig properly') |
---|
[3402] | 193 | |
---|
[798] | 194 | def test_addAction(self): |
---|
[799] | 195 | self.purgeActions() |
---|
[3402] | 196 | self.panel.addAction('new_category', {'id': 'id1', 'title': 'Test'}) |
---|
[799] | 197 | self.failUnless('id1' in self.tool.new_category.objectIds(), |
---|
| 198 | 'addAction method is not workig properly') |
---|
[3402] | 199 | |
---|
[798] | 200 | def test_updateAction(self): |
---|
[799] | 201 | method = self.panel.updateAction |
---|
[3402] | 202 | |
---|
[799] | 203 | self.purgeActions() |
---|
[3402] | 204 | self.failUnlessRaises(KeyError, method, 'id1', 'cat1', {'id': 'new'}) |
---|
| 205 | |
---|
[799] | 206 | self.setupActions(self.tool) |
---|
| 207 | # we need to commit transaction because |
---|
| 208 | # we are going to rename just added action now |
---|
| 209 | import transaction |
---|
| 210 | transaction.savepoint() |
---|
[3402] | 211 | method('home', 'portal_tabs', {'id': 'new_home'}) |
---|
[799] | 212 | self.failUnless('new_home' in self.tool.portal_tabs.objectIds(), |
---|
| 213 | 'updateAction method is not workig properly') |
---|
[3402] | 214 | |
---|
[798] | 215 | def test_deleteAction(self): |
---|
[799] | 216 | self.purgeActions() |
---|
| 217 | self.setupActions(self.tool) |
---|
| 218 | self.panel.deleteAction('home', 'portal_tabs') |
---|
| 219 | self.failIf('home' in self.tool.portal_tabs.objectIds(), |
---|
| 220 | 'deleteAction method is not workig properly') |
---|
[3402] | 221 | |
---|
[798] | 222 | def test_moveAction(self): |
---|
[799] | 223 | self.purgeActions() |
---|
| 224 | self.setupActions(self.tool) |
---|
| 225 | pos = self.tool.portal_tabs.getObjectPosition |
---|
| 226 | self.assertEquals(pos('home'), 0, |
---|
| 227 | 'moveAction method is not workig properly') |
---|
| 228 | self.panel.moveAction('home', 'portal_tabs', -1) |
---|
| 229 | self.assertEquals(pos('home'), 1, |
---|
| 230 | 'moveAction method is not workig properly') |
---|
[798] | 231 | |
---|
| 232 | |
---|
[917] | 233 | class TestControlPanelAPIMethods(PloneTabsTestCase): |
---|
[798] | 234 | """Test here interface methods of control panel class""" |
---|
[3402] | 235 | |
---|
[798] | 236 | def afterSetUp(self): |
---|
[917] | 237 | super(TestControlPanelAPIMethods, self).afterSetUp() |
---|
[798] | 238 | self.loginAsPortalOwner() |
---|
[865] | 239 | panel = getMultiAdapter((self.portal, self.portal.REQUEST), |
---|
| 240 | name='plonetabs-controlpanel') |
---|
| 241 | # we need this to apply zope2 security (got from zope2 traverse method) |
---|
| 242 | self.panel = panel.__of__(self.portal) |
---|
[798] | 243 | self.tool = getToolByName(self.portal, 'portal_actions') |
---|
[3402] | 244 | |
---|
[775] | 245 | def test_interface(self): |
---|
| 246 | self.failUnless(IPloneTabsControlPanel.implementedBy(ptp), |
---|
| 247 | 'PloneTabs control panel does not implement required interface.') |
---|
| 248 | self.failUnless(verifyClass(IPloneTabsControlPanel, ptp), |
---|
| 249 | 'PloneTabs control panel does not implement required interface.') |
---|
[3402] | 250 | |
---|
[775] | 251 | def test_getPageTitle(self): |
---|
| 252 | self.assertEquals(self.panel.getPageTitle(), |
---|
[874] | 253 | _(u"Portal Tabs Configuration"), |
---|
[775] | 254 | 'getPageTitle method is broken') |
---|
| 255 | self.assertEquals(self.panel.getPageTitle(category='notexists'), |
---|
[874] | 256 | _(u"Plone '${cat_name}' Configuration", |
---|
| 257 | mapping={'cat_name': 'notexists'}), |
---|
[775] | 258 | 'getPageTitle method is broken') |
---|
[3402] | 259 | |
---|
[775] | 260 | def test_hasActions(self): |
---|
| 261 | method = self.panel.hasActions |
---|
| 262 | # purge any default portal actions |
---|
| 263 | self.purgeActions() |
---|
| 264 | self.failIf(method(), |
---|
| 265 | 'There should be no portal_tab actions in portal') |
---|
[3402] | 266 | |
---|
[775] | 267 | # setup our own actions |
---|
| 268 | self.setupActions(self.tool) |
---|
| 269 | self.failUnless(method(), |
---|
| 270 | 'There should be portal_tab actions in portal') |
---|
[3402] | 271 | |
---|
[775] | 272 | def test_getPortalActions(self): |
---|
| 273 | method = self.panel.getPortalActions |
---|
| 274 | # purge any default portal actions |
---|
| 275 | self.purgeActions() |
---|
| 276 | self.assertEquals(len(method()), 0, |
---|
| 277 | 'There should be no actions in portal_tabs category.') |
---|
[3402] | 278 | |
---|
[775] | 279 | # setup our own actions |
---|
| 280 | self.setupActions(self.tool) |
---|
| 281 | self.assertEquals(len(method()), 2, |
---|
| 282 | 'There should be 2 actions in portal_tabs category.') |
---|
[3402] | 283 | |
---|
[775] | 284 | # marginal arguments |
---|
| 285 | self.assertEquals(len(method('notexistent_category')), 0, |
---|
| 286 | 'There should be no actions for not existed category.') |
---|
[3402] | 287 | |
---|
[775] | 288 | def test_isGeneratedTabs(self): |
---|
| 289 | method = self.panel.isGeneratedTabs |
---|
| 290 | # prepare value |
---|
| 291 | sp = getToolByName(self.portal, 'portal_properties').site_properties |
---|
| 292 | sp.manage_changeProperties(disable_folder_sections=True) |
---|
| 293 | self.failIf(method(), 'But folder sections are disabled...') |
---|
[3402] | 294 | |
---|
[775] | 295 | def test_isNotFoldersGenerated(self): |
---|
| 296 | method = self.panel.isNotFoldersGenerated |
---|
| 297 | # prepare value |
---|
| 298 | sp = getToolByName(self.portal, 'portal_properties').site_properties |
---|
| 299 | sp.manage_changeProperties(disable_nonfolderish_sections=True) |
---|
| 300 | self.failIf(method(), 'But non folderish sections are disabled...') |
---|
[3402] | 301 | |
---|
[775] | 302 | def test_getActionsList(self): |
---|
| 303 | method = self.panel.getActionsList |
---|
| 304 | # purge any default portal actions |
---|
| 305 | self.purgeActions() |
---|
| 306 | self.failIf('class="editform"' in method(), |
---|
| 307 | 'There should no be actions in actions list template.') |
---|
| 308 | self.setupActions(self.tool) |
---|
| 309 | self.failUnless('class="editform"' in method(), |
---|
| 310 | 'There are no actions in actions list template.') |
---|
[3402] | 311 | |
---|
[775] | 312 | def test_getAutoGenereatedSection(self): |
---|
| 313 | method = self.panel.getAutoGenereatedSection |
---|
| 314 | self.failIf('<form' in method('user'), |
---|
| 315 | 'There should be no form in autogenerated tabs template ' |
---|
| 316 | 'for category other than portal_tabs.') |
---|
| 317 | self.failUnless('<form' in method('portal_tabs'), |
---|
| 318 | 'There should be form in autogenerated tabs template ' |
---|
| 319 | 'for portal_tabs category.') |
---|
[3402] | 320 | |
---|
[775] | 321 | def test_getGeneratedTabs(self): |
---|
| 322 | self.panel.getGeneratedTabs() |
---|
| 323 | # check expiration header set by generated tabs template |
---|
| 324 | self.assertEquals( |
---|
| 325 | self.portal.REQUEST.RESPONSE.headers.get('expires', ''), |
---|
| 326 | 'Mon, 26 Jul 1996 05:00:00 GMT', |
---|
| 327 | 'Expiration header is not set properly.') |
---|
[3402] | 328 | |
---|
[775] | 329 | def test_getRootTabs(self): |
---|
| 330 | method = self.panel.getRootTabs |
---|
| 331 | # make sure we don't depend on external settings |
---|
| 332 | self.purgeContent() |
---|
| 333 | self.assertEquals(len(method()), 0, |
---|
| 334 | 'There should be no root elements for navigation.') |
---|
[3402] | 335 | |
---|
[775] | 336 | # now add some testing content |
---|
| 337 | self.setupContent(self.portal) |
---|
| 338 | self.assertEquals(len(method()), 2, |
---|
| 339 | 'There should be 2 elements in portal root for navigation.') |
---|
[3402] | 340 | |
---|
[775] | 341 | # now switch off autogeneration |
---|
| 342 | sp = getToolByName(self.portal, 'portal_properties').site_properties |
---|
| 343 | sp.manage_changeProperties(disable_folder_sections=True) |
---|
| 344 | self.assertEquals(len(method()), 0, |
---|
| 345 | 'There should be no root elements for navigation when ' |
---|
| 346 | 'tabs autogeneration is switched off.') |
---|
[3402] | 347 | |
---|
[775] | 348 | def test_getCategories(self): |
---|
| 349 | method = self.panel.getCategories |
---|
| 350 | # purge any default portal actions |
---|
| 351 | self.purgeActions() |
---|
| 352 | self.assertEquals(len(method()), 0, |
---|
| 353 | 'There should be no categories in portal_actions tool.') |
---|
[3402] | 354 | |
---|
[775] | 355 | # now setup actions |
---|
| 356 | self.setupActions(self.tool) |
---|
| 357 | self.assertEquals(method(), ['portal_tabs', 'new_category'], |
---|
| 358 | 'There should be exactly 2 categories in portal_actions tool.') |
---|
[3402] | 359 | |
---|
[775] | 360 | def test_portal_tabs(self): |
---|
| 361 | method = self.panel.portal_tabs |
---|
| 362 | self.purgeContent() |
---|
| 363 | self.purgeActions() |
---|
| 364 | self.assertEquals(len(method()), 0, |
---|
| 365 | 'There should be no portal tabs.') |
---|
[3402] | 366 | |
---|
[798] | 367 | # cleanup memoize cache |
---|
| 368 | # cause actions method of portal context state is caching it's |
---|
| 369 | # results in request and we have the same request for every call |
---|
| 370 | self.purgeCache(self.portal.REQUEST) |
---|
[3402] | 371 | |
---|
[775] | 372 | # add actions |
---|
| 373 | self.setupActions(self.tool) |
---|
| 374 | self.assertEquals(len(method()), 2, |
---|
| 375 | 'There should be 2 portal tabs.') |
---|
[3402] | 376 | |
---|
[775] | 377 | # add content |
---|
| 378 | self.setupContent(self.portal) |
---|
| 379 | self.assertEquals(len(method()), 4, |
---|
| 380 | 'There should be 4 portal tabs.') |
---|
[3402] | 381 | |
---|
[775] | 382 | def test_selected_portal_tab(self): |
---|
[798] | 383 | self.assertEquals(self.panel.selected_portal_tab(), 'index_html', |
---|
| 384 | 'index_html is not selected tab while being on configlet.') |
---|
[775] | 385 | |
---|
| 386 | def test_test(self): |
---|
[798] | 387 | self.assertEquals(self.panel.test(True, 'true', 'false'), 'true', |
---|
[801] | 388 | 'Test function does not work properly.') |
---|
[775] | 389 | |
---|
| 390 | |
---|
[801] | 391 | class TestControlPanelManageMethods(PloneTabsTestCase): |
---|
| 392 | """Test here management methods of control panel class""" |
---|
[3402] | 393 | |
---|
[801] | 394 | def afterSetUp(self): |
---|
[865] | 395 | super(TestControlPanelManageMethods, self).afterSetUp() |
---|
[801] | 396 | self.loginAsPortalOwner() |
---|
[865] | 397 | panel = getMultiAdapter((self.portal, self.portal.REQUEST), |
---|
| 398 | name='plonetabs-controlpanel') |
---|
| 399 | # we need this to apply zope2 security (got from zope2 traverse method) |
---|
| 400 | self.panel = panel.__of__(self.portal) |
---|
[801] | 401 | self.tool = getToolByName(self.portal, 'portal_actions') |
---|
[3402] | 402 | |
---|
[801] | 403 | # purge standard set of actions and set our own testing ones |
---|
| 404 | self.purgeActions() |
---|
| 405 | self.setupActions(self.tool) |
---|
[3402] | 406 | |
---|
[801] | 407 | def test_manage_setAutogeneration(self): |
---|
| 408 | self.setupContent(self.portal) |
---|
| 409 | form = {'generated_tabs': '1', |
---|
| 410 | 'nonfolderish_tabs': '0', |
---|
| 411 | 'folder1': '0'} |
---|
| 412 | self.panel.manage_setAutogeneration(form, {}) |
---|
| 413 | self.failUnless(self.portal.folder1.exclude_from_nav()) |
---|
| 414 | sp = getToolByName(self.portal, 'portal_properties').site_properties |
---|
| 415 | self.failIf(sp.disable_folder_sections) |
---|
| 416 | self.failUnless(sp.disable_nonfolderish_sections) |
---|
[3402] | 417 | |
---|
[801] | 418 | def test_manage_addAction(self): |
---|
| 419 | self.purgeActions() |
---|
| 420 | form = {'id': 'id1', |
---|
| 421 | 'category': 'cat1', |
---|
| 422 | 'visible': True, |
---|
| 423 | 'title': 'title1', |
---|
| 424 | 'url_expr': 'string:expr1', |
---|
| 425 | 'available_expr': 'expr2'} |
---|
| 426 | postback = self.panel.manage_addAction(form, {}) |
---|
| 427 | self.failUnless('id1' in self.tool.cat1.objectIds()) |
---|
| 428 | self.failIf(postback, |
---|
| 429 | 'There should be redirect after successfull adding.') |
---|
[3402] | 430 | |
---|
[801] | 431 | def test_manage_editAction(self): |
---|
| 432 | method = self.panel.manage_editAction |
---|
| 433 | self.purgeActions() |
---|
| 434 | self.setupActions(self.tool) |
---|
| 435 | form = {'orig_id': 'home', |
---|
| 436 | 'category': 'portal_tabs', |
---|
| 437 | 'visible_home': True, |
---|
| 438 | 'id_home': 'id_new', |
---|
| 439 | 'title_home': 'title1', |
---|
| 440 | 'url_expr_home': 'expr1', |
---|
| 441 | 'available_expr_home': 'expr2'} |
---|
| 442 | import transaction |
---|
| 443 | transaction.savepoint() |
---|
[3402] | 444 | |
---|
[801] | 445 | postback = method(form, {}) |
---|
| 446 | self.failUnless('id_new' in self.tool.portal_tabs.objectIds()) |
---|
| 447 | self.failIf(postback, |
---|
| 448 | 'There should be redirect after successfull edition.') |
---|
[3402] | 449 | |
---|
[801] | 450 | form['category'] = 'non_existent' |
---|
| 451 | self.failUnlessRaises(KeyError, method, form, {}) |
---|
[3402] | 452 | |
---|
[801] | 453 | def test_manage_deleteAction(self): |
---|
| 454 | self.purgeActions() |
---|
| 455 | self.setupActions(self.tool) |
---|
| 456 | form = {'orig_id': 'home', |
---|
| 457 | 'category': 'portal_tabs', |
---|
| 458 | 'visible_home': True, |
---|
| 459 | 'id_home': 'id_new', |
---|
| 460 | 'title_home': 'title1', |
---|
| 461 | 'url_expr_home': 'expr1', |
---|
| 462 | 'available_expr_home': 'expr2'} |
---|
| 463 | self.panel.manage_deleteAction(form, {}) |
---|
| 464 | self.failIf('home' in self.tool.portal_tabs.objectIds()) |
---|
[3402] | 465 | |
---|
[801] | 466 | def test_manage_moveUpAction(self): |
---|
| 467 | self.purgeActions() |
---|
| 468 | self.setupActions(self.tool) |
---|
| 469 | form = {'orig_id': 'quintagroup', |
---|
| 470 | 'category': 'portal_tabs', |
---|
| 471 | 'visible_quintagroup': True, |
---|
| 472 | 'id_quintagroup': 'quintagroup', |
---|
| 473 | 'title_quintagroup': 'title1', |
---|
| 474 | 'url_expr_quintagroup': 'expr1', |
---|
| 475 | 'available_expr_quintagroup': 'expr2'} |
---|
| 476 | self.panel.manage_moveUpAction(form, {}) |
---|
| 477 | self.assertEquals( |
---|
| 478 | self.tool.portal_tabs.getObjectPosition('quintagroup'), 0) |
---|
[3402] | 479 | |
---|
[801] | 480 | def test_manage_moveDownAction(self): |
---|
| 481 | self.purgeActions() |
---|
| 482 | self.setupActions(self.tool) |
---|
| 483 | form = {'orig_id': 'home', |
---|
| 484 | 'category': 'portal_tabs', |
---|
| 485 | 'visible_home': True, |
---|
| 486 | 'id_home': 'home', |
---|
| 487 | 'title_home': 'title1', |
---|
| 488 | 'url_expr_home': 'expr1', |
---|
| 489 | 'available_expr_home': 'expr2'} |
---|
| 490 | self.panel.manage_moveDownAction(form, {}) |
---|
| 491 | self.assertEquals(self.tool.portal_tabs.getObjectPosition('home'), 1) |
---|
| 492 | |
---|
| 493 | |
---|
[775] | 494 | def test_suite(): |
---|
| 495 | suite = unittest.TestSuite() |
---|
[798] | 496 | suite.addTest(unittest.makeSuite(TestControlPanelHelperMethods)) |
---|
[917] | 497 | suite.addTest(unittest.makeSuite(TestControlPanelAPIMethods)) |
---|
[801] | 498 | suite.addTest(unittest.makeSuite(TestControlPanelManageMethods)) |
---|
[3402] | 499 | |
---|
[865] | 500 | # these tests are implemented as Selenium KSS Tests |
---|
| 501 | # using kss.demo package, and KSS plugins are tested by means of |
---|
| 502 | # ecmaunit.js |
---|
[775] | 503 | #suite.addTest(unittest.makeSuite(TestControlPanelKSSMethods)) |
---|
| 504 | return suite |
---|