For @auth.requires_login() to pass, I think you just need auth.user to 
exist (and not be None). If your layout includes auth.navbar(), I think the 
auth.user object at least needs to include an "id" attribute as well (i.e., 
auth.user.id should be some integer). So maybe add something like this in 
your test code:

from gluon.storage import Storage
auth.user = Storage(dict(id=1))

Anthony

On Saturday, April 7, 2012 4:11:53 AM UTC-4, backseat wrote:
>
> I've been looking that the unit testing page
> (http://www.web2py.com/AlterEgo/default/show/260), which is very helpful.
> However, most of my controller functions are decorated with
> '@auth.requires_login()', and thus if I call them from the test suite,
> they fail (issuing a redirect):
>
>   File "/home/kae/hg/kae/web2py/gluon/tools.py", line 934, in <lambda>
>     settings.on_failed_authentication = lambda x: redirect(x)
>   File "/home/kae/hg/kae/web2py/gluon/http.py", line 128, in redirect
>     Location=location)
> HTTP: 303 SEE OTHER
>
> One could argue that's a "correct" failure because the test suite isn't
> authenticated, but I'd like to use unit tests to test functions that need
> authentication. I don't want to test the authentication mechanism itself.
>
> Is there a way to fake authentication to allow unit testing? Do others
> have a better way of doing this?
> -- 
> "You can have everything in life you want if you help enough other people
> get what they want" - Zig Ziglar. 
>
> Who did you help today?
>
>

Reply via email to