fix: accept none date end

dependabot/pip/requests-2.31.0
Pierre-Louis Guhur 1 year ago
parent b4988e58d3
commit 66ba888ad7

@ -125,7 +125,7 @@ class ElectionBase(BaseModel):
description: Description = ""
ref: Ref = ""
date_start: datetime = Field(default_factory=datetime.now)
date_end: datetime = Field(default_factory=_in_a_long_time)
date_end: datetime | None = Field(default_factory=_in_a_long_time)
hide_results: bool = True
restricted: bool = False

@ -58,7 +58,7 @@ class RandomElection(t.TypedDict):
restricted: t.NotRequired[bool]
hide_results: t.NotRequired[bool]
num_voters: t.NotRequired[int]
date_end: t.NotRequired[str]
date_end: t.NotRequired[str | None]
def _random_election(num_candidates: int, num_grades: int) -> RandomElection:
@ -91,6 +91,14 @@ def test_create_election():
req_grade_names = {c["name"] for c in body["grades"]}
assert db_grade_names == req_grade_names, db_grade_names
# Can create an election with a null date_end
body = _random_election(2, 2)
body["date_end"] = None
response = client.post("/elections", json=body)
assert response.status_code == 200, response.text
data = response.json()
assert data["name"] == body["name"]
def test_get_election():
body = _random_election(3, 4)

Loading…
Cancel
Save