diff --git a/planty/application/tests/test_endpoints.py b/planty/application/tests/test_endpoints.py index 2bff916..576eb8d 100644 --- a/planty/application/tests/test_endpoints.py +++ b/planty/application/tests/test_endpoints.py @@ -118,6 +118,7 @@ async def test_get_archived_tasks( "parent_id, status_code, error_detail", [ ("0d966845-254b-4b5c-b8a7-8d34dcd3d527", 201, None), + ("45561eb6-3570-44de-af8a-54212e2981e6", 201, None), ( "090eda97-dd2d-45bb-baa0-7814313e5a38", 422, @@ -132,18 +133,21 @@ async def test_create_section( ac: AsyncClient, additional_test_data: dict[str, Any], ) -> None: - section_data = { - "title": str(additional_test_data["sections"][0]["title"]), - "parent_id": parent_id, - } - response = await ac.post("/api/section", json=section_data) - assert response.status_code == status_code - if not response.is_success: - assert response.json()["detail"] == error_detail - return + # Do it twice to check that the `has_subsections` flag is updated correctly + # (there is no other way to check it using endpoints) + for _ in range(2): + section_data = { + "title": str(additional_test_data["sections"][0]["title"]), + "parent_id": parent_id, + } + response = await ac.post("/api/section", json=section_data) + assert response.status_code == status_code + if not response.is_success: + assert response.json()["detail"] == error_detail + return - data = response.json() - assert "id" in data + data = response.json() + assert "id" in data @pytest.mark.parametrize( diff --git a/planty/conftest.py b/planty/conftest.py index 8308756..d381183 100644 --- a/planty/conftest.py +++ b/planty/conftest.py @@ -40,6 +40,7 @@ def additional_test_data() -> dict[str, Any]: def _load_json_with_data(filename: str) -> dict[str, Any]: with open(Path(__file__).parent / "resources" / filename) as f: test_data: dict[str, Any] = json.load(f) + ids = set() for table_key in test_data: last_idx: int = 0 for row in test_data[table_key]: @@ -58,6 +59,10 @@ def _load_json_with_data(filename: str) -> dict[str, Any]: "(NOTE: this is just a heuristic)" ) last_idx = idx + if column == "id": + if row[column] in ids: + raise ValueError(f"Duplicate id {row[column]} in {table_key}") + ids.add(row[column]) # TODO: make this dict immutable to prevent accidental modification return test_data diff --git a/planty/resources/data.json b/planty/resources/data.json index 445059b..46f82f3 100644 --- a/planty/resources/data.json +++ b/planty/resources/data.json @@ -141,7 +141,7 @@ "index": 2 }, { - "id": "f05b7527-8173-4d14-a1bd-49aaba743247", + "id": "45561eb6-3570-44de-af8a-54212e2981e6", "title": "🎸 Music", "user_id": "38df4136-36b2-4171-8459-27f411af8323", "parent_id": "36ea0a4f-0334-464d-8066-aa359ecfdcba",