11import asyncio
2+ import re
23from http import HTTPStatus
34
45import deepdiff
78from sqlalchemy import text
89from sqlalchemy .ext .asyncio import AsyncConnection
910
10- from core .errors import DatasetNotFoundError
11-
1211
1312async def _remove_quality_from_database (quality_name : str , expdb_test : AsyncConnection ) -> None :
1413 await expdb_test .execute (
@@ -287,7 +286,7 @@ async def test_get_quality(py_api: httpx.AsyncClient) -> None:
287286
288287@pytest .mark .parametrize (
289288 "data_id" ,
290- list (set (range (1 , 132 )) - { 55 , 56 , 59 , 116 , 130 }) ,
289+ [ * list (set (range (1 , 133 ))), 9999999 ] ,
291290)
292291async def test_get_quality_identical (
293292 data_id : int , py_api : httpx .AsyncClient , php_api : httpx .AsyncClient
@@ -296,8 +295,24 @@ async def test_get_quality_identical(
296295 py_api .get (f"/datasets/qualities/{ data_id } " ),
297296 php_api .get (f"/data/qualities/{ data_id } " ),
298297 )
299- assert python_response .status_code == php_response .status_code
298+ if php_response .status_code == HTTPStatus .OK :
299+ _assert_get_quality_success_equal (python_response , php_response )
300+ return
301+
302+ php_error_code = int (php_response .json ()["error" ]["code" ])
303+ if php_error_code == 361 : # noqa: PLR2004
304+ _assert_get_quality_error_dataset_not_found (python_response , php_response )
305+ elif php_error_code == 364 : # noqa: PLR2004
306+ _assert_get_quality_error_dataset_process_error (python_response , php_response )
307+ else :
308+ msg = f"Dataset { data_id } response not under test:" , php_response .json ()
309+ raise AssertionError (msg )
300310
311+
312+ def _assert_get_quality_success_equal (
313+ python_response : httpx .Response , php_response : httpx .Response
314+ ) -> None :
315+ assert python_response .status_code == php_response .status_code
301316 expected = [
302317 {
303318 "name" : quality ["name" ],
@@ -308,28 +323,31 @@ async def test_get_quality_identical(
308323 assert python_response .json () == expected
309324
310325
311- @pytest .mark .parametrize (
312- "data_id" ,
313- [55 , 56 , 59 , 116 , 130 , 132 ],
314- )
315- async def test_get_quality_identical_error (
316- data_id : int ,
317- py_api : httpx .AsyncClient ,
318- php_api : httpx .AsyncClient ,
326+ def _assert_get_quality_error_dataset_not_found (
327+ python_response : httpx .Response , php_response : httpx .Response
319328) -> None :
320- if data_id in [55 , 56 , 59 ]:
321- pytest .skip ("Detailed error for code 364 (failed processing) not yet supported." )
322- if data_id in [116 ]: # noqa: FURB171
323- pytest .skip ("Detailed error for code 362 (no qualities) not yet supported." )
324- python_response , php_response = await asyncio .gather (
325- py_api .get (f"/datasets/qualities/{ data_id } " ),
326- php_api .get (f"/data/qualities/{ data_id } " ),
327- )
328- assert python_response .status_code == php_response .status_code
329- # RFC 9457: Python API now returns problem+json format
330- assert python_response .headers ["content-type" ] == "application/problem+json"
331- error = python_response .json ()
332- assert error ["type" ] == DatasetNotFoundError .uri
333- # Verify the error message matches the PHP API semantically
334- assert php_response .json ()["error" ]["message" ] == "Unknown dataset"
335- assert error ["detail" ] == f"Dataset with id { data_id } not found."
329+ assert php_response .status_code == HTTPStatus .PRECONDITION_FAILED
330+ assert python_response .status_code == HTTPStatus .NOT_FOUND
331+
332+ php_error = php_response .json ()["error" ]
333+ py_error = python_response .json ()
334+
335+ assert php_error ["code" ] == py_error ["code" ]
336+ assert php_error ["message" ] == "Unknown dataset"
337+ assert re .match (r"Dataset with id \d+ not found." , py_error ["detail" ])
338+
339+
340+ def _assert_get_quality_error_dataset_process_error (
341+ python_response : httpx .Response , php_response : httpx .Response
342+ ) -> None :
343+ assert php_response .status_code == python_response .status_code
344+
345+ php_error = php_response .json ()["error" ]
346+ py_error = python_response .json ()
347+
348+ assert php_error ["code" ] == py_error ["code" ]
349+ assert php_error ["message" ] == "Dataset processed with error"
350+ assert py_error ["title" ] == "Dataset Processing Error"
351+ # The PHP can add some additional unnecessary escapes.
352+ assert php_error ["additional_information" ][:30 ] == py_error ["detail" ][:30 ]
353+ assert php_error ["additional_information" ][- 30 :] == py_error ["detail" ][- 30 :]
0 commit comments