Skip to content

Instantly share code, notes, and snippets.

@rpq
Created September 18, 2014 13:35
Show Gist options
  • Save rpq/780500367a23f56c8359 to your computer and use it in GitHub Desktop.
Save rpq/780500367a23f56c8359 to your computer and use it in GitHub Desktop.
django admin testing login
31 +class AdminLoginMixin(object):
40 32
41 33 def _create_user(self):
42 34 self.TEST_USERNAME = 'testusername'
43 35 self.TEST_PASSWORD = 'testpassword'
44 36
45 37 u, created = auth_models.User.objects.get_or_create(
46 38 username=self.TEST_USERNAME)
47 39 if created:
48 40 u.set_password(self.TEST_PASSWORD)
49 41 u.is_staff = True
50 42 u.is_superuser = True
51 43 u.save()
52 44 self.user = u
53 45
54 46 def _login(self):
55 47 self._create_user()
56 48 self.CREDENTIALS = {'username': self.TEST_USERNAME,
57 49 'password': self.TEST_PASSWORD}
58 50 self.client.login(**self.CREDENTIALS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment