diff options
| author | Tom Christie | 2015-02-04 14:20:21 +0000 |
|---|---|---|
| committer | Tom Christie | 2015-02-04 14:20:21 +0000 |
| commit | d21617ff3bc39114a8d9cb75666158e80f1242d0 (patch) | |
| tree | 15da031a9587fb2277b1361de8ca39f61b9d5424 /tests/test_authentication.py | |
| parent | 46181341d5579cb7a1b07cd7203b2f94b6c9c119 (diff) | |
| parent | 58e7bbc8ecad8016cc18f7dbd31b235cb515b785 (diff) | |
| download | django-rest-framework-d21617ff3bc39114a8d9cb75666158e80f1242d0.tar.bz2 | |
Merge pull request #2519 from Ofir-Purple/optimize-token-auth-queries
Prefetching the user object when getting the token in TokenAuthentication
Diffstat (limited to 'tests/test_authentication.py')
| -rw-r--r-- | tests/test_authentication.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/tests/test_authentication.py b/tests/test_authentication.py index 44837c4e..caabcc21 100644 --- a/tests/test_authentication.py +++ b/tests/test_authentication.py @@ -202,6 +202,12 @@ class TokenAuthTests(TestCase): response = self.csrf_client.post('/token/', {'example': 'example'}, format='json', HTTP_AUTHORIZATION=auth) self.assertEqual(response.status_code, status.HTTP_200_OK) + def test_post_json_makes_one_db_query(self): + """Ensure that authenticating a user using a token performs only one DB query""" + auth = "Token " + self.key + func_to_test = lambda: self.csrf_client.post('/token/', {'example': 'example'}, format='json', HTTP_AUTHORIZATION=auth) + self.assertNumQueries(1, func_to_test) + def test_post_form_failing_token_auth(self): """Ensure POSTing form over token auth without correct credentials fails""" response = self.csrf_client.post('/token/', {'example': 'example'}) |
