From 765d0693891d7d0e58492d3c2ab4e1ddb8582195 Mon Sep 17 00:00:00 2001 From: Raymond Penners Date: Tue, 16 Aug 2016 10:26:12 +0200 Subject: [PATCH] Django 1.10 --- .travis.yml | 1 + ChangeLog.rst | 12 ++++ allauth/account/tests.py | 63 +++++++++++-------- allauth/compat.py | 8 +++ .../templatetags/socialaccount.py | 6 +- allauth/tests.py | 16 +++++ tox.ini | 3 +- 7 files changed, 80 insertions(+), 29 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2025d3607d..38b356657f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ env: - DJANGO="Django<1.8" - DJANGO="Django<1.9" - DJANGO="Django<1.10" + - DJANGO="Django<1.11" cache: directories: - $HOME/.cache/pip diff --git a/ChangeLog.rst b/ChangeLog.rst index 7db05da41e..a0cfff7792 100644 --- a/ChangeLog.rst +++ b/ChangeLog.rst @@ -1,3 +1,15 @@ +Unreleased +********** + +Note worthy changes +------------------- + +- Django 1.10 compatibility. + +- The Twitter provider now supports querying of the email address. + + + 0.26.1 (2016-07-25) ******************* diff --git a/allauth/account/tests.py b/allauth/account/tests.py index f724762d19..4b1650cb89 100644 --- a/allauth/account/tests.py +++ b/allauth/account/tests.py @@ -145,15 +145,21 @@ def test_signup_email_twice(self): user = get_user_model().objects.get(username='johndoe') self.assertEqual(user.email, 'john@work.com') - def _create_user(self): - user = get_user_model().objects.create(username='john', is_active=True) - user.set_password('doe') + def _create_user(self, username='john', password='doe'): + user = get_user_model().objects.create( + username=username, + is_active=True) + if password: + user.set_password(password) + else: + user.set_unusable_password() user.save() return user - def _create_user_and_login(self): - user = self._create_user() - self.client.login(username='john', password='doe') + def _create_user_and_login(self, usable_password=True): + password = 'doe' if usable_password else False + user = self._create_user(password=password) + self.client_force_login(user) return user def test_redirect_when_authenticated(self): @@ -168,33 +174,38 @@ def test_password_reset_get(self): self.assertTemplateUsed(resp, 'account/password_reset.html') def test_password_set_redirect(self): - resp = self._password_set_or_reset_redirect('account_set_password', - True) - self.assertEqual(resp.status_code, 302) + resp = self._password_set_or_change_redirect( + 'account_set_password', + True) + self.assertRedirects( + resp, + reverse('account_change_password'), + fetch_redirect_response=False) - def test_password_reset_no_redirect(self): - resp = self._password_set_or_reset_redirect('account_change_password', - True) + def test_password_change_no_redirect(self): + resp = self._password_set_or_change_redirect( + 'account_change_password', + True) self.assertEqual(resp.status_code, 200) def test_password_set_no_redirect(self): - resp = self._password_set_or_reset_redirect('account_set_password', - False) + resp = self._password_set_or_change_redirect( + 'account_set_password', + False) self.assertEqual(resp.status_code, 200) - def test_password_reset_redirect(self): - resp = self._password_set_or_reset_redirect('account_change_password', - False) - self.assertEqual(resp.status_code, 302) + def test_password_change_redirect(self): + resp = self._password_set_or_change_redirect( + 'account_change_password', + False) + self.assertRedirects( + resp, + reverse('account_set_password'), + fetch_redirect_response=False) - def _password_set_or_reset_redirect(self, urlname, usable_password): - user = self._create_user_and_login() - c = self.client - if not usable_password: - user.set_unusable_password() - user.save() - resp = c.get(reverse(urlname)) - return resp + def _password_set_or_change_redirect(self, urlname, usable_password): + self._create_user_and_login(usable_password) + return self.client.get(reverse(urlname)) def test_password_forgotten_username_hint(self): user = self._request_new_password() diff --git a/allauth/compat.py b/allauth/compat.py index 09b79a2d4f..6de9059fa0 100644 --- a/allauth/compat.py +++ b/allauth/compat.py @@ -34,3 +34,11 @@ def render_to_string( else: def validate_password(password, user=None, password_validators=None): pass + + +def template_context_value(context, key): + try: + value = context[key] + except KeyError: + value = getattr(context, key) + return value diff --git a/allauth/socialaccount/templatetags/socialaccount.py b/allauth/socialaccount/templatetags/socialaccount.py index ce7cd8ec0f..f6040c2be8 100644 --- a/allauth/socialaccount/templatetags/socialaccount.py +++ b/allauth/socialaccount/templatetags/socialaccount.py @@ -3,6 +3,8 @@ from allauth.socialaccount import providers from allauth.utils import get_request_param +from allauth.compat import template_context_value + register = template.Library() @@ -14,7 +16,7 @@ def __init__(self, provider_id, params): def render(self, context): provider_id = self.provider_id_var.resolve(context) - request = context['request'] + request = template_context_value(context, 'request') provider = providers.registry.by_id(provider_id, request) query = dict([(str(name), var.resolve(context)) for name, var in self.params.items()]) @@ -52,7 +54,7 @@ def provider_login_url(parser, token): class ProvidersMediaJSNode(template.Node): def render(self, context): - request = context['request'] + request = template_context_value(context, 'request') ret = '\n'.join([p.media_js(request) for p in providers.registry.get_list(request)]) return ret diff --git a/allauth/tests.py b/allauth/tests.py index 4d5bd943cc..99642f3f7a 100644 --- a/allauth/tests.py +++ b/allauth/tests.py @@ -10,6 +10,7 @@ from django.test import TestCase as DjangoTestCase from django.db import models +from allauth.account.utils import user_username from . import utils from .compat import urlparse, urlunparse @@ -53,6 +54,21 @@ def assertRedirects(self, response, expected_url, actual_url = urlunparse(parts) self.assertEqual(expected_url, actual_url) + def client_force_login(self, user): + if django.VERSION >= (1, 9): + self.client.force_login( + user, + 'django.contrib.auth.backends.ModelBackend') + else: + old_password = user.password + user.set_password('doe') + user.save() + self.client.login( + username=user_username(user), + password='doe') + user.password = old_password + user.save() + class MockedResponse(object): def __init__(self, status_code, content, headers=None): diff --git a/tox.ini b/tox.ini index e126fbf2a1..ec7b99ce09 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{27,32,33,34,35}-django{17,18,19} +envlist = py{27,32,33,34,35}-django{17,18,19,110} [testenv] deps = @@ -8,6 +8,7 @@ deps = django17: Django < 1.8 django18: Django < 1.9 django19: Django < 1.10 + django110: Django < 1.11 commands = coverage run manage.py test allauth coverage report