From 10be6439a91facbef67ae6a34a2ac6ec9b6483c3 Mon Sep 17 00:00:00 2001 From: Alexander Schrijver Date: Tue, 27 Sep 2016 18:13:10 +0200 Subject: [PATCH] Add a test for inactive users with token auth. --- tests/test_authentication.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_authentication.py b/tests/test_authentication.py index 5ef620abe..4996ef669 100644 --- a/tests/test_authentication.py +++ b/tests/test_authentication.py @@ -349,6 +349,25 @@ class TokenAuthTests(BaseTokenAuthTests, TestCase): format='json' ) self.assertEqual(response.status_code, 400) + self.assertEqual(response.data['non_field_errors'], + [u'Unable to log in with provided credentials.', ]) + + def test_token_login_json_inactive_user(self): + """ + Ensure token login view using JSON POST fails if + an inactive user is given. + """ + self.user.is_active = False + self.user.save() + client = APIClient(enforce_csrf_checks=True) + response = client.post( + '/auth-token/', + {'username': self.username, 'password': self.password}, + format='json' + ) + self.assertEqual(response.status_code, 400) + self.assertEqual(response.data['non_field_errors'], + [u'User account is disabled.', ]) def test_token_login_json_missing_fields(self): """Ensure token login view using JSON POST fails if missing fields."""