diff options
| author | Tom Christie | 2014-11-28 15:31:51 +0000 |
|---|---|---|
| committer | Tom Christie | 2014-11-28 15:31:51 +0000 |
| commit | 6fbd23ab346e1a5b5401ba83e2ad2cd3474d2410 (patch) | |
| tree | 23b9d19d212ed67ef7c825b01ae2627d8dfaa630 /tests/test_utils.py | |
| parent | 8d989bb16dcc2f035ccc42710ca2714912a2ec40 (diff) | |
| parent | 67735687b297e66c7cfe61614040efcd9763f1f1 (diff) | |
| download | django-rest-framework-6fbd23ab346e1a5b5401ba83e2ad2cd3474d2410.tar.bz2 | |
Merge pull request #2086 from beck/doug/blow-up-with-bad-models
Ensure _resolve_model does not return None
Diffstat (limited to 'tests/test_utils.py')
| -rw-r--r-- | tests/test_utils.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/test_utils.py b/tests/test_utils.py index 96c5f997..0bdb36bb 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -7,6 +7,8 @@ from rest_framework.utils.breadcrumbs import get_breadcrumbs from rest_framework.views import APIView from tests.models import BasicModel +import rest_framework.utils.model_meta + class Root(APIView): pass @@ -130,3 +132,34 @@ class ResolveModelTests(TestCase): def test_resolve_improper_string_representation(self): with self.assertRaises(ValueError): _resolve_model('BasicModel') + + +class ResolveModelWithPatchedDjangoTests(TestCase): + """ + Test coverage for when Django's `get_model` returns `None`. + + Under certain circumstances Django may return `None` with `get_model`: + http://git.io/get-model-source + + It usually happens with circular imports so it is important that DRF + excepts early, otherwise fault happens downstream and is much more + difficult to debug. + + """ + + def setUp(self): + """Monkeypatch get_model.""" + self.get_model = rest_framework.utils.model_meta.models.get_model + + def get_model(app_label, model_name): + return None + + rest_framework.utils.model_meta.models.get_model = get_model + + def tearDown(self): + """Revert monkeypatching.""" + rest_framework.utils.model_meta.models.get_model = self.get_model + + def test_blows_up_if_model_does_not_resolve(self): + with self.assertRaises(ValueError): + _resolve_model('tests.BasicModel') |
