Skip to content

Commit 2f3fc6e

Browse files
committed
tests for broken related objects with custom Application
See issue #90
1 parent 16524e0 commit 2f3fc6e

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

oauth2_provider/tests/models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.db import models
2+
from oauth2_provider.models import AbstractApplication
3+
4+
5+
class TestApplication(AbstractApplication):
6+
custom_field = models.CharField(max_length=255)

oauth2_provider/tests/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
'django.contrib.admin',
6969

7070
'oauth2_provider',
71+
'oauth2_provider.tests',
7172
)
7273

7374
LOGGING = {

oauth2_provider/tests/test_models.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
from __future__ import unicode_literals
22

3+
try:
4+
from unittest import skipIf
5+
except ImportError:
6+
from django.utils.unittest.case import skipIf
7+
8+
import django
39
from django.test import TestCase
10+
from django.test.utils import override_settings
411
from django.core.exceptions import ValidationError
512

613
from ..models import AccessToken, get_application_model
@@ -60,3 +67,22 @@ def test_grant_implicit_redirect_uris(self):
6067
)
6168

6269
self.assertRaises(ValidationError, app.full_clean)
70+
71+
@skipIf(django.VERSION < (1, 5), "Behavior is broken on 1.4 and there is no solution")
72+
@override_settings(OAUTH2_PROVIDER_APPLICATION_MODEL='tests.TestApplication')
73+
class TestCustomApplicationModel(TestCase):
74+
def setUp(self):
75+
self.user = UserModel.objects.create_user("test_user", "[email protected]", "123456")
76+
77+
def test_related_objects(self):
78+
"""
79+
If a custom application model is installed, it should be present in
80+
the related objects and not the swapped out one.
81+
82+
See issue #90 (https://github.com/evonove/django-oauth-toolkit/issues/90)
83+
"""
84+
# Django internals caches the related objects.
85+
del UserModel._meta._related_objects_cache
86+
related_object_names = [ro.name for ro in UserModel._meta.get_all_related_objects()]
87+
self.assertNotIn('oauth2_provider:application', related_object_names)
88+
self.assertIn('tests:testapplication', related_object_names)

0 commit comments

Comments
 (0)