The key you're missing there is instantiating the environment.
Instead of
self.controller.user('register'), you need to do something like:

self.controller = env('myapp', True, c='default', f='myfunction')

and then you can do assertions on the various objects bound to the
controller (request, response, auth, etc).
(So, for example, to test if a user is logged in, I do:
self.assert_(controller['auth'].user is None)
)

On Fri, Oct 9, 2009 at 5:00 PM, bm <[email protected]> wrote:
>
> Does anyone know how to unit test the auth functions in web2py?
>
> If so, could you please send examples?
>
> So far, using the example unit test provided here:
> http://www.web2py.com/AlterEgo/default/show/213 as the basis, I've
> attempted to call http://site/default/user/register.
>
> Here's an example:
>
> class TestDefaultController(unittest.TestCase):
>    def testRegisterGet_noKeys(self):
>        self.request.env.request_method = 'GET'
>        self.request.vars = None
>        self.controller.user('register')
>        form = self.controller.user('register').response._vars['form']
>        self.assertFalse(form.errors)
>
>
> I've tried some obvious permutations of the line:
>        self.controller.user('register')
> like:
>        self.controller.user.register
>        self.controller.user(register)
>
> But to no avail, so far.
>
> Naturally, for the 2 examples above that are passing an arg I changed
> the default.py user function to be:
>
>     def user(arg=None):
>          return dict(form=auth())
>
> but, oddly, I get the following error when I've tried passing
> 'register' as an arg:
>
> NameError: global name 'auth' is not defined
>
> Also, I've already checked the projects source tree for existing unit
> tests for auth.
>
> Thanks in advance to anyone that provides insight and examples on how
> to this. :-)
>
>
>
>
>
>
>
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to