def test_incomplete_month_field():
    """Verify an incomplete error on the month field is saved in the widget."""
    field = DateInputField(require_all_fields=False)
    with pytest.raises(ValidationError) as err:
        field.clean(["11", "", "2007"])
    assert err.value.args[0][0] in field.fields[1].widget.errors
    assert err.value.args[0][0] == field.fields[1].error_messages["incomplete"]
def test_required_month_field():
    """Verify a parent field required error is not recorded on the month widget."""
    field = DateInputField()
    with pytest.raises(ValidationError) as err:
        field.clean(["11", "", "2007"])
    assert field.fields[1].widget.errors == []
    assert err.value.args[0] == field.error_messages["required"]
def test_invalid_month_field():
    """Verify a validation error on the month field is saved in the widget."""
    field = DateInputField()
    with pytest.raises(ValidationError) as err:
        field.clean(["11", "a", "2007"])
    error = err.value.args[0][0].args[0]
    assert error in field.fields[1].widget.errors
    assert error == field.fields[1].validators[0].message
def test_cleaned_valid_value():
    """Verify the Date input field returns a date object."""
    date = datetime.date(year=2007, month=12, day=11)
    field = DateInputField()
    value = field.clean([date.day, date.month, date.year])
    assert value == date
def test_clean_optional_fields_empty():
    """Verify clean returns None if the values are not required and not set."""
    field = DateInputField(required=False)
    field.require_all_fields = False
    value = field.clean(["", "", ""])
    assert value is None