django-rest-framework/tests/test_modelinfo.py

32 lines
1.1 KiB
Python
Raw Normal View History

2014-09-08 17:24:05 +04:00
from django.test import TestCase
from django.utils import six
2014-09-09 20:46:28 +04:00
from rest_framework.utils.modelinfo import _resolve_model
2014-09-08 17:24:05 +04:00
from tests.models import BasicModel
2014-09-08 17:24:05 +04:00
class ResolveModelTests(TestCase):
"""
`_resolve_model` should return a Django model class given the
provided argument is a Django model class itself, or a properly
formatted string representation of one.
"""
def test_resolve_django_model(self):
resolved_model = _resolve_model(BasicModel)
self.assertEqual(resolved_model, BasicModel)
2014-09-08 17:24:05 +04:00
def test_resolve_string_representation(self):
resolved_model = _resolve_model('tests.BasicModel')
self.assertEqual(resolved_model, BasicModel)
2014-09-08 17:24:05 +04:00
def test_resolve_unicode_representation(self):
resolved_model = _resolve_model(six.text_type('tests.BasicModel'))
self.assertEqual(resolved_model, BasicModel)
2014-09-08 17:24:05 +04:00
def test_resolve_non_django_model(self):
with self.assertRaises(ValueError):
_resolve_model(TestCase)
2014-09-08 17:24:05 +04:00
def test_resolve_improper_string_representation(self):
with self.assertRaises(ValueError):
_resolve_model('BasicModel')