Commits

Robert Brewer  committed ab47261

Test for tool kwargs from config using custom toolbox.

  • Participants
  • Parent commits 6cf069a

Comments (0)

Files changed (1)

File cherrypy/test/test_tools.py

     # Put check_access in a custom toolbox with its own namespace
     myauthtools = cherrypy._cptools.Toolbox("myauth")
     
-    def check_access():
-        if not getattr(cherrypy.request, "login", None):
+    def check_access(default=False):
+        if not getattr(cherrypy.request, "userid", default):
             raise cherrypy.HTTPError(401)
     myauthtools.check_access = cherrypy.Tool('before_request_body', check_access)
     
         def restricted(self):
             return "Welcome!"
         restricted = myauthtools.check_access()(restricted)
+        userid = restricted
         
         def err_in_onstart(self):
             return "success!"
         '/demo/restricted': {
             'request.show_tracebacks': False,
         },
+        '/demo/userid': {
+            'request.show_tracebacks': False,
+            'myauth.check_access.default': True,
+        },
         '/demo/errinstream': {
             'response.stream': True,
         },
         # Test the "__call__" technique (compile-time decorator).
         self.getPage("/demo/restricted")
         self.assertErrorPage(401)
+        
+        # Test compile-time decorator with kwargs from config.
+        self.getPage("/demo/userid")
+        self.assertBody("Welcome!")
     
     def testGuaranteedHooks(self):
         # The 'critical' on_start_resource hook is 'failsafe' (guaranteed