mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
Test rejigging
This commit is contained in:
parent
c0150e619c
commit
b361c54c5c
|
@ -24,6 +24,9 @@ class CustomField(models.Field):
|
|||
pass
|
||||
|
||||
|
||||
COLOR_CHOICES = (('red', 'Red'), ('blue', 'Blue'), ('green', 'Green'))
|
||||
|
||||
|
||||
class RegularFieldsModel(models.Model):
|
||||
"""
|
||||
A model class for testing regular flat fields.
|
||||
|
@ -32,6 +35,7 @@ class RegularFieldsModel(models.Model):
|
|||
big_integer_field = models.BigIntegerField()
|
||||
boolean_field = models.BooleanField(default=False)
|
||||
char_field = models.CharField(max_length=100)
|
||||
choices_field = models.CharField(max_length=100, choices=COLOR_CHOICES)
|
||||
comma_seperated_integer_field = models.CommaSeparatedIntegerField(max_length=100)
|
||||
date_field = models.DateField()
|
||||
datetime_field = models.DateTimeField()
|
||||
|
@ -68,6 +72,7 @@ class TestRegularFieldMappings(TestCase):
|
|||
big_integer_field = IntegerField()
|
||||
boolean_field = BooleanField(default=False)
|
||||
char_field = CharField(max_length=100)
|
||||
choices_field = ChoiceField(choices=[('red', 'Red'), ('blue', 'Blue'), ('green', 'Green')])
|
||||
comma_seperated_integer_field = CharField(max_length=100, validators=[<django.core.validators.RegexValidator object>])
|
||||
date_field = DateField()
|
||||
datetime_field = DateTimeField()
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
from django.test import TestCase
|
||||
from django.utils import six
|
||||
from rest_framework.utils.model_meta import _resolve_model
|
||||
from tests.models import BasicModel
|
||||
|
||||
|
||||
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)
|
||||
|
||||
def test_resolve_string_representation(self):
|
||||
resolved_model = _resolve_model('tests.BasicModel')
|
||||
self.assertEqual(resolved_model, BasicModel)
|
||||
|
||||
def test_resolve_unicode_representation(self):
|
||||
resolved_model = _resolve_model(six.text_type('tests.BasicModel'))
|
||||
self.assertEqual(resolved_model, BasicModel)
|
||||
|
||||
def test_resolve_non_django_model(self):
|
||||
with self.assertRaises(ValueError):
|
||||
_resolve_model(TestCase)
|
||||
|
||||
def test_resolve_improper_string_representation(self):
|
||||
with self.assertRaises(ValueError):
|
||||
_resolve_model('BasicModel')
|
|
@ -4,6 +4,7 @@ from django.test import TestCase
|
|||
from rest_framework.test import APIRequestFactory
|
||||
from rest_framework.templatetags.rest_framework import add_query_param, urlize_quoted_links
|
||||
|
||||
|
||||
factory = APIRequestFactory()
|
||||
|
||||
|
||||
|
@ -49,3 +50,37 @@ class Issue1386Tests(TestCase):
|
|||
|
||||
# example from issue #1386, this shouldn't raise an exception
|
||||
urlize_quoted_links("asdf:[/p]zxcv.com")
|
||||
|
||||
|
||||
class URLizerTests(TestCase):
|
||||
"""
|
||||
Test if both JSON and YAML URLs are transformed into links well
|
||||
"""
|
||||
def _urlize_dict_check(self, data):
|
||||
"""
|
||||
For all items in dict test assert that the value is urlized key
|
||||
"""
|
||||
for original, urlized in data.items():
|
||||
assert urlize_quoted_links(original, nofollow=False) == urlized
|
||||
|
||||
def test_json_with_url(self):
|
||||
"""
|
||||
Test if JSON URLs are transformed into links well
|
||||
"""
|
||||
data = {}
|
||||
data['"url": "http://api/users/1/", '] = \
|
||||
'"url": "<a href="http://api/users/1/">http://api/users/1/</a>", '
|
||||
data['"foo_set": [\n "http://api/foos/1/"\n], '] = \
|
||||
'"foo_set": [\n "<a href="http://api/foos/1/">http://api/foos/1/</a>"\n], '
|
||||
self._urlize_dict_check(data)
|
||||
|
||||
def test_yaml_with_url(self):
|
||||
"""
|
||||
Test if YAML URLs are transformed into links well
|
||||
"""
|
||||
data = {}
|
||||
data['''{users: 'http://api/users/'}'''] = \
|
||||
'''{users: '<a href="http://api/users/">http://api/users/</a>'}'''
|
||||
data['''foo_set: ['http://api/foos/1/']'''] = \
|
||||
'''foo_set: ['<a href="http://api/foos/1/">http://api/foos/1/</a>']'''
|
||||
self._urlize_dict_check(data)
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
from __future__ import unicode_literals
|
||||
from django.test import TestCase
|
||||
from rest_framework.templatetags.rest_framework import urlize_quoted_links
|
||||
|
||||
|
||||
class URLizerTests(TestCase):
|
||||
"""
|
||||
Test if both JSON and YAML URLs are transformed into links well
|
||||
"""
|
||||
def _urlize_dict_check(self, data):
|
||||
"""
|
||||
For all items in dict test assert that the value is urlized key
|
||||
"""
|
||||
for original, urlized in data.items():
|
||||
assert urlize_quoted_links(original, nofollow=False) == urlized
|
||||
|
||||
def test_json_with_url(self):
|
||||
"""
|
||||
Test if JSON URLs are transformed into links well
|
||||
"""
|
||||
data = {}
|
||||
data['"url": "http://api/users/1/", '] = \
|
||||
'"url": "<a href="http://api/users/1/">http://api/users/1/</a>", '
|
||||
data['"foo_set": [\n "http://api/foos/1/"\n], '] = \
|
||||
'"foo_set": [\n "<a href="http://api/foos/1/">http://api/foos/1/</a>"\n], '
|
||||
self._urlize_dict_check(data)
|
||||
|
||||
def test_yaml_with_url(self):
|
||||
"""
|
||||
Test if YAML URLs are transformed into links well
|
||||
"""
|
||||
data = {}
|
||||
data['''{users: 'http://api/users/'}'''] = \
|
||||
'''{users: '<a href="http://api/users/">http://api/users/</a>'}'''
|
||||
data['''foo_set: ['http://api/foos/1/']'''] = \
|
||||
'''foo_set: ['<a href="http://api/foos/1/">http://api/foos/1/</a>']'''
|
||||
self._urlize_dict_check(data)
|
|
@ -1,8 +1,11 @@
|
|||
from __future__ import unicode_literals
|
||||
from django.conf.urls import patterns, url
|
||||
from django.test import TestCase
|
||||
from django.utils import six
|
||||
from rest_framework.utils.model_meta import _resolve_model
|
||||
from rest_framework.utils.breadcrumbs import get_breadcrumbs
|
||||
from rest_framework.views import APIView
|
||||
from tests.models import BasicModel
|
||||
|
||||
|
||||
class Root(APIView):
|
||||
|
@ -24,6 +27,7 @@ class NestedResourceRoot(APIView):
|
|||
class NestedResourceInstance(APIView):
|
||||
pass
|
||||
|
||||
|
||||
urlpatterns = patterns(
|
||||
'',
|
||||
url(r'^$', Root.as_view()),
|
||||
|
@ -35,9 +39,10 @@ urlpatterns = patterns(
|
|||
|
||||
|
||||
class BreadcrumbTests(TestCase):
|
||||
"""Tests the breadcrumb functionality used by the HTML renderer."""
|
||||
|
||||
urls = 'tests.test_breadcrumbs'
|
||||
"""
|
||||
Tests the breadcrumb functionality used by the HTML renderer.
|
||||
"""
|
||||
urls = 'tests.test_utils'
|
||||
|
||||
def test_root_breadcrumbs(self):
|
||||
url = '/'
|
||||
|
@ -98,3 +103,30 @@ class BreadcrumbTests(TestCase):
|
|||
get_breadcrumbs(url),
|
||||
[('Root', '/')]
|
||||
)
|
||||
|
||||
|
||||
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)
|
||||
|
||||
def test_resolve_string_representation(self):
|
||||
resolved_model = _resolve_model('tests.BasicModel')
|
||||
self.assertEqual(resolved_model, BasicModel)
|
||||
|
||||
def test_resolve_unicode_representation(self):
|
||||
resolved_model = _resolve_model(six.text_type('tests.BasicModel'))
|
||||
self.assertEqual(resolved_model, BasicModel)
|
||||
|
||||
def test_resolve_non_django_model(self):
|
||||
with self.assertRaises(ValueError):
|
||||
_resolve_model(TestCase)
|
||||
|
||||
def test_resolve_improper_string_representation(self):
|
||||
with self.assertRaises(ValueError):
|
||||
_resolve_model('BasicModel')
|
Loading…
Reference in New Issue
Block a user