Skip to content

Instantly share code, notes, and snippets.

@bengolder
Created May 28, 2016 03:56
Show Gist options
  • Save bengolder/c9dc7006f9d6b4d17d5af5465115df73 to your computer and use it in GitHub Desktop.
Save bengolder/c9dc7006f9d6b4d17d5af5465115df73 to your computer and use it in GitHub Desktop.
A useful Django test assertion for testing auth based on http://stackoverflow.com/questions/5660952/test-that-user-was-logged-in-successfully
from django.test import TestCase
from django.contrib import auth
class BaseAuthTestCase(TestCase):
def assertLoggedInAs(self, user):
client_user = auth.get_user(self.client)
self.assertEqual(client_user, user)
assert client_user.is_authenticated()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment