| | 333 | class PluginPermissionsTest(PluginAPI_Base): |
| | 334 | """ |
| | 335 | Test the permissions of a plugin method |
| | 336 | |
| | 337 | Test the work-a-round if settings.TEMPLATE_DEBUG is on and a AccessDenied |
| | 338 | would be catched and raised as a TemplateSyntaxError, see: |
| | 339 | * django/template/debug.py |
| | 340 | * PyLucid.index._render_cms_page() |
| | 341 | |
| | 342 | TODO: Must be update if ticket:199 is implemented! |
| | 343 | ticket: "change plugin_manager_data (must_login and must_admin)" |
| | 344 | """ |
| | 345 | def test_restricted_method_deny(self): |
| | 346 | """ |
| | 347 | Test to access a restricted method as a anonymous user. |
| | 348 | Test with settings.TEMPLATE_DEBUG True/False |
| | 349 | """ |
| | 350 | from PyLucid.system.exceptions import AccessDenied |
| | 351 | |
| | 352 | def test(): |
| | 353 | try: |
| | 354 | self.assertPluginAccess( |
| | 355 | self.base_url, |
| | 356 | plugin_name = TEST_PLUGIN_NAME, |
| | 357 | method_names = ("test_restricted_method",), |
| | 358 | must_contain=("[Permission Denied!]",), |
| | 359 | must_not_contain=("Traceback",) |
| | 360 | ) |
| | 361 | except AccessDenied: |
| | 362 | pass # It's ok. |
| | 363 | except Exception: |
| | 364 | raise |
| | 365 | |
| | 366 | self.client.logout() |
| | 367 | old_value = settings.TEMPLATE_DEBUG |
| | 368 | |
| | 369 | settings.TEMPLATE_DEBUG = True |
| | 370 | test() |
| | 371 | settings.TEMPLATE_DEBUG = False |
| | 372 | test() |
| | 373 | |
| | 374 | settings.TEMPLATE_DEBUG = old_value |
| | 375 | |
| | 376 | def test_restricted_method_allowed(self): |
| | 377 | """ |
| | 378 | If the user logged in, he should see the plugin output |
| | 379 | """ |
| | 380 | self.login("superuser") # login client as superuser |
| | 381 | self.assertPluginAccess( |
| | 382 | self.base_url, |
| | 383 | plugin_name = TEST_PLUGIN_NAME, |
| | 384 | method_names = ("test_restricted_method",), |
| | 385 | must_contain=("This is restricted!",), |
| | 386 | must_not_contain=("Traceback",) |
| | 387 | ) |
| | 388 | |