mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-29 17:39:48 +03:00
Test init for fields w/ lazy translations
This commit is contained in:
parent
1b8141a4aa
commit
9ec2963be0
|
@ -1 +1,16 @@
|
||||||
from rest_framework import compat # noqa
|
"""
|
||||||
|
This test "app" exists to ensure that parts of Django REST Framework can be
|
||||||
|
imported/invoked before Django itself has been fully initialized.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from rest_framework import compat, serializers # noqa
|
||||||
|
|
||||||
|
|
||||||
|
# test initializing fields with lazy translations
|
||||||
|
class ExampleSerializer(serializers.Serializer):
|
||||||
|
charfield = serializers.CharField(min_length=1, max_length=2)
|
||||||
|
integerfield = serializers.IntegerField(min_value=1, max_value=2)
|
||||||
|
floatfield = serializers.FloatField(min_value=1, max_value=2)
|
||||||
|
decimalfield = serializers.DecimalField(max_digits=10, decimal_places=1, min_value=1, max_value=2)
|
||||||
|
durationfield = serializers.DurationField(min_value=1, max_value=2)
|
||||||
|
listfield = serializers.ListField(min_length=1, max_length=2)
|
||||||
|
|
|
@ -4,10 +4,21 @@ from tests import importable
|
||||||
|
|
||||||
|
|
||||||
def test_installed():
|
def test_installed():
|
||||||
# ensure that apps can freely import rest_framework.compat
|
# ensure the test app hasn't been removed from the test suite
|
||||||
assert 'tests.importable' in settings.INSTALLED_APPS
|
assert 'tests.importable' in settings.INSTALLED_APPS
|
||||||
|
|
||||||
|
|
||||||
def test_imported():
|
def test_compat():
|
||||||
# ensure that the __init__ hasn't been mucked with
|
|
||||||
assert hasattr(importable, 'compat')
|
assert hasattr(importable, 'compat')
|
||||||
|
|
||||||
|
|
||||||
|
def test_serializer_fields_initialization():
|
||||||
|
assert hasattr(importable, 'ExampleSerializer')
|
||||||
|
|
||||||
|
serializer = importable.ExampleSerializer()
|
||||||
|
assert 'charfield' in serializer.fields
|
||||||
|
assert 'integerfield' in serializer.fields
|
||||||
|
assert 'floatfield' in serializer.fields
|
||||||
|
assert 'decimalfield' in serializer.fields
|
||||||
|
assert 'durationfield' in serializer.fields
|
||||||
|
assert 'listfield' in serializer.fields
|
||||||
|
|
Loading…
Reference in New Issue
Block a user