2014-01-13 05:28:19 +04:00
|
|
|
from django.db import models
|
|
|
|
from django.test import TestCase
|
|
|
|
|
2014-01-13 20:47:44 +04:00
|
|
|
from rest_framework.serializers import _resolve_model
|
2014-03-02 15:40:30 +04:00
|
|
|
from tests.models import BasicModel
|
2014-05-22 23:51:20 +04:00
|
|
|
from rest_framework.compat import six
|
2014-01-13 05:28:19 +04:00
|
|
|
|
|
|
|
|
|
|
|
class ResolveModelTests(TestCase):
|
|
|
|
"""
|
2014-01-13 20:47:44 +04:00
|
|
|
`_resolve_model` should return a Django model class given the
|
2014-01-13 05:28:19 +04:00
|
|
|
provided argument is a Django model class itself, or a properly
|
|
|
|
formatted string representation of one.
|
|
|
|
"""
|
|
|
|
def test_resolve_django_model(self):
|
2014-01-13 20:47:44 +04:00
|
|
|
resolved_model = _resolve_model(BasicModel)
|
2014-01-13 05:28:19 +04:00
|
|
|
self.assertEqual(resolved_model, BasicModel)
|
|
|
|
|
|
|
|
def test_resolve_string_representation(self):
|
2014-01-13 20:47:44 +04:00
|
|
|
resolved_model = _resolve_model('tests.BasicModel')
|
2014-01-13 05:28:19 +04:00
|
|
|
self.assertEqual(resolved_model, BasicModel)
|
|
|
|
|
2014-05-22 23:51:20 +04:00
|
|
|
def test_resolve_unicode_representation(self):
|
|
|
|
resolved_model = _resolve_model(six.text_type('tests.BasicModel'))
|
|
|
|
self.assertEqual(resolved_model, BasicModel)
|
|
|
|
|
2014-01-13 05:28:19 +04:00
|
|
|
def test_resolve_non_django_model(self):
|
|
|
|
with self.assertRaises(ValueError):
|
2014-01-13 20:47:44 +04:00
|
|
|
_resolve_model(TestCase)
|
2014-01-13 05:28:19 +04:00
|
|
|
|
2014-01-13 20:47:44 +04:00
|
|
|
def test_resolve_improper_string_representation(self):
|
2014-01-13 05:28:19 +04:00
|
|
|
with self.assertRaises(ValueError):
|
2014-01-13 20:47:44 +04:00
|
|
|
_resolve_model('BasicModel')
|