Skip to content

Commit 3cc27bd

Browse files
committed
Fix test setup for client model swapping
1 parent 53f86a8 commit 3cc27bd

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

oidc_provider/migrations/0027_auto_20181207_1311.py renamed to oidc_provider/migrations/0027_swappable_client_model.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
# Generated by Django 1.11.4 on 2018-12-07 13:11
2+
# Generated by Django 1.11.4 on 2018-12-07 14:12
33
from __future__ import unicode_literals
44

55
from django.conf import settings
@@ -19,4 +19,9 @@ class Migration(migrations.Migration):
1919
name='owner',
2020
field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='oidc_provider_client_set', to=settings.AUTH_USER_MODEL, verbose_name='Owner'),
2121
),
22+
migrations.AlterField(
23+
model_name='client',
24+
name='response_types',
25+
field=models.ManyToManyField(related_name='oidc_provider_client_set', to='oidc_provider.ResponseType'),
26+
),
2227
]

oidc_provider/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class AbstractClient(models.Model):
7373
u' of their credentials. <b>Public</b> clients are incapable.'))
7474
client_id = models.CharField(max_length=255, unique=True, verbose_name=_(u'Client ID'))
7575
client_secret = models.CharField(max_length=255, blank=True, verbose_name=_(u'Client SECRET'))
76-
response_types = models.ManyToManyField(ResponseType)
76+
response_types = models.ManyToManyField(
77+
ResponseType, related_name='%(app_label)s_%(class)s_set')
7778
jwt_alg = models.CharField(
7879
max_length=10,
7980
choices=JWT_ALGS,
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
from unittest import skip
2-
import django
31
from django.test import TestCase, override_settings
42
from django.contrib.auth import get_user_model
53

64
from oidc_provider.models import get_client_model, Client
7-
from oidc_provider.tests.models import CustomClient
5+
from oidc_provider.tests.models import Client as CustomClient
86

97
UserModel = get_user_model()
108

@@ -15,16 +13,15 @@ def test_retrieve_default_client_model(self):
1513
client = get_client_model()
1614
self.assertEqual(Client, client)
1715

18-
@override_settings(OIDC_CLIENT_MODEL='tests.CustomClient')
16+
@override_settings(OIDC_CLIENT_MODEL='tests.Client')
1917
def test_retrireve_custom_client_model(self):
2018
client = get_client_model()
2119
self.assertEqual(CustomClient, client)
2220

2321

24-
@override_settings(OIDC_CLIENT_MODEL='tests.CustomClient')
22+
@override_settings(OIDC_CLIENT_MODEL='tests.Client')
2523
class TestCustomClientModel(TestCase):
2624

27-
@skip(django.VERSION <= (1, 7))
2825
def test_custom_client_model(self):
2926
"""
3027
If a custom client model is installed, it should be present in
@@ -34,12 +31,12 @@ def test_custom_client_model(self):
3431
f.name for f in UserModel._meta.get_fields()
3532
if (f.one_to_many or f.one_to_one) and f.auto_created and not f.concrete
3633
]
37-
self.assertIn("tests_customclient_set", related_object_names)
34+
self.assertIn("tests_client_set", related_object_names)
3835

3936
@override_settings(OIDC_CLIENT_MODEL='IncorrectModelFormat')
40-
def test_custom_application_model_incorrect_format(self):
37+
def test_custom_application_model_incorrect_format_1(self):
4138
self.assertRaises(ValueError, get_client_model)
4239

4340
@override_settings(OIDC_CLIENT_MODEL='tests.ClientNotInstalled')
44-
def test_custom_application_model_incorrect_format(self):
41+
def test_custom_application_model_incorrect_format_2(self):
4542
self.assertRaises(LookupError, get_client_model)

oidc_provider/tests/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
from oidc_provider.models import AbstractClient
44

55

6-
class CustomClient(AbstractClient):
6+
class Client(AbstractClient):
77
custom_field = models.CharField(max_length=255)

oidc_provider/tests/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
'django.contrib.messages',
4848
'django.contrib.admin',
4949
'oidc_provider',
50+
'oidc_provider.tests',
5051
]
5152

5253
ROOT_URLCONF = 'oidc_provider.tests.app.urls'

0 commit comments

Comments
 (0)