예제 #1
0
def test_valid_json_field():
    field = JSONSchemaField(schema=schema)
    assert field.to_internal_value({
        'a': 'foo',
        'b': 3.1
    }) == {
        'a': 'foo',
        'b': 3.1
    }
예제 #2
0
 class TestSerializer(serializers.Serializer):
     json = JSONSchemaField(schema=schema)
예제 #3
0
def test_json_field_invalid_format_check_but_format_checking_disabled():
    field = JSONSchemaField(schema=format_schema, format_checker=None)
    assert field.to_internal_value({'a': 'noemail'}) == {'a': 'noemail'}
예제 #4
0
def test_json_field_invalid_format_check():
    field = JSONSchemaField(schema=format_schema)
    with pytest.raises(serializers.ValidationError) as e:
        field.run_validation({'a': 'noemail'})
    assert e.value.detail == ["'noemail' is not a 'email'"]
예제 #5
0
def test_json_field_valid_format_check():
    field = JSONSchemaField(schema=format_schema)
    assert field.to_internal_value({'a': '*****@*****.**'}) == {
        'a': '*****@*****.**'
    }
예제 #6
0
def test_invalid_json_field():
    field = JSONSchemaField(schema=schema)
    with pytest.raises(serializers.ValidationError) as e:
        field.run_validation({'a': 'foo', 'b': 'nonumber'})
    assert e.value.detail == ["'nonumber' is not of type 'number'"]