|
10 | 10 | from sqlalchemy import text |
11 | 11 | from sqlalchemy.ext.asyncio import AsyncConnection |
12 | 12 |
|
| 13 | +from core.conversions import nested_remove_values, nested_str_to_num |
13 | 14 | from tests.conftest import temporary_records |
14 | 15 | from tests.users import OWNER_USER, ApiKey |
15 | 16 |
|
@@ -274,6 +275,55 @@ async def test_setup_tag_response_is_identical_tag_already_exists( |
274 | 275 |
|
275 | 276 | assert original.status_code == HTTPStatus.INTERNAL_SERVER_ERROR |
276 | 277 | assert new.status_code == HTTPStatus.CONFLICT |
277 | | - assert original.json()["error"]["code"] == new.json()["code"] |
278 | 278 | assert original.json()["error"]["message"] == "Entity already tagged by this tag." |
279 | 279 | assert new.json()["detail"] == f"Setup {setup_id} already has tag {tag!r}." |
| 280 | + |
| 281 | + |
| 282 | +async def test_get_setup_response_is_identical_setup_doesnt_exist( |
| 283 | + py_api: httpx.AsyncClient, |
| 284 | + php_api: httpx.AsyncClient, |
| 285 | +) -> None: |
| 286 | + setup_id = 999999 |
| 287 | + |
| 288 | + original, new = await asyncio.gather( |
| 289 | + php_api.get(f"/setup/{setup_id}"), |
| 290 | + py_api.get(f"/setup/{setup_id}"), |
| 291 | + ) |
| 292 | + |
| 293 | + assert original.status_code == HTTPStatus.PRECONDITION_FAILED |
| 294 | + assert new.status_code == HTTPStatus.NOT_FOUND |
| 295 | + assert original.json()["error"]["message"] == "Unknown setup" |
| 296 | + assert original.json()["error"]["code"] == new.json()["code"] |
| 297 | + assert new.json()["detail"] == f"Setup {setup_id} not found." |
| 298 | + |
| 299 | + |
| 300 | +@pytest.mark.parametrize("setup_id", range(1, 125)) |
| 301 | +async def test_get_setup_response_is_identical( |
| 302 | + setup_id: int, |
| 303 | + py_api: httpx.AsyncClient, |
| 304 | + php_api: httpx.AsyncClient, |
| 305 | +) -> None: |
| 306 | + original, new = await asyncio.gather( |
| 307 | + php_api.get(f"/setup/{setup_id}"), |
| 308 | + py_api.get(f"/setup/{setup_id}"), |
| 309 | + ) |
| 310 | + |
| 311 | + if original.status_code == HTTPStatus.PRECONDITION_FAILED: |
| 312 | + assert new.status_code == HTTPStatus.NOT_FOUND |
| 313 | + return |
| 314 | + |
| 315 | + assert original.status_code == HTTPStatus.OK |
| 316 | + assert new.status_code == HTTPStatus.OK |
| 317 | + |
| 318 | + original_json = original.json() |
| 319 | + |
| 320 | + # PHP returns integer fields as strings. To compare, we recursively convert string digits |
| 321 | + # to integers. |
| 322 | + # PHP also returns `[]` instead of null for empty string optional fields, which Python omits. |
| 323 | + original_json = nested_str_to_num(original_json) |
| 324 | + original_json = nested_remove_values(original_json, values=[[], None]) |
| 325 | + |
| 326 | + new_json = nested_str_to_num(new.json()) |
| 327 | + new_json = nested_remove_values(new_json, values=[[], None]) |
| 328 | + |
| 329 | + assert original_json == new_json |
0 commit comments