Skip to content

Commit f047748

Browse files
jdufresnePierre Chiquet
authored andcommitted
Remove unused compat._resolve_model() (encode#5733)
Last use removed in c674687.
1 parent b0d06a2 commit f047748

File tree

2 files changed

+0
-91
lines changed

2 files changed

+0
-91
lines changed

rest_framework/compat.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@
55

66
from __future__ import unicode_literals
77

8-
import inspect
9-
108
import django
11-
from django.apps import apps
129
from django.conf import settings
1310
from django.core import validators
14-
from django.core.exceptions import ImproperlyConfigured
15-
from django.db import models
1611
from django.utils import six
1712
from django.views.generic import View
1813

@@ -107,30 +102,6 @@ def distinct(queryset, base):
107102
return queryset.distinct()
108103

109104

110-
def _resolve_model(obj):
111-
"""
112-
Resolve supplied `obj` to a Django model class.
113-
114-
`obj` must be a Django model class itself, or a string
115-
representation of one. Useful in situations like GH #1225 where
116-
Django may not have resolved a string-based reference to a model in
117-
another model's foreign key definition.
118-
119-
String representations should have the format:
120-
'appname.ModelName'
121-
"""
122-
if isinstance(obj, six.string_types) and len(obj.split('.')) == 2:
123-
app_name, model_name = obj.split('.')
124-
resolved_model = apps.get_model(app_name, model_name)
125-
if resolved_model is None:
126-
msg = "Django did not return a model for {0}.{1}"
127-
raise ImproperlyConfigured(msg.format(app_name, model_name))
128-
return resolved_model
129-
elif inspect.isclass(obj) and issubclass(obj, models.Model):
130-
return obj
131-
raise ValueError("{0} is not a Django model".format(obj))
132-
133-
134105
# django.contrib.postgres requires psycopg2
135106
try:
136107
from django.contrib.postgres import fields as postgres_fields

tests/test_utils.py

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22
from __future__ import unicode_literals
33

44
from django.conf.urls import url
5-
from django.core.exceptions import ImproperlyConfigured
65
from django.test import TestCase, override_settings
7-
from django.utils import six
86

9-
import rest_framework.utils.model_meta
10-
from rest_framework.compat import _resolve_model
117
from rest_framework.routers import SimpleRouter
128
from rest_framework.serializers import ModelSerializer
139
from rest_framework.utils import json
@@ -124,64 +120,6 @@ def test_modelviewset_resource_instance_breadcrumbs(self):
124120
]
125121

126122

127-
class ResolveModelTests(TestCase):
128-
"""
129-
`_resolve_model` should return a Django model class given the
130-
provided argument is a Django model class itself, or a properly
131-
formatted string representation of one.
132-
"""
133-
def test_resolve_django_model(self):
134-
resolved_model = _resolve_model(BasicModel)
135-
assert resolved_model == BasicModel
136-
137-
def test_resolve_string_representation(self):
138-
resolved_model = _resolve_model('tests.BasicModel')
139-
assert resolved_model == BasicModel
140-
141-
def test_resolve_unicode_representation(self):
142-
resolved_model = _resolve_model(six.text_type('tests.BasicModel'))
143-
assert resolved_model == BasicModel
144-
145-
def test_resolve_non_django_model(self):
146-
with self.assertRaises(ValueError):
147-
_resolve_model(TestCase)
148-
149-
def test_resolve_improper_string_representation(self):
150-
with self.assertRaises(ValueError):
151-
_resolve_model('BasicModel')
152-
153-
154-
class ResolveModelWithPatchedDjangoTests(TestCase):
155-
"""
156-
Test coverage for when Django's `get_model` returns `None`.
157-
158-
Under certain circumstances Django may return `None` with `get_model`:
159-
http://git.io/get-model-source
160-
161-
It usually happens with circular imports so it is important that DRF
162-
excepts early, otherwise fault happens downstream and is much more
163-
difficult to debug.
164-
165-
"""
166-
167-
def setUp(self):
168-
"""Monkeypatch get_model."""
169-
self.get_model = rest_framework.compat.apps.get_model
170-
171-
def get_model(app_label, model_name):
172-
return None
173-
174-
rest_framework.compat.apps.get_model = get_model
175-
176-
def tearDown(self):
177-
"""Revert monkeypatching."""
178-
rest_framework.compat.apps.get_model = self.get_model
179-
180-
def test_blows_up_if_model_does_not_resolve(self):
181-
with self.assertRaises(ImproperlyConfigured):
182-
_resolve_model('tests.BasicModel')
183-
184-
185123
class JsonFloatTests(TestCase):
186124
"""
187125
Internaly, wrapped json functions should adhere to strict float handling

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy