Commit a70466bb authored by Tim Graham's avatar Tim Graham
Browse files

Add testing for Django 1.10

parent d1ffc7a8
......@@ -5,11 +5,14 @@ cache: pip
env:
- TOXENV=py27-django18
- TOXENV=py27-django19
- TOXENV=py27-django110
- TOXENV=py33-django18
- TOXENV=py34-django18
- TOXENV=py34-django19
- TOXENV=py34-django110
- TOXENV=py35-django18
- TOXENV=py35-django19
- TOXENV=py35-django110
- TOXENV=docs
- TOXENV=lint
install:
......
......@@ -30,7 +30,7 @@ Changelog
* 1.0 (TBA):
* Drop support for Django < 1.8.
* Drop support for Django < 1.8 and confirm support for Django 1.10.
* 0.9 (2016-06-01):
......
from django.contrib.auth.models import (
AbstractBaseUser, AbstractUser, BaseUserManager, Group, Permission,
PermissionsMixin, UserManager,
)
from django.db import models
# The custom User uses email as the unique identifier, and requires
# that every user provide a date of birth. This lets us test
# changes in username datatype, and non-text required fields.
class CustomUserManager(BaseUserManager):
def create_user(self, email, date_of_birth, password=None):
"""
Creates and saves a User with the given email and password.
"""
if not email:
raise ValueError('Users must have an email address')
user = self.model(
email=self.normalize_email(email),
date_of_birth=date_of_birth,
)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, email, password, date_of_birth):
u = self.create_user(
email, password=password, date_of_birth=date_of_birth,
)
u.is_admin = True
u.save(using=self._db)
return u
class CustomUser(AbstractBaseUser):
email = models.EmailField(
verbose_name='email address',
max_length=255,
unique=True,
)
is_active = models.BooleanField(default=True)
is_admin = models.BooleanField(default=False)
date_of_birth = models.DateField()
custom_objects = CustomUserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['date_of_birth']
def get_full_name(self):
return self.email
def get_short_name(self):
return self.email
def __str__(self):
return self.email
# Maybe required?
def get_group_permissions(self, obj=None):
return set()
def get_all_permissions(self, obj=None):
return set()
def has_perm(self, perm, obj=None):
return True
def has_perms(self, perm_list, obj=None):
return True
def has_module_perms(self, app_label):
return True
# Admin required fields
@property
def is_staff(self):
return self.is_admin
class RemoveGroupsAndPermissions(object):
"""
A context manager to temporarily remove the groups and user_permissions M2M
fields from the AbstractUser class, so they don't clash with the
related_name sets.
"""
def __enter__(self):
self._old_au_local_m2m = AbstractUser._meta.local_many_to_many
self._old_pm_local_m2m = PermissionsMixin._meta.local_many_to_many
groups = models.ManyToManyField(Group, blank=True)
groups.contribute_to_class(PermissionsMixin, "groups")
user_permissions = models.ManyToManyField(Permission, blank=True)
user_permissions.contribute_to_class(
PermissionsMixin, "user_permissions"
)
PermissionsMixin._meta.local_many_to_many = [groups, user_permissions]
AbstractUser._meta.local_many_to_many = [groups, user_permissions]
def __exit__(self, exc_type, exc_value, traceback):
AbstractUser._meta.local_many_to_many = self._old_au_local_m2m
PermissionsMixin._meta.local_many_to_many = self._old_pm_local_m2m
# The extension user is a simple extension of the built-in user class,
# adding a required date_of_birth field.
with RemoveGroupsAndPermissions():
class ExtensionUser(AbstractUser):
date_of_birth = models.DateField()
custom_objects = UserManager()
REQUIRED_FIELDS = AbstractUser.REQUIRED_FIELDS + ['date_of_birth']
from unittest import SkipTest
from django.contrib.auth import get_user_model
from django.contrib.auth.tests.custom_user import CustomUser, ExtensionUser
from django.core import mail
from django.core.urlresolvers import reverse
from django.test import TestCase
......@@ -10,11 +9,12 @@ from django.utils import timezone
from django.utils.six import with_metaclass
from ..forms import PasswordRecoveryForm, PasswordResetForm
from .models import CustomUser, ExtensionUser
class CustomUserVariants(type):
def __new__(cls, name, bases, dct):
for custom_user in ['auth.CustomUser', 'auth.ExtensionUser']:
for custom_user in ['tests.CustomUser', 'tests.ExtensionUser']:
suffix = custom_user.lower().replace('.', '_')
for key, fn in list(dct.items()):
if key.startswith('test') and '_CUSTOM_' not in key:
......
......@@ -27,6 +27,7 @@ setup(
'Framework :: Django',
'Framework :: Django :: 1.8',
'Framework :: Django :: 1.9',
'Framework :: Django :: 1.10',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Natural Language :: English',
......
[tox]
envlist =
py27-django1{8,9},
py27-django1{8,9,10},
py33-django18,
py34-django1{8,9},
py35-django1{8,9},
py34-django1{8,9,10},
py35-django1{8,9,10},
docs, lint
[testenv]
......@@ -16,6 +16,7 @@ basepython =
deps =
django18: Django>=1.8,<1.9
django19: Django>=1.9,<1.10
django110: Django>=1.10,<1.11
[testenv:docs]
basepython = python3.5
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment