Skip to content

Commit 81a6dff

Browse files
author
Jacob Foster
committed
Update field converter tests
1 parent ee23638 commit 81a6dff

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

graphene_django/rest_framework/tests/test_field_converter.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from ..types import DictType
99

1010

11-
def _get_type(rest_framework_field, **kwargs):
11+
def _get_type(rest_framework_field, is_input=True, **kwargs):
1212
# prevents the following error:
1313
# AssertionError: The `source` argument is not meaningful when applied to a `child=` field.
1414
# Remove `source=` from the field declaration.
@@ -19,7 +19,7 @@ def _get_type(rest_framework_field, **kwargs):
1919

2020
field = rest_framework_field(**kwargs)
2121

22-
return convert_serializer_field(field)
22+
return convert_serializer_field(field, is_input=is_input)
2323

2424

2525
def assert_conversion(rest_framework_field, graphene_field, **kwargs):
@@ -40,18 +40,6 @@ def test_should_unknown_rest_framework_field_raise_exception():
4040
assert 'Don\'t know how to convert the serializer field' in str(excinfo.value)
4141

4242

43-
def test_should_date_convert_string():
44-
assert_conversion(serializers.DateField, graphene.String)
45-
46-
47-
def test_should_time_convert_string():
48-
assert_conversion(serializers.TimeField, graphene.String)
49-
50-
51-
def test_should_date_time_convert_string():
52-
assert_conversion(serializers.DateTimeField, graphene.String)
53-
54-
5543
def test_should_char_convert_string():
5644
assert_conversion(serializers.CharField, graphene.String)
5745

@@ -85,6 +73,28 @@ def test_should_uuid_convert_string():
8573
assert_conversion(serializers.UUIDField, graphene.String)
8674

8775

76+
def test_should_model_convert_field():
77+
78+
class MyModelSerializer(serializers.ModelSerializer):
79+
class Meta:
80+
model = None
81+
fields = '__all__'
82+
83+
assert_conversion(MyModelSerializer, graphene.Field, is_input=False)
84+
85+
86+
def test_should_date_time_convert_datetime():
87+
assert_conversion(serializers.DateTimeField, graphene.types.datetime.DateTime)
88+
89+
90+
def test_should_date_convert_datetime():
91+
assert_conversion(serializers.DateField, graphene.types.datetime.DateTime)
92+
93+
94+
def test_should_time_convert_time():
95+
assert_conversion(serializers.TimeField, graphene.types.datetime.Time)
96+
97+
8898
def test_should_integer_convert_int():
8999
assert_conversion(serializers.IntegerField, graphene.Int)
90100

0 commit comments

Comments
 (0)