Django Unittests Client Login: Fails In Test Suite, But Not In Shell
I'm running a basic test of my home view. While logging the client in from the shell works, the same line of code fails to log the client in when using the test suite. What is the
Solution 1:
A test user should be created. Something like:
defsetUp(self):
self.client = Client()
self.username = 'agconti'
self.email = 'test@test.com'
self.password = 'test'
self.test_user = User.objects.create_user(self.username, self.email, self.password)
login = self.client.login(username=self.username, password=self.password)
self.assertEqual(login, True)
In your shell test the user is probably already present in your db, whereas in your unittest there might not be a user...
Post a Comment for "Django Unittests Client Login: Fails In Test Suite, But Not In Shell"