Skip to content

Commit 02502ca

Browse files
author
Peter Bengtsson
authored
[refactoring] smart_bytes exists in django 1.8 (#139)
* smart_bytes exists in django 1.8 * undo sneak-in commit * nits
1 parent 70cc070 commit 02502ca

File tree

7 files changed

+13
-40
lines changed

7 files changed

+13
-40
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Django of your choice. Here is such an example:
4545
4646
$ virtualenv -p /path/to/bin/python3.5 venv
4747
$ source venv
48-
(venv) $ pip install Django==1.11.1
48+
(venv) $ pip install Django==1.11.2
4949
(venv) $ pip install -r tests/requirements.txt
5050
(venv) $ DJANGO_SETTINGS_MODULE=tests.settings django-admin.py test
5151

mozilla_django_oidc/auth.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
import logging
55
import requests
66

7-
try:
8-
from django.utils.encoding import smart_bytes
9-
except ImportError:
10-
from django.utils.encoding import smart_str as smart_bytes
11-
from django.utils.encoding import smart_text
7+
from django.utils.encoding import smart_bytes, smart_text
128
from django.contrib.auth import get_user_model
139
from django.core.exceptions import SuspiciousOperation
1410
from django.core.urlresolvers import reverse

mozilla_django_oidc/middleware.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import logging
22
import time
33
try:
4-
from urllib import urlencode
5-
except ImportError:
64
from urllib.parse import urlencode
5+
except ImportError:
6+
# Python < 3
7+
from urllib import urlencode
78

89
import django
910
from django.core.urlresolvers import reverse

mozilla_django_oidc/views.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import time
22
try:
3-
from urllib import urlencode
4-
except ImportError:
53
from urllib.parse import urlencode
4+
except ImportError:
5+
# Python < 3
6+
from urllib import urlencode
67

78
from django.core.exceptions import SuspiciousOperation
89
from django.core.urlresolvers import reverse

tests/test_auth.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,9 @@ def test_successful_authentication_new_user(self, token_mock, request_mock, algo
198198
'redirect_uri': 'http://testserver/callback/',
199199
}
200200
self.assertEqual(User.objects.all().count(), 0)
201-
result = self.backend.authenticate(request=auth_request)
201+
self.backend.authenticate(request=auth_request)
202202
self.assertEqual(User.objects.all().count(), 1)
203203
user = User.objects.all()[0]
204-
self.assertEquals(user, result)
205-
206204
self.assertEquals(user.email, '[email protected]')
207205
self.assertEquals(user.username, 'username_algo')
208206

@@ -215,31 +213,6 @@ def test_successful_authentication_new_user(self, token_mock, request_mock, algo
215213
headers={'Authorization': 'Bearer access_granted'}
216214
)
217215

218-
@patch('mozilla_django_oidc.auth.requests')
219-
@patch('mozilla_django_oidc.auth.OIDCAuthenticationBackend.verify_token')
220-
def test_successful_authentication_no_email(self, token_mock, request_mock):
221-
"""What happens if the auth "works" but it doesn't have an email?"""
222-
auth_request = RequestFactory().get('/foo', {'code': 'foo',
223-
'state': 'bar'})
224-
auth_request.session = {}
225-
226-
token_mock.return_value = True
227-
get_json_mock = Mock()
228-
get_json_mock.json.return_value = {
229-
'nickname': 'a_username',
230-
'email': ''
231-
}
232-
request_mock.get.return_value = get_json_mock
233-
post_json_mock = Mock()
234-
post_json_mock.json.return_value = {
235-
'id_token': 'id_token',
236-
'access_token': 'access_granted'
237-
}
238-
request_mock.post.return_value = post_json_mock
239-
result = self.backend.authenticate(request=auth_request)
240-
assert result is None
241-
self.assertEqual(User.objects.all().count(), 0)
242-
243216
def test_authenticate_no_code_no_state(self):
244217
"""Test authenticate with wrong parameters."""
245218

tests/test_middleware.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
try:
44
from urllib.parse import parse_qs
55
except ImportError:
6+
# Python < 3
67
from urlparse import parse_qs
78

89
from mock import patch

tests/test_views.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
try:
2-
from urlparse import parse_qs, urlparse
3-
except ImportError:
42
from urllib.parse import parse_qs, urlparse
3+
except ImportError:
4+
# Python < 3
5+
from urlparse import parse_qs, urlparse
56

67
from mock import patch
78

0 commit comments

Comments
 (0)