I'm trying to unit test an REST API viewset using the examples here. If I run the code line-by-line in manage.py shell, I can authenticate just fine and get a 200 response code. When it's in my unit test, the authentication fails!
Here's the class:
class RiskViewSetTest(unittest.TestCase):
def setUp(self):
pass
def testClientView(self):
client = APIClient()
client.login(username='[email protected]',password='realpassword')
response = client.get('/api/v1/risks/')
self.assertTrue(response.status_code, 200)
If I change the assertion to:
self.assertTrue(client.login(username='[email protected]',password='realpassword'))
it also fails, whereas the same command in shell returns True.
client.login(username='[email protected]',password='realpassword')isn't authenticating, but when I try the exact same code in shell, it authenticates!