Hello, is there a way to fake the user group and membership as well? 
Thanks! 

On Saturday, April 7, 2012 at 5:24:09 PM UTC+2, Anthony wrote:
>
> 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?
>>
>>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to