31 lines
957 B
Python
31 lines
957 B
Python
"""Tests for weekends route query validation."""
|
|
|
|
from datetime import date
|
|
import typing
|
|
|
|
import pytest
|
|
|
|
import web_view
|
|
|
|
|
|
@pytest.fixture # type: ignore[untyped-decorator]
|
|
def client() -> typing.Any:
|
|
"""Flask test client."""
|
|
web_view.app.config["TESTING"] = True
|
|
with web_view.app.test_client() as c:
|
|
yield c
|
|
|
|
|
|
def test_weekends_rejects_year_before_2020(client: typing.Any) -> None:
|
|
"""Years before 2020 should return HTTP 400."""
|
|
response = client.get("/weekends?year=2019&week=1")
|
|
assert response.status_code == 400
|
|
assert b"Year must be between 2020" in response.data
|
|
|
|
|
|
def test_weekends_rejects_year_more_than_five_years_ahead(client: typing.Any) -> None:
|
|
"""Years beyond current year + 5 should return HTTP 400."""
|
|
too_far = date.today().year + 6
|
|
response = client.get(f"/weekends?year={too_far}&week=1")
|
|
assert response.status_code == 400
|
|
assert b"Year must be between 2020" in response.data
|