|
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
|
@@ -60,3 +67,22 @@ def test_grant_implicit_redirect_uris(self):
|
60 | 67 | )
|
61 | 68 |
|
62 | 69 | 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