Skip to content

Commit 4ff64b8

Browse files
author
Aristobulo Meneses
committed
Add test cases to validate proper model names and that models are installed
1 parent eea3928 commit 4ff64b8

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

tests/test_models.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,16 @@ def test_custom_application_model_incorrect_format(self):
149149
# Patch oauth2 settings to use a custom Application model
150150
oauth2_settings.APPLICATION_MODEL = "IncorrectApplicationFormat"
151151

152-
self.assertRaises(ImproperlyConfigured, get_application_model)
152+
self.assertRaises(ValueError, get_application_model)
153+
154+
# Revert oauth2 settings
155+
oauth2_settings.APPLICATION_MODEL = 'oauth2_provider.Application'
156+
157+
def test_custom_application_model_not_installed(self):
158+
# Patch oauth2 settings to use a custom Application model
159+
oauth2_settings.APPLICATION_MODEL = "tests.ApplicationNotInstalled"
160+
161+
self.assertRaises(LookupError, get_application_model)
153162

154163
# Revert oauth2 settings
155164
oauth2_settings.APPLICATION_MODEL = 'oauth2_provider.Application'
@@ -176,7 +185,16 @@ def test_custom_access_token_model_incorrect_format(self):
176185
# Patch oauth2 settings to use a custom AccessToken model
177186
oauth2_settings.ACCESS_TOKEN_MODEL = "IncorrectAccessTokenFormat"
178187

179-
self.assertRaises(ImproperlyConfigured, get_access_token_model)
188+
self.assertRaises(ValueError, get_access_token_model)
189+
190+
# Revert oauth2 settings
191+
oauth2_settings.ACCESS_TOKEN_MODEL = 'oauth2_provider.AccessToken'
192+
193+
def test_custom_access_token_model_not_installed(self):
194+
# Patch oauth2 settings to use a custom AccessToken model
195+
oauth2_settings.ACCESS_TOKEN_MODEL = "tests.AccessTokenNotInstalled"
196+
197+
self.assertRaises(LookupError, get_access_token_model)
180198

181199
# Revert oauth2 settings
182200
oauth2_settings.ACCESS_TOKEN_MODEL = 'oauth2_provider.AccessToken'
@@ -203,7 +221,16 @@ def test_custom_refresh_token_model_incorrect_format(self):
203221
# Patch oauth2 settings to use a custom RefreshToken model
204222
oauth2_settings.REFRESH_TOKEN_MODEL = "IncorrectRefreshTokenFormat"
205223

206-
self.assertRaises(ImproperlyConfigured, get_refresh_token_model)
224+
self.assertRaises(ValueError, get_refresh_token_model)
225+
226+
# Revert oauth2 settings
227+
oauth2_settings.REFRESH_TOKEN_MODEL = 'oauth2_provider.RefreshToken'
228+
229+
def test_custom_refresh_token_model_not_installed(self):
230+
# Patch oauth2 settings to use a custom AccessToken model
231+
oauth2_settings.REFRESH_TOKEN_MODEL = "tests.RefreshTokenNotInstalled"
232+
233+
self.assertRaises(LookupError, get_refresh_token_model)
207234

208235
# Revert oauth2 settings
209236
oauth2_settings.REFRESH_TOKEN_MODEL = 'oauth2_provider.RefreshToken'
@@ -230,7 +257,16 @@ def test_custom_grant_model_incorrect_format(self):
230257
# Patch oauth2 settings to use a custom Grant model
231258
oauth2_settings.GRANT_MODEL = "IncorrectGrantFormat"
232259

233-
self.assertRaises(ImproperlyConfigured, get_grant_model)
260+
self.assertRaises(ValueError, get_grant_model)
261+
262+
# Revert oauth2 settings
263+
oauth2_settings.GRANT_MODEL = 'oauth2_provider.Grant'
264+
265+
def test_custom_grant_model_not_installed(self):
266+
# Patch oauth2 settings to use a custom AccessToken model
267+
oauth2_settings.GRANT_MODEL = "tests.GrantNotInstalled"
268+
269+
self.assertRaises(LookupError, get_grant_model)
234270

235271
# Revert oauth2 settings
236272
oauth2_settings.GRANT_MODEL = 'oauth2_provider.Grant'

0 commit comments

Comments
 (0)