Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Commit

Permalink
Better test (to squash)
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Sep 22, 2017
1 parent a1584b2 commit 63dc76e
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions tests/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ def test_post_form_passing_jwt_auth(self):
'/jwt/', {'example': 'example'}, HTTP_AUTHORIZATION=auth)

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.content, b'abc')

# Ensure `authenticate` returned the decoded payload.
self.assertEqual(response.wsgi_request.user, self.user)
payload = response.wsgi_request.auth
self.assertIsInstance(payload, dict)
self.assertEqual(set(payload.keys()), {
'user_id', 'username', 'exp', 'email'})

def test_post_json_passing_jwt_auth(self):
"""
Expand Down Expand Up @@ -285,17 +293,3 @@ def test_post_form_failing_jwt_auth_different_auth_header_prefix(self):

# Restore original settings
api_settings.JWT_AUTH_HEADER_PREFIX = DEFAULTS['JWT_AUTH_HEADER_PREFIX']

def test_authenticate_returns_decoded_payload(self):
"""
Ensure `authenticate` returns the decoded payload, and not the
JWT value.
"""
payload = utils.jwt_payload_handler(self.user)
token = utils.jwt_encode_handler(payload)
auth = 'JWT {0}'.format(token)
request = factory.request(HTTP_AUTHORIZATION=auth)
(user, payload) = JSONWebTokenAuthentication().authenticate(request)
self.assertIsInstance(payload, dict)
self.assertEqual(set(payload.keys()), {
'user_id', 'username', 'exp', 'email'})

0 comments on commit 63dc76e

Please sign in to comment.