mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Changed get_model to raise an exception on errors.
Returning None on errors required unpythonic error checking and was inconsistent with get_app_config. get_model was a private API until the previous commit, but given that it was certainly used in third party software, the change is explained in the release notes. Applied the same change to get_registered_model, which is a new private API introduced during the recent refactoring.
This commit is contained in:
parent
54790e669d
commit
ba7206cd81
20 changed files with 80 additions and 53 deletions
|
@ -148,9 +148,11 @@ class AppsTests(TestCase):
|
|||
Tests that the models in the models.py file were loaded correctly.
|
||||
"""
|
||||
self.assertEqual(apps.get_model("apps", "TotallyNormal"), TotallyNormal)
|
||||
self.assertEqual(apps.get_model("apps", "SoAlternative"), None)
|
||||
with self.assertRaises(LookupError):
|
||||
apps.get_model("apps", "SoAlternative")
|
||||
|
||||
self.assertEqual(new_apps.get_model("apps", "TotallyNormal"), None)
|
||||
with self.assertRaises(LookupError):
|
||||
new_apps.get_model("apps", "TotallyNormal")
|
||||
self.assertEqual(new_apps.get_model("apps", "SoAlternative"), SoAlternative)
|
||||
|
||||
def test_dynamic_load(self):
|
||||
|
@ -174,4 +176,6 @@ class AppsTests(TestCase):
|
|||
old_models,
|
||||
apps.get_models(apps.get_app_config("apps").models_module),
|
||||
)
|
||||
with self.assertRaises(LookupError):
|
||||
apps.get_model("apps", "SouthPonies")
|
||||
self.assertEqual(new_apps.get_model("apps", "SouthPonies"), temp_model)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue