> On 19 Aug 2014, at 23:13, pyramidX <[email protected]> wrote:
> 
> I'm using DummyRequest in my tests to test authentication, this is what I 
> return from the view when login succeeds
> 
>             headers = remember(request, email)
>             return HTTPFound(location=next, headers=headers)
> 
> 
> 
> This is my test
> 
>         request = testing.DummyRequest(post={'usr': '[email protected]', 
> 'pwd': 'mypassword'})
>         view = views.login(request)
>         print(view.headers)

The returned value there is a response object.

>         print(request.headers)

The exact response here will vary a bit depending on your authentication 
policy. For auth_tkt you should see a couple of Set-Cookie headers that set the 
authentication cookie. If you use a session authentication policy you might not 
see anything here, or only a Set-Cookie header to set the session cookie.

>         print(unauthenticated_userid(request))
>         print(authenticated_userid(request))

Those function only work on an incoming request, not on a response object.

> How can I test that authentication has worked?

That depends a bit on your testing style. The most reliable method is to write 
an integration test and do a second request and check the response to see if 
authentication succeeded. The pure unit-test approach is to insert a mock for 
remember() and check if the headers returned by remember() show up in the 
response headers.

Wichert.

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.

Reply via email to