I've been attempting many different methods to login as superuser to test-drive admin features with Django 1.9 and Python 3.5, and all seem to have failed. I'm attempting with fixtures or with just setting is_superuser
to True.
fixtures gives me this warning:
...C:\Users\Jordon\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\management\commands\loaddata.py:243: User
Warning: No fixture named 'users' found.
warnings.warn("No fixture named '%s' found." % fixture_name)
And the line self.client.login(username='user', password='password')
in the following block appears to absolutely nothing, as the next line indicates, and as a print statement verified, showing the same login page. I could perhaps try selenium on it, but I'm trying to figure out why it's not taking the login credentials.
class AdminTest(LiveServerTestCase):
fixtures = ['users.json']
def setUp(self):
self.user = User(username='user', password='password')
self.user.is_superuser = True
self.user.is_staff = True
self.user.save()
self.client = Client()
def test_login(self):
response = self.client.get('/admin/', follow=True)
self.assertEqual(response.status_code, 200)
self.assertTrue('Log in' in response.content.decode('utf-8'))
self.client.login(username='user', password='password')
response = self.client.get('/admin/', follow=True)
self.assertTrue('Log out' in response.content.decode('utf-8'))
Aucun commentaire:
Enregistrer un commentaire