Changeset 1725 for trunk/pylucid/tests

Show
Ignore:
Timestamp:
07/29/08 14:33:43 (20 months ago)
Author:
JensDiemer
Message:

* merge some redirect code together
* work-a-round for restricted plugin method and settings.TEMPLATE_DEBUG is on.
* add a unittest for this.

Location:
trunk/pylucid/tests
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid/tests/test_plugin_api.py

    r1669 r1725  
    6161        ) 
    6262 
    63         self.command = "/%s/%s/%s/%%s/" % ( 
    64             settings.COMMAND_URL_PREFIX, 
    65             self.test_page.id, 
    66             TEST_PLUGIN_NAME, 
    67         ) 
     63        self.base_url = "/%s/%s" % ( # Used with self.assertPluginAccess() 
     64            settings.COMMAND_URL_PREFIX, self.test_page.id 
     65        ) 
     66        self.command = "%s/%s/%%s/" % (self.base_url, TEST_PLUGIN_NAME) 
    6867        self.test_url = self.test_page.get_absolute_url() 
    6968 
     
    332331        ) 
    333332 
     333class 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 
    334389 
    335390if __name__ == "__main__": 
  • trunk/pylucid/tests/unittest_plugin/unittest_plugin.py

    r1706 r1725  
    7979        """ 
    8080        self.response.write("Hello world!") 
     81 
     82    def test_restricted_method(self): 
     83        """ 
     84        TODO: Must be update if ticket:199 is implemented! 
     85        ticket: "change plugin_manager_data (must_login and must_admin)" 
     86        """ 
     87        self.response.write("<pre>This is restricted!</pre>") 
    8188 
    8289    def test_attributes(self, attr_name): 
  • trunk/pylucid/tests/unittest_plugin/unittest_plugin_cfg.py

    r1720 r1725  
    5656        "must_admin"    : False, 
    5757    }, 
     58    "test_restricted_method" : global_rights, 
    5859    "test_attributes" : global_rights, 
    5960    "test_page_msg" : global_rights,