mirror of
				https://github.com/graphql-python/graphene-django.git
				synced 2025-11-04 18:08:01 +03:00 
			
		
		
		
	Update field converter tests
This commit is contained in:
		
							parent
							
								
									ee23638378
								
							
						
					
					
						commit
						81a6dff9d0
					
				| 
						 | 
					@ -8,7 +8,7 @@ from ..serializer_converter import convert_serializer_field
 | 
				
			||||||
from ..types import DictType
 | 
					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:
 | 
					    # prevents the following error:
 | 
				
			||||||
    # AssertionError: The `source` argument is not meaningful when applied to a `child=` field.
 | 
					    # AssertionError: The `source` argument is not meaningful when applied to a `child=` field.
 | 
				
			||||||
    # Remove `source=` from the field declaration.
 | 
					    # Remove `source=` from the field declaration.
 | 
				
			||||||
| 
						 | 
					@ -19,7 +19,7 @@ def _get_type(rest_framework_field, **kwargs):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    field = 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):
 | 
					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)
 | 
					    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():
 | 
					def test_should_char_convert_string():
 | 
				
			||||||
    assert_conversion(serializers.CharField, graphene.String)
 | 
					    assert_conversion(serializers.CharField, graphene.String)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -85,6 +73,28 @@ def test_should_uuid_convert_string():
 | 
				
			||||||
        assert_conversion(serializers.UUIDField, graphene.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():
 | 
					def test_should_integer_convert_int():
 | 
				
			||||||
    assert_conversion(serializers.IntegerField, graphene.Int)
 | 
					    assert_conversion(serializers.IntegerField, graphene.Int)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user