def test_compress_invalid_fields(): """Verify compress raises an error on an invalid date.""" day = 30 month = 2 year = 2021 field = DateInputField() with pytest.raises(ValidationError) as err: field.compress([day, month, year]) assert err.value.args[0] == "day is out of range for month"
def test_compress_optional_fields_empty(): """Verify compress returns None if the values are not required and not set.""" field = DateInputField() field.require_all_fields = False value = field.compress(["", "", ""]) assert value is None
def test_compress_valid_fields(): """Verify compress returns a date.""" date = datetime.date(year=2007, month=12, day=11) field = DateInputField() value = field.compress([date.day, date.month, date.year]) assert value == date