def test_validate_non_dict():
    """
    When a DictField is given a non-dict value, then validate should raise a ValidationError.
    """
    field = DictField(child=DateField())
    with pytest.raises(ValidationError):
        field.to_internal_value('notADict')
Пример #2
0
def test_validate_non_dict():
    """
    When a DictField is given a non-dict value, then validate should raise a ValidationError.
    """
    field = DictField(child=DateField())
    with pytest.raises(ValidationError):
        field.to_internal_value('notADict')
def test_validate_elements_invalid():
    """
    When a DictField is given a dict containing values that are invalid for the value-field, then
    validate should raise a ValidationError.
    """
    field = DictField(child=CharField(max_length=5))
    with pytest.raises(ValidationError):
        field.to_internal_value({"a": "012345", "b": "012345"})
Пример #4
0
def test_validate_elements_invalid():
    """
    When a DictField is given a dict containing values that are invalid for the value-field, then
    validate should raise a ValidationError.
    """
    field = DictField(child=CharField(max_length=5))
    with pytest.raises(ValidationError):
        field.to_internal_value({"a": "012345", "b": "012345"})
def test_validate_elements_valid():
    """
    When a DictField is given a dict whose values are valid for the value-field, then validate
    should not raise a ValidationError.
    """
    field = DictField(child=CharField(max_length=5))
    try:
        field.to_internal_value({"a": "a", "b": "b", "c": "c"})
    except ValidationError:
        assert False, "ValidationError was raised"
Пример #6
0
def test_validate_elements_valid():
    """
    When a DictField is given a dict whose values are valid for the value-field, then validate
    should not raise a ValidationError.
    """
    field = DictField(child=CharField(max_length=5))
    try:
        field.to_internal_value({"a": "a", "b": "b", "c": "c"})
    except ValidationError:
        assert False, "ValidationError was raised"
def test_to_internal_value_with_child():
    """
    When a DictField has an value-field, to_internal_value should return a dict of elements resulting
    from the application of the value-field's to_internal_value method to each value of the input
    data dict.
    """
    field = DictField(child=DateField())
    data = {"a": "2000-01-01", "b": "2000-01-02"}
    obj = field.to_internal_value(data)
    assert {"a": date(2000, 1, 1), "b": date(2000, 1, 2)} == obj
Пример #8
0
def test_to_internal_value_with_child():
    """
    When a DictField has an value-field, to_internal_value should return a dict of elements resulting
    from the application of the value-field's to_internal_value method to each value of the input
    data dict.
    """
    field = DictField(child=DateField())
    data = {"a": "2000-01-01", "b": "2000-01-02"}
    obj = field.to_internal_value(data)
    assert {"a": date(2000, 1, 1), "b": date(2000, 1, 2)} == obj