Tony wrote:
> Hi
>
> I have tried numerous ways to login through client() but it keeps
> returning false.
> I have tested it in the shell and it works fine and returns
> login=true.
> But in my tests.py file, it keeps failing the test because it keeps
> returning login=false.
>
> Here is my script:
> """
> from django.test import TestCase
> from django.test.client import Client
>
> class AuthorisedUserTests(TestCase):
> def setUp(self):
> self.client = Client()
>
> def test_login_returns_True(self):
> response = self.client.login(username='auser',
> password='apassword')
> self.failUnlessEqual(response, True)
> """
>
> I have used Djangos inbuilt user authorisation through the use of
> "from django.contrib.auth.models import User". I am also using
> decorators.
>
> Where am I going wrong?
>
> Thanks in advance,
> Tony
The test runner always creates a new blank database to run against, so
there are no users set up. You will need to create one first:
from django.contrib.auth.models import User
testuser = User.objects.create_user('auser', '[EMAIL PROTECTED]',
'apassword')
testuser.is_staff=True
testuser.save()
You could probably do this in the setUp method if you are going to be
using it in multiple tests.
--
DR.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---