2023-01-04 22:51:58 +01:00
|
|
|
import datetime
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
from marshmallow import ValidationError
|
|
|
|
|
2023-01-14 17:38:03 +01:00
|
|
|
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)
|