Exemplo n.º 1
0
def test_field_errors():
    field = ListField(child=IntegerField())

    with pytest.raises(ValidationError) as e:
        field.to_internal_value(['123', 'foo'])

    assert e.value.errors == {1: ['A valid integer is required.']}
Exemplo n.º 2
0
def test_field_errors():
    field = ListField(child=IntegerField())

    with pytest.raises(ValidationError) as e:
        field.to_internal_value(['123', 'foo'])

    assert e.value.errors == {1: ['A valid integer is required.']}
Exemplo n.º 3
0
def test_string_field():
    field = ListField(child=StringField())

    assert field.to_internal_value(['foo', 'bar']) == ['foo', 'bar']

    with pytest.raises(ValidationError):
        field.to_internal_value('foo')
Exemplo n.º 4
0
def test_string_field():
    field = ListField(child=StringField())

    assert field.to_internal_value(['foo', 'bar']) == ['foo', 'bar']

    with pytest.raises(ValidationError):
        field.to_internal_value('foo')
Exemplo n.º 5
0
def test_none():
    i = ['2016-01-01', None, '2016-01-02']
    o = [date(2016, 1, 1), None, date(2016, 1, 2)]

    with pytest.raises(ValidationError):
        ListField(child=DateField(required=True)).to_internal_value(i)

    assert ListField(child=DateField(required=False)).to_internal_value(i) == o
Exemplo n.º 6
0
def test_serializer_errors():
    class FooSerializer(Serializer):
        foo = IntegerField()

    field = ListField(child=FooSerializer())

    with pytest.raises(ValidationError) as e:
        field.to_internal_value([{'foo': '123'}, {'foo': 'foo'}])

    assert e.value.errors == {1: {'foo': ['A valid integer is required.']}}
Exemplo n.º 7
0
def test_serializer_errors():
    class FooSerializer(Serializer):
        foo = IntegerField()

    field = ListField(child=FooSerializer())

    with pytest.raises(ValidationError) as e:
        field.to_internal_value([{'foo': '123'}, {'foo': 'foo'}])

    assert e.value.errors == {1: {'foo': ['A valid integer is required.']}}
Exemplo n.º 8
0
def test_default():
    field = ListField(required=False, child=IntegerField())

    # Default should be an empty list
    assert field.run_validation(empty) == []
    assert field.run_validation(None) == []
Exemplo n.º 9
0
def test_default():
    field = ListField(required=False, child=IntegerField())

    # Default should be an empty list
    assert field.run_validation(empty) == []
    assert field.run_validation(None) == []
Exemplo n.º 10
0
def test_to_internal_value_invalid(data):
    with pytest.raises(ValidationError):
        ListField(child=DateField()).to_internal_value(data)
Exemplo n.º 11
0
def test_to_internal_value(data, expected):
    assert ListField(child=DateField()).to_internal_value(data) == expected
Exemplo n.º 12
0
def test_to_representation(value, expected):
    assert ListField(child=DateField()).to_representation(value) == expected