On 5/11/07, sandro dentella <[EMAIL PROTECTED]> wrote:
>
>
> I'm trying to use test.client to test some pages that are login
> protected.
>
> 1. the docs say that syntax is:
>    """
>    c = Client()
>    c.login(username='fred', password='secret')
>    # Now you can access a login protected view
>    """
>
>    while the signature is:
>
>    def login(self, path, username, password, **extra):

This is a recent backwards-incompatible change in the development
stream. The login method was changed to make it more robust, capable
of supporting different authentication schemes, and less bound to
templates.

If you have Django 0.96 (or a pre-5152 SVN checkout), the old
prototype will be correct, and you should consult the 0.96 docs
(/documentation/0.96/testing/).

If you have a post-5152 SVN checkout, the new prototype will be
correct, and the docs on /documentation/testing/ will be correct.

> 2. the response of c.get() has correct content but no context and no
>    template. Any possible explanation?

There won't be any context or template objects in one of two circumstances:
- No templates were used to render the content
- The test case isn't being run in a test environment. The signal that
capture template rendering information don't exist by default - they
are installed as part of a test system startup script
(setup_test_environment). If you are running the unit tests outside of
'./manage.py test', this script probably won't be called.

> A NOTE to save time to people that may read this while trying to
> debug the c.login. It's important you LOGIN_URL end with a slash,
> if not - as was my case- c.get issued by c.login will receive a 301
> instead of a 302. That allows the browser to continue, not the
> login method. ;-(

Hence one of the many reasons for the backwards incompatible change.
This problem doesn't affect the new version of Client.login().

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django 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/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to