• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LeanderCS / flask-inputfilter / #420

02 Jul 2025 08:10PM UTC coverage: 94.487% (-1.3%) from 95.792%
#420

push

coveralls-python

web-flow
Merge pull request #60 from LeanderCS/optimize

Optimize

292 of 328 new or added lines in 108 files covered. (89.02%)

10 existing lines in 2 files now uncovered.

1868 of 1977 relevant lines covered (94.49%)

0.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.33
/flask_inputfilter/validators/date_before_validator.py
1
from __future__ import annotations
1✔
2

3
from typing import TYPE_CHECKING, Any, Optional, Union
1✔
4

5
from flask_inputfilter.exceptions import ValidationError
1✔
6
from flask_inputfilter.helpers import parse_date
1✔
7
from flask_inputfilter.models import BaseValidator
1✔
8

9
if TYPE_CHECKING:
1✔
NEW
10
    from datetime import date, datetime
×
11

12

13
class DateBeforeValidator(BaseValidator):
1✔
14
    """
15
    Validates that a given date is before a specified reference date. It
16
    supports datetime objects and ISO 8601 formatted strings.
17

18
    **Parameters:**
19

20
    - **reference_date** (*Union[str, date, datetime]*): The date that the
21
      input must be earlier than.
22
    - **error_message** (*Optional[str]*): Custom error message if validation
23
      fails.
24

25
    **Expected Behavior:**
26

27
    Parses the input and reference date into datetime objects and checks that
28
    the input date is earlier. Raises a ``ValidationError`` on failure.
29

30
    **Example Usage:**
31

32
    .. code-block:: python
33

34
        class RegistrationInputFilter(InputFilter):
35
            def __init__(self):
36
                super().__init__()
37

38
                self.add('birth_date', validators=[
39
                    DateBeforeValidator(reference_date="2005-01-01")
40
                ])
41
    """
42

43
    __slots__ = ("error_message", "reference_date")
1✔
44

45
    def __init__(
1✔
46
        self,
47
        reference_date: Union[str, date, datetime],
48
        error_message: Optional[str] = None,
49
    ) -> None:
50
        self.reference_date = parse_date(reference_date)
1✔
51
        self.error_message = error_message
1✔
52

53
    def validate(self, value: Any) -> None:
1✔
54
        if parse_date(value) >= self.reference_date:
1✔
55
            raise ValidationError(
1✔
56
                self.error_message
57
                or f"Date '{value}' is not before '{self.reference_date}'."
58
            )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc