system-pri/backend/tests/unit_tests/test_validators.py

33 lines
853 B
Python
Raw Normal View History

2023-01-04 22:51:58 +01:00
import datetime
import pytest
from marshmallow import ValidationError
from app.coordinator.validators import (
validate_datetime_greater_than_now,
validate_index,
)
2023-01-04 22:51:58 +01:00
def test_validate_index() -> None:
assert validate_index(123456) is None
def test_validate_index_with_invalid_value() -> None:
with pytest.raises(ValidationError):
validate_index(12345)
with pytest.raises(ValidationError):
validate_index(1234567)
def test_validate_datetime_greater_than_now() -> None:
d = datetime.datetime.now() + datetime.timedelta(days=2)
assert validate_datetime_greater_than_now(d) is None
def test_validate_datetime_greater_than_now_with_invalid_data() -> None:
d = datetime.datetime.now() - datetime.timedelta(days=2)
with pytest.raises(ValidationError):
validate_datetime_greater_than_now(d)