From 81a6dff9d07fe6008c1df40a7b031e7ac69e02bb Mon Sep 17 00:00:00 2001 From: Jacob Foster Date: Tue, 18 Jul 2017 08:46:36 -0500 Subject: [PATCH] Update field converter tests --- .../tests/test_field_converter.py | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/graphene_django/rest_framework/tests/test_field_converter.py b/graphene_django/rest_framework/tests/test_field_converter.py index 2248b6f..623cf58 100644 --- a/graphene_django/rest_framework/tests/test_field_converter.py +++ b/graphene_django/rest_framework/tests/test_field_converter.py @@ -8,7 +8,7 @@ from ..serializer_converter import convert_serializer_field from ..types import DictType -def _get_type(rest_framework_field, **kwargs): +def _get_type(rest_framework_field, is_input=True, **kwargs): # prevents the following error: # AssertionError: The `source` argument is not meaningful when applied to a `child=` field. # Remove `source=` from the field declaration. @@ -19,7 +19,7 @@ def _get_type(rest_framework_field, **kwargs): field = rest_framework_field(**kwargs) - return convert_serializer_field(field) + return convert_serializer_field(field, is_input=is_input) def assert_conversion(rest_framework_field, graphene_field, **kwargs): @@ -40,18 +40,6 @@ def test_should_unknown_rest_framework_field_raise_exception(): assert 'Don\'t know how to convert the serializer field' in str(excinfo.value) -def test_should_date_convert_string(): - assert_conversion(serializers.DateField, graphene.String) - - -def test_should_time_convert_string(): - assert_conversion(serializers.TimeField, graphene.String) - - -def test_should_date_time_convert_string(): - assert_conversion(serializers.DateTimeField, graphene.String) - - def test_should_char_convert_string(): assert_conversion(serializers.CharField, graphene.String) @@ -85,6 +73,28 @@ def test_should_uuid_convert_string(): assert_conversion(serializers.UUIDField, graphene.String) +def test_should_model_convert_field(): + + class MyModelSerializer(serializers.ModelSerializer): + class Meta: + model = None + fields = '__all__' + + assert_conversion(MyModelSerializer, graphene.Field, is_input=False) + + +def test_should_date_time_convert_datetime(): + assert_conversion(serializers.DateTimeField, graphene.types.datetime.DateTime) + + +def test_should_date_convert_datetime(): + assert_conversion(serializers.DateField, graphene.types.datetime.DateTime) + + +def test_should_time_convert_time(): + assert_conversion(serializers.TimeField, graphene.types.datetime.Time) + + def test_should_integer_convert_int(): assert_conversion(serializers.IntegerField, graphene.Int)