gmr/Tinman — pull request #5 by brisssou (2012-11-06 08:33:28+00:00)
Title: Testing require_basic_auth-wrapped handlers

Hello,
I added a parameter in the `require_basic_auth` wrapper.
This way, you can use the wrapper and still be able to test your handler:

from tinman.auth import AM_I_TESTING
from tinman.auth.basic import require_basic_auth
import tornado.web
import ldapauth

@require_basic_auth('Authrealm',
ldapauth.auth_user_ldap,
not AM_I_TESTING.am_i)
class SomeHandler(tornado.web.RequestHandler):
pass

And then you test case may look like this:

from tinman.auth import AM_I_TESTING
AM_I_TESTING.am_i = True
#More imports

class Test(AsyncHTTPTestCase):
pass

The first tow lines really have to be those ones, and the wrapper will not wrap the handler, so you can test the code, with no need of authentication, or mock authentication.

I'm not really happy with the names of the function/class/parameter or the way it's used, but it does the work, and I can now test a wrapped Handler.

Brice.