From e9b314d4c11c22b89e010934cc31c14a3fb0276f Mon Sep 17 00:00:00 2001 From: Joshua Blum Date: Wed, 4 Oct 2017 11:16:32 -0400 Subject: [PATCH] Version bump (#292) * Test against latest django versions and python 3.6 * Make use of override_settings * Prep for 1.8 release --- .travis.yml | 15 +++++-- CHANGELOG | 4 +- docs/conf.py | 6 +-- docs/upgrade.rst | 7 +++- registration/__init__.py | 2 +- registration/tests/admin_actions.py | 35 ++++++----------- registration/tests/default_backend.py | 37 ++++-------------- registration/tests/forms_custom_user.py | 9 ++--- registration/tests/models.py | 52 ++++++++----------------- registration/tests/simple_backend.py | 13 +++---- 10 files changed, 65 insertions(+), 115 deletions(-) diff --git a/.travis.yml b/.travis.yml index 009f771e..37398936 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,21 +5,28 @@ python: - 3.3 - 3.4 - 3.5 + - 3.6 env: - DJANGO=Django==1.8.18 - DJANGO=Django==1.9.13 - - DJANGO=Django==1.10.7 - - DJANGO=Django==1.11.4 + - DJANGO=Django==1.10.8 + - DJANGO=Django==1.11.5 matrix: exclude: - python: 3.3 env: DJANGO=Django==1.9.13 - python: 3.3 - env: DJANGO=Django==1.10.7 + env: DJANGO=Django==1.10.8 - python: 3.3 - env: DJANGO=Django==1.11.4 + env: DJANGO=Django==1.11.5 + - python: 3.6 + env: DJANGO=Django==1.8.18 + - python: 3.6 + env: DJANGO=Django==1.9.13 + - python: 3.6 + env: DJANGO=Django==1.10.8 install: - pip install -r requirements.txt diff --git a/CHANGELOG b/CHANGELOG index 2eb7c104..159dfbbd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,9 +2,9 @@ django-registration-redux changelog =================================== -Version 1.8, TBD +Version 1.8, 03 October, 2017 ---------------- -* Bugfix: Add outlook.com to the list of free email providers. - +* Bugfix: Add `outlook.com` to the list of free email providers. - `#287 _` * Documentation: Add possible settings for activation emails. - `#283 _` diff --git a/docs/conf.py b/docs/conf.py index f2f8b1cd..7332e5d1 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -38,16 +38,16 @@ # General information about the project. project = u'django-registration-redux' -copyright = u'2007-2013, James Bennett. 2014, Andrew Cutler and others.' +copyright = u'2007-2013, James Bennett. 2014-2017, Andrew Cutler and others.' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = '1.7' +version = '1.8' # The full version, including alpha/beta/rc tags. -release = '1.7' +release = '1.8' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/upgrade.rst b/docs/upgrade.rst index b9dce0e4..b398a919 100644 --- a/docs/upgrade.rst +++ b/docs/upgrade.rst @@ -12,12 +12,17 @@ Django version requirement As of |version|, |project| requires Django 1.8 or newer; older Django releases may work, but are officially unsupported. Additionally, -|project| officially supports Python 2.7, 3.3, 3.4, and 3.5. +|project| officially supports Python 2.7, 3.3, 3.4, 3.5, and 3.6. Backwards-incompatible changes ------------------------------ +Version 1.8 +``````````` + +- None + Version 1.7 ``````````` diff --git a/registration/__init__.py b/registration/__init__.py index 82777552..ae66f9a3 100644 --- a/registration/__init__.py +++ b/registration/__init__.py @@ -1,4 +1,4 @@ -VERSION = (1, 7, 0, 'final', 0) +VERSION = (1, 8, 0, 'final', 0) def get_version(): diff --git a/registration/tests/admin_actions.py b/registration/tests/admin_actions.py index 217181bc..2ba5a1b7 100644 --- a/registration/tests/admin_actions.py +++ b/registration/tests/admin_actions.py @@ -1,14 +1,18 @@ from __future__ import unicode_literals -from django.conf import settings from django.contrib.admin import helpers from django.core import mail, urlresolvers from django.test import TestCase from django.test.client import Client +from django.test.utils import override_settings from registration.models import RegistrationProfile from registration.users import UserModel +@override_settings(ACCOUNT_ACTIVATION_DAYS=7, + REGISTRATION_DEFAULT_FROM_EMAIL='registration@email.com', + REGISTRATION_EMAIL_HTML=True, + DEFAULT_FROM_EMAIL='django@email.com') class AdminCustomActionsTestCase(TestCase): """ Test the available admin custom actions @@ -16,33 +20,14 @@ class AdminCustomActionsTestCase(TestCase): def setUp(self): self.client = Client() - admin_user = UserModel().objects.create_superuser('admin', 'admin@test.com', 'admin') + admin_user = UserModel().objects.create_superuser( + 'admin', 'admin@test.com', 'admin') self.client.login(username=admin_user.username, password=admin_user) self.user_info = {'username': 'alice', 'password': 'swordfish', 'email': 'alice@example.com'} - self.old_activation = getattr(settings, - 'ACCOUNT_ACTIVATION_DAYS', None) - self.old_reg_email = getattr(settings, - 'REGISTRATION_DEFAULT_FROM_EMAIL', None) - self.old_email_html = getattr(settings, - 'REGISTRATION_EMAIL_HTML', None) - self.old_django_email = getattr(settings, - 'DEFAULT_FROM_EMAIL', None) - - settings.ACCOUNT_ACTIVATION_DAYS = 7 - settings.REGISTRATION_DEFAULT_FROM_EMAIL = 'registration@email.com' - settings.REGISTRATION_EMAIL_HTML = True - settings.DEFAULT_FROM_EMAIL = 'django@email.com' - - def tearDown(self): - settings.ACCOUNT_ACTIVATION_DAYS = self.old_activation - settings.REGISTRATION_DEFAULT_FROM_EMAIL = self.old_reg_email - settings.REGISTRATION_EMAIL_HTML = self.old_email_html - settings.DEFAULT_FROM_EMAIL = self.old_django_email - def test_activate_users(self): """ Test the admin custom command 'activate users' @@ -53,7 +38,8 @@ def test_activate_users(self): self.assertFalse(profile.activated) - registrationprofile_list = urlresolvers.reverse('admin:registration_registrationprofile_changelist') + registrationprofile_list = urlresolvers.reverse( + 'admin:registration_registrationprofile_changelist') post_data = { 'action': 'activate_users', helpers.ACTION_CHECKBOX_NAME: [profile.pk], @@ -70,7 +56,8 @@ def test_resend_activation_email(self): new_user = UserModel().objects.create_user(**self.user_info) profile = RegistrationProfile.objects.create_profile(new_user) - registrationprofile_list = urlresolvers.reverse('admin:registration_registrationprofile_changelist') + registrationprofile_list = urlresolvers.reverse( + 'admin:registration_registrationprofile_changelist') post_data = { 'action': 'resend_activation_email', helpers.ACTION_CHECKBOX_NAME: [profile.pk], diff --git a/registration/tests/default_backend.py b/registration/tests/default_backend.py index 64d13839..dd3cd88f 100644 --- a/registration/tests/default_backend.py +++ b/registration/tests/default_backend.py @@ -14,7 +14,8 @@ from registration.users import UserModel -@override_settings(ROOT_URLCONF='test_app.urls_default') +@override_settings(ROOT_URLCONF='test_app.urls_default', + ACCOUNT_ACTIVATION_DAYS=7) class DefaultBackendViewTests(TestCase): """ Test the default registration backend. @@ -30,40 +31,18 @@ class DefaultBackendViewTests(TestCase): registration_view = RegistrationView - def setUp(self): - """ - Create an instance of the default backend for use in testing, - and set ``ACCOUNT_ACTIVATION_DAYS`` if it's not set already. - - """ - self.old_activation = getattr(settings, - 'ACCOUNT_ACTIVATION_DAYS', None) - if self.old_activation is None: - settings.ACCOUNT_ACTIVATION_DAYS = 7 # pragma: no cover - - def tearDown(self): - """ - Yank ``ACCOUNT_ACTIVATION_DAYS`` back out if it wasn't - originally set. - - """ - if self.old_activation is None: - # pragma: no cover - settings.ACCOUNT_ACTIVATION_DAYS = self.old_activation - - def test_allow(self): + @override_settings(REGISTRATION_OPEN=True) + def test_registration_open(self): """ The setting ``REGISTRATION_OPEN`` appropriately controls whether registration is permitted. """ - old_allowed = getattr(settings, 'REGISTRATION_OPEN', True) - settings.REGISTRATION_OPEN = True - resp = self.client.get(reverse('registration_register')) self.assertEqual(200, resp.status_code) - settings.REGISTRATION_OPEN = False + @override_settings(REGISTRATION_OPEN=False) + def test_registration_closed(self): # Now all attempts to hit the register view should redirect to # the 'registration is closed' message. @@ -77,8 +56,6 @@ def test_allow(self): 'password2': 'secret'}) self.assertRedirects(resp, reverse('registration_disallowed')) - settings.REGISTRATION_OPEN = old_allowed - def test_registration_get(self): """ HTTP ``GET`` to the registration view uses the appropriate @@ -90,7 +67,7 @@ def test_registration_get(self): self.assertTemplateUsed(resp, 'registration/registration_form.html') self.failUnless(isinstance(resp.context['form'], - RegistrationForm)) + RegistrationForm)) def test_registration(self): """ diff --git a/registration/tests/forms_custom_user.py b/registration/tests/forms_custom_user.py index 667b1b2e..48a25d01 100644 --- a/registration/tests/forms_custom_user.py +++ b/registration/tests/forms_custom_user.py @@ -8,28 +8,25 @@ pass # Python 2 reload() -from django.conf import settings from django.test import TestCase +from django.test.utils import override_settings from registration import forms from registration.users import UsernameField +@override_settings(AUTH_USER_MODEL='test_app.CustomUser') class RegistrationFormTests(TestCase): """ Test the default registration forms. """ + def setUp(self): - self.old_auth_model = getattr(settings, 'AUTH_USER_MODEL', None) - settings.AUTH_USER_MODEL = 'test_app.CustomUser' # The form's Meta class is created on import. We have to reload() # to apply the new AUTH_USER_MODEL to the Meta class. reload(forms) - def tearDown(self): - settings.AUTH_USER_MODEL = self.old_auth_model - def test_registration_form_adds_custom_user_name_field(self): """ Test that ``RegistrationForm`` adds custom username diff --git a/registration/tests/models.py b/registration/tests/models.py index 21e81281..bea07172 100644 --- a/registration/tests/models.py +++ b/registration/tests/models.py @@ -22,6 +22,10 @@ Site = apps.get_model('sites', 'Site') +@override_settings(ACCOUNT_ACTIVATION_DAYS=7, + REGISTRATION_DEFAULT_FROM_EMAIL='registration@email.com', + REGISTRATION_EMAIL_HTML=True, + DEFAULT_FROM_EMAIL='django@email.com') class RegistrationModelTests(TestCase): """ Test the model and manager used in the default backend. @@ -34,31 +38,7 @@ class RegistrationModelTests(TestCase): registration_profile = RegistrationProfile def setUp(self): - self.old_activation = getattr(settings, - 'ACCOUNT_ACTIVATION_DAYS', None) - self.old_reg_email = getattr(settings, - 'REGISTRATION_DEFAULT_FROM_EMAIL', None) - self.old_email_html = getattr(settings, - 'REGISTRATION_EMAIL_HTML', None) - self.old_django_email = getattr(settings, - 'DEFAULT_FROM_EMAIL', None) - self.old_django_admins = getattr(settings, 'ADMINS', None) - self.old_registration_admins = getattr(settings, 'REGISTRATION_ADMINS', - None) - warnings.simplefilter('always', UserWarning) - settings.ACCOUNT_ACTIVATION_DAYS = 7 - settings.REGISTRATION_DEFAULT_FROM_EMAIL = 'registration@email.com' - settings.REGISTRATION_EMAIL_HTML = True - settings.DEFAULT_FROM_EMAIL = 'django@email.com' - - def tearDown(self): - settings.ACCOUNT_ACTIVATION_DAYS = self.old_activation - settings.REGISTRATION_DEFAULT_FROM_EMAIL = self.old_reg_email - settings.REGISTRATION_EMAIL_HTML = self.old_email_html - settings.DEFAULT_FROM_EMAIL = self.old_django_email - settings.ADMINS = self.old_django_admins - settings.REGISTRATION_ADMINS = self.old_registration_admins def test_profile_creation(self): """ @@ -112,13 +92,13 @@ def test_activation_email_uses_registration_default_from_email(self): profile.send_activation_email(Site.objects.get_current()) self.assertEqual(mail.outbox[0].from_email, 'registration@email.com') + @override_settings(REGISTRATION_DEFAULT_FROM_EMAIL=None) def test_activation_email_falls_back_to_django_default_from_email(self): """ ``RegistrationProfile.send_activation_email`` sends an email. """ - settings.REGISTRATION_DEFAULT_FROM_EMAIL = None new_user = UserModel().objects.create_user(**self.user_info) profile = self.registration_profile.objects.create_profile(new_user) profile.send_activation_email(Site.objects.get_current()) @@ -136,13 +116,13 @@ def test_activation_email_is_html_by_default(self): self.assertEqual(len(mail.outbox[0].alternatives), 1) + @override_settings(REGISTRATION_EMAIL_HTML=False) def test_activation_email_is_plain_text_if_html_disabled(self): """ ``RegistrationProfile.send_activation_email`` sends a plain text email if settings.REGISTRATION_EMAIL_HTML is False. """ - settings.REGISTRATION_EMAIL_HTML = False new_user = UserModel().objects.create_user(**self.user_info) profile = self.registration_profile.objects.create_profile(new_user) profile.send_activation_email(Site.objects.get_current()) @@ -271,7 +251,8 @@ def test_valid_activation_with_profile(self): .activate_user(profile.activation_key, Site.objects.get_current(), get_profile=True)) - self.failUnless(isinstance(activated_profile, self.registration_profile)) + self.failUnless(isinstance(activated_profile, + self.registration_profile)) self.assertEqual(activated_profile.id, profile.id) self.failUnless(activated_profile.activated) @@ -589,7 +570,8 @@ def test_valid_activation_with_profile(self): .activate_user(profile.activation_key, Site.objects.get_current(), get_profile=True)) - self.failUnless(isinstance(activated_profile, self.registration_profile)) + self.failUnless(isinstance(activated_profile, + self.registration_profile)) self.assertEqual(activated_profile.id, profile.id) self.failUnless(activated_profile.activated) @@ -650,13 +632,13 @@ def test_admin_approval_email_uses_registration_default_from_email(self): new_user, Site.objects.get_current()) self.assertEqual(mail.outbox[0].from_email, 'registration@email.com') + @override_settings(REGISTRATION_DEFAULT_FROM_EMAIL=None) def test_admin_approval_email_falls_back_to_django_default_from_email(self): """ ``SupervisedRegistrationManager.send_admin_approve_email`` sends an email. """ - settings.REGISTRATION_DEFAULT_FROM_EMAIL = None new_user = UserModel().objects.create_user(**self.user_info) profile = self.registration_profile.objects.create_profile(new_user) profile.activated = True @@ -678,13 +660,13 @@ def test_admin_approval_email_is_html_by_default(self): self.assertEqual(len(mail.outbox[0].alternatives), 1) + @override_settings(REGISTRATION_EMAIL_HTML=False) def test_admin_approval_email_is_plain_text_if_html_disabled(self): """ ``SupervisedRegistrationProfile.send_activation_email`` sends a plain text email if settings.REGISTRATION_EMAIL_HTML is False. """ - settings.REGISTRATION_EMAIL_HTML = False new_user = UserModel().objects.create_user(**self.user_info) profile = self.registration_profile.objects.create_profile(new_user) profile.activated = True @@ -717,13 +699,13 @@ def test_admin_approval_complete_email_uses_registration_default_from_email(self self.assertEqual(len(mail.outbox), 1) self.assertEqual(mail.outbox[0].from_email, 'registration@email.com') + @override_settings(REGISTRATION_DEFAULT_FROM_EMAIL=None) def test_admin_approval_complete_email_falls_back_to_django_default_from_email(self): """ ``SupervisedRegistrationManager.send_admin_approve_complete_email`` sends an email """ - settings.REGISTRATION_DEFAULT_FROM_EMAIL = None new_user = UserModel().objects.create_user(**self.user_info) profile = self.registration_profile.objects.create_profile(new_user) profile.send_admin_approve_complete_email(Site.objects.get_current()) @@ -742,13 +724,13 @@ def test_admin_approval_complete_email_is_html_by_default(self): self.assertEqual(len(mail.outbox), 1) self.assertEqual(len(mail.outbox[0].alternatives), 1) + @override_settings(REGISTRATION_EMAIL_HTML=False) def test_admin_approval_complete_email_is_plain_text_if_html_disabled(self): """ ``SupervisedRegistrationProfile.send_admin_approve_complete_email`` sends a plain text email if settings.REGISTRATION_EMAIL_HTML is False. """ - settings.REGISTRATION_EMAIL_HTML = False new_user = UserModel().objects.create_user(**self.user_info) profile = self.registration_profile.objects.create_profile(new_user) profile.send_admin_approve_complete_email(Site.objects.get_current()) @@ -870,6 +852,7 @@ def old_method(self, save=True): profile = self.registration_profile.objects.get(user=new_user) self.assertTrue(profile.activated) + @override_settings(ADMINS=(), REGISTRATION_ADMINS=()) def test_no_admins_registered(self): """ Approving a non existent user profile does nothing and returns False @@ -877,12 +860,11 @@ def test_no_admins_registered(self): new_user = self.registration_profile.objects.create_inactive_user( site=Site.objects.get_current(), **self.user_info) - settings.ADMINS = () - settings.REGISTRATION_ADMINS = () with self.assertRaises(ImproperlyConfigured): self.registration_profile.objects.send_admin_approve_email( new_user, Site.objects.get_current()) + @override_settings(REGISTRATION_ADMINS=()) def test_no_registration_admins_registered(self): """ Approving a non existent user profile does nothing and returns False @@ -890,8 +872,6 @@ def test_no_registration_admins_registered(self): new_user = self.registration_profile.objects.create_inactive_user( site=Site.objects.get_current(), **self.user_info) - settings.REGISTRATION_ADMINS = () - with warnings.catch_warnings(record=True) as _warning: self.registration_profile.objects.send_admin_approve_email( new_user, Site.objects.get_current()) diff --git a/registration/tests/simple_backend.py b/registration/tests/simple_backend.py index 7528c6dd..e9993f13 100644 --- a/registration/tests/simple_backend.py +++ b/registration/tests/simple_backend.py @@ -9,19 +9,18 @@ @override_settings(ROOT_URLCONF='test_app.urls_simple') class SimpleBackendViewTests(TestCase): - def test_allow(self): + @override_settings(REGISTRATION_OPEN=True) + def test_registration_open(self): """ The setting ``REGISTRATION_OPEN`` appropriately controls whether registration is permitted. """ - old_allowed = getattr(settings, 'REGISTRATION_OPEN', True) - settings.REGISTRATION_OPEN = True - resp = self.client.get(reverse('registration_register')) self.assertEqual(200, resp.status_code) - settings.REGISTRATION_OPEN = False + @override_settings(REGISTRATION_OPEN=False) + def test_registration_closed(self): # Now all attempts to hit the register view should redirect to # the 'registration is closed' message. @@ -35,8 +34,6 @@ def test_allow(self): 'password2': 'secret'}) self.assertRedirects(resp, reverse('registration_disallowed')) - settings.REGISTRATION_OPEN = old_allowed - def test_registration_get(self): """ HTTP ``GET`` to the registration view uses the appropriate @@ -48,7 +45,7 @@ def test_registration_get(self): self.assertTemplateUsed(resp, 'registration/registration_form.html') self.failUnless(isinstance(resp.context['form'], - RegistrationForm)) + RegistrationForm)) def test_registration(self): """