I am looking for a way to clear the cache after a request. In the same test, I am testing the results with a normal user request, and staff user request. Here's the important part of my test (from an APITestCase class)
# REGULAR USER
self.client.login(username=user.username, password=self.password)
response = self.client.get(url)
# HTTP_200_OK
self.assertEqual(response.status_code, status.HTTP_200_OK)
# Only 1 user can be returned
self.assertEqual(len(response.data), 1)
# User returned is current user
self.assertEqual(response.data[0]['username'], 'user')
# STAFF USER
cache.clear() # <- this does not work
# Creating a staff user
staff_user = User(username='staff_user', password=self.password, is_staff=True)
staff_user.set_password(self.password)
staff_user.save()
self.client.logout()
self.client.login(username=staff_user.username, password=self.password)
response = self.client.get(url)
# HTTP_200_OK
self.assertEqual(response.status_code, status.HTTP_200_OK)
print response.data
# Superuser cannot be contained in list
self.assertEqual(len(response.data), 3)
So, in the second response I am getting the same results, although they should be different
Aucun commentaire:
Enregistrer un commentaire