Extend User from AbstractBaseUser and AnonymousUser

Django-1.8 added _meta classes for User models,
which aren't supported by AnonymousUsers, the
AbstractBaseUser provides default implementation
for _meta classes.

SimpleTest has been deprecated since Django-1.6 and
was now removed.

Unfortunately, this change drops Django-1.6 (and earlier) compatibility.

Co-Authored-By: Lin Hua Cheng <os.lcheng@gmail.com>

Partially Implements: blueprint django18
Change-Id: Ie243fd2304421694023f579f49f8fa201e761ba3
This commit is contained in:
Matthias Runge 2015-03-26 14:04:18 +01:00 committed by lin-hua-cheng
parent 2fcf6f569a
commit da2395146e
3 changed files with 16 additions and 13 deletions

View File

@ -20,7 +20,10 @@ import sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'openstack_auth.tests.settings' os.environ['DJANGO_SETTINGS_MODULE'] = 'openstack_auth.tests.settings'
import django import django
from django.test import simple as test_simple if django.VERSION < (1, 8, 0):
from django.test.simple import DjangoTestSuiteRunner as test_runner
else:
from django.test.runner import DiscoverRunner as test_runner
if hasattr(django, 'setup'): if hasattr(django, 'setup'):
django.setup() django.setup()
@ -35,7 +38,7 @@ def run(*test_args):
"..", "..",
) )
sys.path.insert(0, parent) sys.path.insert(0, parent)
failures = test_simple.DjangoTestSuiteRunner().run_tests(test_args) failures = test_runner().run_tests(test_args)
sys.exit(failures) sys.exit(failures)

View File

@ -117,7 +117,7 @@ class Token(object):
self.serviceCatalog = auth_ref.service_catalog.get_data() self.serviceCatalog = auth_ref.service_catalog.get_data()
class User(models.AnonymousUser): class User(models.AbstractBaseUser, models.AnonymousUser):
"""A User class with some extra special sauce for Keystone. """A User class with some extra special sauce for Keystone.
In addition to the standard Django user attributes, this class also has In addition to the standard Django user attributes, this class also has
@ -191,7 +191,7 @@ class User(models.AnonymousUser):
services_region=None, user_domain_id=None, services_region=None, user_domain_id=None,
user_domain_name=None, domain_id=None, domain_name=None, user_domain_name=None, domain_id=None, domain_name=None,
project_id=None, project_name=None, project_id=None, project_name=None,
is_federated=False, unscoped_token=None): is_federated=False, unscoped_token=None, password=None):
self.id = id self.id = id
self.pk = id self.pk = id
self.token = token self.token = token
@ -221,6 +221,9 @@ class User(models.AnonymousUser):
self.tenant_id = self.project_id self.tenant_id = self.project_id
self.tenant_name = self.project_name self.tenant_name = self.project_name
# Required by AbstractBaseUser
self.password = None
def __unicode__(self): def __unicode__(self):
return self.username return self.username

15
tox.ini
View File

@ -1,7 +1,7 @@
[tox] [tox]
minversion = 1.6 minversion = 1.6
skipsdist = True skipsdist = True
envlist = py27,py27dj14,py27dj15,py27dj16,pep8,py33,py34 envlist = py27,py27dj17,py27dj18,pep8,py33,py34
[testenv] [testenv]
usedevelop = True usedevelop = True
@ -24,22 +24,19 @@ commands =
python -m coverage html --include='openstack_auth/*' --omit='openstack_auth/tests/*' -d 'reports' python -m coverage html --include='openstack_auth/*' --omit='openstack_auth/tests/*' -d 'reports'
python -m coverage xml --include='openstack_auth/*' --omit='openstack_auth/tests/*' python -m coverage xml --include='openstack_auth/*' --omit='openstack_auth/tests/*'
[testenv:py27dj16] [testenv:py27dj17]
commands = pip install django>=1.6,<1.7 commands = pip install django>=1.7,<1.8
python openstack_auth/tests/run_tests.py {posargs} python openstack_auth/tests/run_tests.py {posargs}
[testenv:py27dj15] [testenv:py27dj18]
commands = pip install django>=1.5,<1.6 commands = pip install django>=1.8,<1.9
python openstack_auth/tests/run_tests.py {posargs}
[testenv:py27dj14]
commands = pip install django>=1.4,<1.5
python openstack_auth/tests/run_tests.py {posargs} python openstack_auth/tests/run_tests.py {posargs}
[testenv:pep8] [testenv:pep8]
setenv = DJANGO_SETTINGS_MODULE=openstack_auth.tests.settings setenv = DJANGO_SETTINGS_MODULE=openstack_auth.tests.settings
commands = flake8 commands = flake8
[testenv:venv] [testenv:venv]
commands = {posargs} commands = {posargs}