|
1 | 1 | from __future__ import unicode_literals |
2 | 2 |
|
| 3 | +try: |
| 4 | + from unittest import skipIf |
| 5 | +except ImportError: |
| 6 | + from django.utils.unittest.case import skipIf |
| 7 | + |
| 8 | +import django |
3 | 9 | from django.test import TestCase |
| 10 | +from django.test.utils import override_settings |
4 | 11 | from django.core.exceptions import ValidationError |
5 | 12 |
|
6 | 13 | from ..models import AccessToken, get_application_model |
@@ -72,3 +79,22 @@ def test_str(self): |
72 | 79 |
|
73 | 80 | app.name = "test_app" |
74 | 81 | self.assertEqual("%s" % app, "test_app") |
| 82 | + |
| 83 | +@skipIf(django.VERSION < (1, 5), "Behavior is broken on 1.4 and there is no solution") |
| 84 | +@override_settings(OAUTH2_PROVIDER_APPLICATION_MODEL='tests.TestApplication') |
| 85 | +class TestCustomApplicationModel(TestCase): |
| 86 | + def setUp(self): |
| 87 | + self.user = UserModel.objects.create_user("test_user", "test@user.com", "123456") |
| 88 | + |
| 89 | + def test_related_objects(self): |
| 90 | + """ |
| 91 | + If a custom application model is installed, it should be present in |
| 92 | + the related objects and not the swapped out one. |
| 93 | +
|
| 94 | + See issue #90 (https://github.com/evonove/django-oauth-toolkit/issues/90) |
| 95 | + """ |
| 96 | + # Django internals caches the related objects. |
| 97 | + del UserModel._meta._related_objects_cache |
| 98 | + related_object_names = [ro.name for ro in UserModel._meta.get_all_related_objects()] |
| 99 | + self.assertNotIn('oauth2_provider:application', related_object_names) |
| 100 | + self.assertIn('tests:testapplication', related_object_names) |
0 commit comments