Skip to content

Commit

Permalink
Add tox and fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jpadilla committed Sep 2, 2014
1 parent 5f9e0d8 commit a4e34f8
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 16 deletions.
7 changes: 7 additions & 0 deletions jwt_auth/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@
from django.utils.encoding import smart_text
except ImportError:
from django.utils.encoding import smart_unicode as smart_text

try:
# In 1.5 the test client uses force_bytes
from django.utils.encoding import force_bytes as force_bytes_or_smart_bytes
except ImportError:
# In 1.4 the test client just uses smart_str
from django.utils.encoding import smart_str as force_bytes_or_smart_bytes
4 changes: 2 additions & 2 deletions jwt_auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.views.generic import View
from django.core.serializers.json import DjangoJSONEncoder

from jwt_auth.compat import json
from jwt_auth.compat import json, smart_text
from jwt_auth.forms import JSONWebTokenForm


Expand All @@ -13,7 +13,7 @@ class ObtainJSONWebToken(View):

def post(self, request, *args, **kwargs):
try:
request_json = json.loads(request.body)
request_json = json.loads(smart_text(request.body))
except ValueError:
return self.render_bad_request_response()

Expand Down
16 changes: 7 additions & 9 deletions tests/test_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
from django.test.client import Client

from jwt_auth import utils
from jwt_auth.compat import User, json
from jwt_auth.compat import User, json, smart_text


class JSONWebTokenAuthMixinTestCase(TestCase):
# urls = 'tests.test_mixins'

def setUp(self):
self.email = '[email protected]'
self.username = 'jpueblo'
Expand Down Expand Up @@ -37,7 +35,7 @@ def test_post_json_passing_jwt_auth(self):
HTTP_AUTHORIZATION=auth
)

response_content = json.loads(response.content)
response_content = json.loads(smart_text(response.content))

self.assertEqual(response.status_code, 200)
self.assertEqual(response_content['username'], self.username)
Expand All @@ -48,7 +46,7 @@ def test_post_json_failing_jwt_auth(self):
"""
response = self.client.post('/jwt/', content_type='application/json')

response_content = json.loads(response.content)
response_content = json.loads(smart_text(response.content))

self.assertEqual(response.status_code, 401)
self.assertEqual(response['WWW-Authenticate'], 'JWT realm="api"')
Expand All @@ -67,7 +65,7 @@ def test_post_no_jwt_header_failing_jwt_auth(self):
HTTP_AUTHORIZATION=auth,
)

response_content = json.loads(response.content)
response_content = json.loads(smart_text(response.content))

self.assertEqual(response.status_code, 401)
self.assertEqual(response['WWW-Authenticate'], 'JWT realm="api"')
Expand All @@ -86,7 +84,7 @@ def test_post_invalid_jwt_header_failing_jwt_auth(self):
HTTP_AUTHORIZATION=auth
)

response_content = json.loads(response.content)
response_content = json.loads(smart_text(response.content))

self.assertEqual(response.status_code, 401)
self.assertEqual(response['WWW-Authenticate'], 'JWT realm="api"')
Expand All @@ -109,7 +107,7 @@ def test_post_expired_token_failing_jwt_auth(self):
HTTP_AUTHORIZATION=auth
)

response_content = json.loads(response.content)
response_content = json.loads(smart_text(response.content))

self.assertEqual(response.status_code, 401)
self.assertEqual(response['WWW-Authenticate'], 'JWT realm="api"')
Expand All @@ -128,7 +126,7 @@ def test_post_invalid_token_failing_jwt_auth(self):
HTTP_AUTHORIZATION=auth
)

response_content = json.loads(response.content)
response_content = json.loads(smart_text(response.content))

self.assertEqual(response.status_code, 401)
self.assertEqual(response['WWW-Authenticate'], 'JWT realm="api"')
Expand Down
8 changes: 3 additions & 5 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
from django.test.client import Client

from jwt_auth import utils
from jwt_auth.compat import json, User
from jwt_auth.compat import json, User, smart_text


class ObtainJSONWebTokenTestCase(TestCase):
# urls = 'tests.test_views'

def setUp(self):
self.email = '[email protected]'
self.username = 'jpueblo'
Expand All @@ -32,7 +30,7 @@ def test_jwt_login_json(self):
content_type='application/json'
)

response_content = json.loads(response.content)
response_content = json.loads(smart_text(response.content))

decoded_payload = utils.jwt_decode_handler(response_content['token'])

Expand Down Expand Up @@ -83,7 +81,7 @@ def test_jwt_login_with_expired_token(self):
HTTP_AUTHORIZATION=auth
)

response_content = json.loads(response.content)
response_content = json.loads(smart_text(response.content))

decoded_payload = utils.jwt_decode_handler(response_content['token'])

Expand Down
86 changes: 86 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
[tox]
downloadcache = {toxworkdir}/cache/
envlist =
py3.4-django1.6,py3.3-django1.6,py3.2-django1.6,py2.7-django1.6,py2.6-django1.6,
py3.4-django1.5,py3.3-django1.5,py3.2-django1.5,py2.7-django1.5,py2.6-django1.5,
py2.7-django1.4,py2.6-django1.4

[testenv]
commands = ./runtests.py --fast

[testenv:flake8]
basepython = python2.7
deps = Django
-rrequirements.txt
-rrequirements-test.txt
commands = ./runtests.py --lintonly

[testenv:py3.4-django1.6]
basepython = python3.4
deps = Django==1.6.3

[testenv:py3.3-django1.6]
basepython = python3.3
deps = Django==1.6.3
-rrequirements.txt
-rrequirements-test.txt

[testenv:py3.2-django1.6]
basepython = python3.2
deps = Django==1.6.3
-rrequirements.txt
-rrequirements-test.txt

[testenv:py2.7-django1.6]
basepython = python2.7
deps = Django==1.6.3
-rrequirements.txt
-rrequirements-test.txt

[testenv:py2.6-django1.6]
basepython = python2.6
deps = Django==1.6.3
-rrequirements.txt
-rrequirements-test.txt

[testenv:py3.4-django1.5]
basepython = python3.4
deps = Django==1.5.6
-rrequirements.txt
-rrequirements-test.txt

[testenv:py3.3-django1.5]
basepython = python3.3
deps = Django==1.5.6
-rrequirements.txt
-rrequirements-test.txt

[testenv:py3.2-django1.5]
basepython = python3.2
deps = Django==1.5.6
-rrequirements.txt
-rrequirements-test.txt

[testenv:py2.7-django1.5]
basepython = python2.7
deps = Django==1.5.6
-rrequirements.txt
-rrequirements-test.txt

[testenv:py2.6-django1.5]
basepython = python2.6
deps = Django==1.5.6
-rrequirements.txt
-rrequirements-test.txt

[testenv:py2.7-django1.4]
basepython = python2.7
deps = Django==1.4.11
-rrequirements.txt
-rrequirements-test.txt

[testenv:py2.6-django1.4]
basepython = python2.6
deps = Django==1.4.11
-rrequirements.txt
-rrequirements-test.txt

0 comments on commit a4e34f8

Please sign in to comment.