Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix #148: Add experimental support for Python 3.3 and 3.2.

  • Loading branch information...
commit ee8a1e398525ec222dd324aba1b9439009175b21 1 parent dcc16b0
@graingert graingert authored Osmose committed
View
13 .travis.yml
@@ -5,8 +5,17 @@ python:
env:
- DJANGO_VERSION=1.3.7
- DJANGO_VERSION=1.4.5
- - DJANGO_VERSION=1.5
+ - DJANGO_VERSION=1.5.1
+matrix:
+ include:
+ - python: 3.2
+ env: DJANGO_VERSION=1.5.1
+ - python: 3.3
+ env: DJANGO_VERSION=1.5.1
+ allow_failures:
+ - python: 3.2
install:
- - pip install -e git+git://github.com/django/django.git@${DJANGO_VERSION}#egg=django
+ - pip install -e git+git://github.com/sobotklp/django-nose@b3f485e914965e0a7b7012c309864d6a6dcac3ed#egg=django-nose
+ - pip install django==${DJANGO_VERSION}
- pip install -r requirements.txt --use-mirrors
script: python setup.py test
View
10 django_browserid/auth.py
@@ -8,6 +8,10 @@
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.importlib import import_module
+try:
+ from django.utils.encoding import smart_bytes
+except ImportError:
+ from django.utils.encoding import smart_str as smart_bytes
from django_browserid.base import verify
from django_browserid.signals import user_created
@@ -28,9 +32,9 @@ def default_username_algo(email):
# store the username as a base64 encoded sha1 of the email address
# this protects against data leakage because usernames are often
# treated as public identifiers (so we can't use the email address).
- username = base64.urlsafe_b64encode(
- hashlib.sha1(email).digest()).rstrip('=')
- return username
+ return base64.urlsafe_b64encode(
+ hashlib.sha1(smart_bytes(email)).digest()
+ ).rstrip(b'=')
class BrowserIDBackend(object):
View
9 django_browserid/forms.py
@@ -4,6 +4,10 @@
from django import forms
from django.conf import settings
+try:
+ from django.utils.encoding import smart_bytes
+except ImportError:
+ from django.utils.encoding import smart_str as smart_bytes
FORM_JAVASCRIPT = ('browserid/browserid.js',)
FORM_CSS = ('browserid/persona-buttons.css',)
@@ -20,7 +24,10 @@ class Media:
def clean_assertion(self):
try:
- return str(self.cleaned_data['assertion'])
+ return smart_bytes(
+ self.cleaned_data['assertion'],
+ encoding='ascii'
+ )
except UnicodeEncodeError:
# not ascii :(
raise forms.ValidationError('non-ascii string')
View
3  django_browserid/helpers.py
@@ -13,6 +13,7 @@
from django_browserid.util import LazyEncoder, static_url
+from six import string_types
# If funfactory is available, we want to use it's locale-aware reverse instead
# of Django's reverse, so we try to import funfactory's first and fallback to
@@ -73,7 +74,7 @@ def browserid_button(text=None, next=None, link_class=None,
href to use for the link.
"""
attrs = attrs or {}
- if isinstance(attrs, basestring):
+ if isinstance(attrs, string_types):
attrs = json.loads(attrs)
attrs.setdefault('class', link_class)
View
68 django_browserid/tests/test_auth.py
@@ -10,12 +10,6 @@
from django_browserid.auth import BrowserIDBackend, default_username_algo, verify
from django_browserid.tests import mock_browserid
-# Support Python 2.6 by using unittest2
-try:
- from unittest import skipIf
-except ImportError:
- from unittest2 import skipIf
-
try:
from django.contrib.auth import get_user_model
from django_browserid.tests.models import CustomUser
@@ -105,34 +99,34 @@ def test_verify_called_with_browserid_extra(self, user_verify):
user_verify.assert_called_with('asdf', 'asdf', extra_params=dic)
-# Only run custom user model tests if we're using a version of Django that
-# supports it.
-@patch.object(settings, 'AUTH_USER_MODEL', 'tests.CustomUser')
-@skipIf(not get_user_model, 'Not supported in Django < 1.5')
-class CustomUserModelTests(TestCase):
- def _auth(self, backend=None, verified_email=None):
- if backend is None:
- backend = BrowserIDBackend()
-
- with mock_browserid(verified_email):
- return backend.authenticate(assertion='asdf', audience='asdf')
-
- def test_existing_user(self):
- """If a custom user exists with the given email, return them."""
- user = CustomUser.objects.create(email='a@test.com')
- authed_user = self._auth(verified_email='a@test.com')
- self.assertEqual(user, authed_user)
-
- @patch.object(settings, 'BROWSERID_CREATE_USER', True)
- def test_create_new_user(self):
- """
- If a custom user does not exist with the given email, create a new
- user and return them.
- """
- class CustomUserBrowserIDBackend(BrowserIDBackend):
- def create_user(self, email):
- return CustomUser.objects.create(email=email)
- user = self._auth(backend=CustomUserBrowserIDBackend(),
- verified_email='b@test.com')
- self.assertTrue(isinstance(user, CustomUser))
- self.assertEqual(user.email, 'b@test.com')
+if get_user_model:
+ # Only run custom user model tests if we're using a version of Django that
+ # supports it.
+ @patch.object(settings, 'AUTH_USER_MODEL', 'tests.CustomUser')
+ class CustomUserModelTests(TestCase):
+ def _auth(self, backend=None, verified_email=None):
+ if backend is None:
+ backend = BrowserIDBackend()
+
+ with mock_browserid(verified_email):
+ return backend.authenticate(assertion='asdf', audience='asdf')
+
+ def test_existing_user(self):
+ """If a custom user exists with the given email, return them."""
+ user = CustomUser.objects.create(email='a@test.com')
+ authed_user = self._auth(verified_email='a@test.com')
+ self.assertEqual(user, authed_user)
+
+ @patch.object(settings, 'BROWSERID_CREATE_USER', True)
+ def test_create_new_user(self):
+ """
+ If a custom user does not exist with the given email, create a new
+ user and return them.
+ """
+ class CustomUserBrowserIDBackend(BrowserIDBackend):
+ def create_user(self, email):
+ return CustomUser.objects.create(email=email)
+ user = self._auth(backend=CustomUserBrowserIDBackend(),
+ verified_email='b@test.com')
+ self.assertTrue(isinstance(user, CustomUser))
+ self.assertEqual(user.email, 'b@test.com')
View
2  django_browserid/tests/test_forms.py
@@ -11,5 +11,5 @@ def test_invalid_assertion():
def test_valid_assertion():
- form = BrowserIDForm({'assertion': 'xxx'})
+ form = BrowserIDForm({'assertion': b'xxx'})
assert form.is_valid()
View
3  django_browserid/tests/test_views.py
@@ -9,6 +9,7 @@
from django_browserid import BrowserIDException, views
from django_browserid.tests import mock_browserid, patch_settings
+from six.moves import reload_module
factory = RequestFactory()
@@ -32,7 +33,7 @@ def verify(request_type, success_url=None, failure_url=None, **kwargs):
# We need to reload verify for the setting changes to take effect.
with patch_settings(**patches):
- reload(views)
+ reload_module(views)
verify_view = views.Verify.as_view()
with patch.object(auth, 'login'):
response = verify_view(request)
View
11 django_browserid/views.py
@@ -2,7 +2,14 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import logging
-import urlparse
+
+import six
+
+if six.PY3:
+ from urllib import parse as urllib_parse
+else:
+ import urlparse as urllib_parse
+
from django.conf import settings
from django.contrib import auth
@@ -56,7 +63,7 @@ def login_success(self):
# Do not accept redirect URLs pointing to a different host.
if redirect_to:
- netloc = urlparse.urlparse(redirect_to).netloc
+ netloc = urllib_parse.urlparse(redirect_to).netloc
if netloc and netloc != self.request.get_host():
redirect_to = None
View
3  requirements.txt
@@ -4,8 +4,7 @@ fancy_tag==0.2.0
# Tests
mock>=0.8.0
Django>=1.3
-django-nose
-unittest2==0.5.1
+-e git+git://github.com/sobotklp/django-nose@b3f485e914965e0a7b7012c309864d6a6dcac3ed#egg=django-nose
pyquery==1.2.4
# Documentation
View
4 setup.py
@@ -15,7 +15,7 @@
def read(*parts):
- return codecs.open(os.path.join(os.path.dirname(__file__), *parts)).read()
+ return codecs.open(os.path.join(os.path.dirname(__file__), *parts), encoding='utf8').read()
def find_version(*file_paths):
@@ -37,7 +37,7 @@ def find_version(*file_paths):
author_email='mkelly@mozilla.com',
url='https://github.com/mozilla/django-browserid',
license='MPL v2.0',
- install_requires=['requests>=0.9.1', 'fancy_tag==0.2.0'],
+ install_requires=['requests>=0.9.1', 'fancy_tag==0.2.0', 'six>=1.3'],
test_suite="runtests.runtests",
include_package_data=True,
classifiers=[
Please sign in to comment.
Something went wrong with that request. Please try again.