Permalink
Browse files

call get_user_model in try block for better backwards compatibility

  • Loading branch information...
1 parent e823dc7 commit 080f6fae322a71414b0cea5eef445f251554f822 Brent Hagany committed Feb 1, 2014
@@ -4,6 +4,7 @@
except ImportError: import json
try:
from django.contrib.auth import get_user_model # Django 1.5+
+ User = get_user_model()
except:
from django.contrib.auth.models import User
from oauth2app.models import Client
@@ -30,14 +31,14 @@ class BaseTestCase(unittest.TestCase):
client_application = None
def setUp(self):
- self.user = (get_user_model() or User).objects.create_user(
+ self.user = User.objects.create_user(
USER_USERNAME,
USER_EMAIL,
USER_PASSWORD)
self.user.first_name = USER_FIRSTNAME
self.user.last_name = USER_LASTNAME
self.user.save()
- self.client = (get_user_model() or User).objects.create_user(CLIENT_USERNAME, CLIENT_EMAIL)
+ self.client = User.objects.create_user(CLIENT_USERNAME, CLIENT_EMAIL)
self.client_application = Client.objects.create(
name="TestApplication",
user=self.client)
@@ -8,6 +8,7 @@
from django.utils import unittest
try:
from django.contrib.auth import get_user_model # Django 1.5+
+ User = get_user_model()
except:
from django.contrib.auth.models import User
from oauth2app.models import Client
@@ -31,14 +32,14 @@ class MACTestCase(unittest.TestCase):
client_application = None
def setUp(self):
- self.user = (get_user_model() or User).objects.create_user(
+ self.user = User.objects.create_user(
USER_USERNAME,
USER_EMAIL,
USER_PASSWORD)
self.user.first_name = USER_FIRSTNAME
self.user.last_name = USER_LASTNAME
self.user.save()
- self.client = (get_user_model() or User).objects.create_user(CLIENT_USERNAME, CLIENT_EMAIL)
+ self.client = User.objects.create_user(CLIENT_USERNAME, CLIENT_EMAIL)
self.client_application = Client.objects.create(
name="TestApplication",
user=self.client)
@@ -70,4 +71,3 @@ def test_00_mac(self):
parameters,
HTTP_AUTHORIZATION="Basic %s" % basic_auth)
token = json.loads(response.content)
-
@@ -7,6 +7,7 @@
from django.test.client import Client as DjangoTestClient
try:
from django.contrib.auth import get_user_model # Django 1.5+
+ User = get_user_model()
except:
from django.contrib.auth.models import User
from oauth2app.models import Client
@@ -29,14 +30,14 @@ class ResponseTypeTestCase(unittest.TestCase):
client_application = None
def setUp(self):
- self.user = (get_user_model() or User).objects.create_user(
+ self.user = User.objects.create_user(
USER_USERNAME,
USER_EMAIL,
USER_PASSWORD)
self.user.first_name = USER_FIRSTNAME
self.user.last_name = USER_LASTNAME
self.user.save()
- self.client = (get_user_model() or User).objects.create_user(CLIENT_USERNAME, CLIENT_EMAIL)
+ self.client = User.objects.create_user(CLIENT_USERNAME, CLIENT_EMAIL)
self.client_application = Client.objects.create(
name="TestApplication",
user=self.client)
@@ -9,6 +9,7 @@
from django.test.client import Client as DjangoTestClient
try:
from django.contrib.auth import get_user_model # Django 1.5+
+ User = get_user_model()
except:
from django.contrib.auth.models import User
from oauth2app.models import Client
@@ -31,14 +32,14 @@ class ScopeTestCase(unittest.TestCase):
client_application = None
def setUp(self):
- self.user = (get_user_model() or User).objects.create_user(
+ self.user = User.objects.create_user(
USER_USERNAME,
USER_EMAIL,
USER_PASSWORD)
self.user.first_name = USER_FIRSTNAME
self.user.last_name = USER_LASTNAME
self.user.save()
- self.client = (get_user_model() or User).objects.create_user(CLIENT_USERNAME, CLIENT_EMAIL)
+ self.client = User.objects.create_user(CLIENT_USERNAME, CLIENT_EMAIL)
self.client_application = Client.objects.create(
name="TestApplication",
user=self.client)
@@ -176,4 +177,3 @@ def test_02_dual_scope(self):
HTTP_AUTHORIZATION="Bearer %s" % token)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, USER_FIRSTNAME)
-

0 comments on commit 080f6fa

Please sign in to comment.