diff options
| author | Stephan Groß | 2012-11-21 11:56:34 +0100 |
|---|---|---|
| committer | Stephan Groß | 2012-11-21 11:56:34 +0100 |
| commit | 6ba4df8a27016fd5e60a3852eea6c97231a03281 (patch) | |
| tree | 935bb3d51a9c3f4307d2d83d4b4c2e4d884886e3 /rest_framework/tests/authentication.py | |
| parent | ed713d0354b67bdc64de9346b9a72e1adfced76e (diff) | |
| parent | 3268c67343f6fc6364a0127a7bfabeb907a4751d (diff) | |
| download | django-rest-framework-6ba4df8a27016fd5e60a3852eea6c97231a03281.tar.bz2 | |
Merge remote-tracking branch 'upstream/master' into regex_field
Conflicts:
docs/topics/release-notes.md
Diffstat (limited to 'rest_framework/tests/authentication.py')
| -rw-r--r-- | rest_framework/tests/authentication.py | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/rest_framework/tests/authentication.py b/rest_framework/tests/authentication.py index 8ab4c4e4..96ca9f52 100644 --- a/rest_framework/tests/authentication.py +++ b/rest_framework/tests/authentication.py @@ -1,4 +1,4 @@ -from django.conf.urls.defaults import patterns +from django.conf.urls.defaults import patterns, include from django.contrib.auth.models import User from django.test import Client, TestCase @@ -27,6 +27,7 @@ MockView.authentication_classes += (TokenAuthentication,) urlpatterns = patterns('', (r'^$', MockView.as_view()), + (r'^auth-token/', 'rest_framework.authtoken.views.obtain_auth_token'), ) @@ -152,3 +153,33 @@ class TokenAuthTests(TestCase): self.token.delete() token = Token.objects.create(user=self.user) self.assertTrue(bool(token.key)) + + def test_token_login_json(self): + """Ensure token login view using JSON POST works.""" + client = Client(enforce_csrf_checks=True) + response = client.post('/auth-token/login/', + json.dumps({'username': self.username, 'password': self.password}), 'application/json') + self.assertEqual(response.status_code, 200) + self.assertEqual(json.loads(response.content)['token'], self.key) + + def test_token_login_json_bad_creds(self): + """Ensure token login view using JSON POST fails if bad credentials are used.""" + client = Client(enforce_csrf_checks=True) + response = client.post('/auth-token/login/', + json.dumps({'username': self.username, 'password': "badpass"}), 'application/json') + self.assertEqual(response.status_code, 400) + + def test_token_login_json_missing_fields(self): + """Ensure token login view using JSON POST fails if missing fields.""" + client = Client(enforce_csrf_checks=True) + response = client.post('/auth-token/login/', + json.dumps({'username': self.username}), 'application/json') + self.assertEqual(response.status_code, 400) + + def test_token_login_form(self): + """Ensure token login view using form POST works.""" + client = Client(enforce_csrf_checks=True) + response = client.post('/auth-token/login/', + {'username': self.username, 'password': self.password}) + self.assertEqual(response.status_code, 200) + self.assertEqual(json.loads(response.content)['token'], self.key) |
