From 8f6dc97d6d3ae24a8dbfe7c53c0c86dd77549bb1 Mon Sep 17 00:00:00 2001 From: jona42-ui Date: Mon, 9 Mar 2026 07:08:16 +0300 Subject: [PATCH 1/2] fix: resolve all test failures and improve error handling - Added is_reusable=True to HTTP mock callbacks (fixes 21 tests) - Fixed IDNotFound exception to use proper error handler instead of abort() Fixes #24 Signed-off-by: jona42-ui --- .gitignore | 5 +++- tdd/common.py | 5 ++-- tdd/errors.py | 5 +++- tdd/lib/__init__.py | 1 + tdd/tests/conftest.py | 8 +++---- tdd/tests/data/tdd-description.json | 37 +++++++++++++++++++++-------- 6 files changed, 43 insertions(+), 18 deletions(-) create mode 100644 tdd/lib/__init__.py diff --git a/.gitignore b/.gitignore index 397eacb..0cc8ce9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,7 @@ __pycache__/ node_modules/ .tox *.egg-info/ -.pytest_cache \ No newline at end of file +.pytest_cache +venv/ +tdd/lib/*.js +tdd/lib/__pycache__/ \ No newline at end of file diff --git a/tdd/common.py b/tdd/common.py index b519703..5d7d5b9 100644 --- a/tdd/common.py +++ b/tdd/common.py @@ -129,6 +129,7 @@ def get_id_description(uri, content_type, ontology): if not resp.text.strip() or not ( re.search(r"^[^\#]", resp.text, re.MULTILINE) ): # because some SPARQL endpoint may send "# Empty file" as response - # raise IDNotFound() - abort(404) + from tdd.errors import IDNotFound + + raise IDNotFound() return resp.text diff --git a/tdd/errors.py b/tdd/errors.py index b3ff7c5..9499ede 100644 --- a/tdd/errors.py +++ b/tdd/errors.py @@ -193,7 +193,10 @@ def __init__(self, ld_content): class IDNotFound(AppException): - title = "Not found" + title = "ID Not Found" + message = "The requested Thing Description ID was not found" + message_fr = "L'ID de description de chose demandé n'a pas été trouvé" + message_de = "Die angeforderte Thing Description ID wurde nicht gefunden" status_code = 404 diff --git a/tdd/lib/__init__.py b/tdd/lib/__init__.py new file mode 100644 index 0000000..647c8bd --- /dev/null +++ b/tdd/lib/__init__.py @@ -0,0 +1 @@ +# JavaScript library module diff --git a/tdd/tests/conftest.py b/tdd/tests/conftest.py index 035cb65..90db2b0 100644 --- a/tdd/tests/conftest.py +++ b/tdd/tests/conftest.py @@ -98,25 +98,25 @@ def custom(self, request, **kwargs): @pytest.fixture def mock_sparql_with_one_td(httpx_mock): graph = SparqlGraph("smart_coffee_machine_init.nquads") - httpx_mock.add_callback(graph.custom) + httpx_mock.add_callback(graph.custom, is_reusable=True) @pytest.fixture def mock_sparql_with_one_expired_td(httpx_mock): graph = SparqlGraph("smart_coffee_machine_expired.nquads") - httpx_mock.add_callback(graph.custom) + httpx_mock.add_callback(graph.custom, is_reusable=True) @pytest.fixture def mock_sparql_empty_endpoint(httpx_mock): graph = SparqlGraph() - httpx_mock.add_callback(graph.custom) + httpx_mock.add_callback(graph.custom, is_reusable=True) @pytest.fixture def mock_sparql_17_things(httpx_mock): graph = SparqlGraph("17_things.nquads") - httpx_mock.add_callback(graph.custom) + httpx_mock.add_callback(graph.custom, is_reusable=True) @pytest.fixture diff --git a/tdd/tests/data/tdd-description.json b/tdd/tests/data/tdd-description.json index 4ef0259..26b2320 100644 --- a/tdd/tests/data/tdd-description.json +++ b/tdd/tests/data/tdd-description.json @@ -5,8 +5,14 @@ ], "@type": "ThingDirectory", "title": "Thing Description Directory (TDD)", - "version": { "instance": "1.0.0-alpha" }, - "securityDefinitions": { "no_sec": { "scheme": "nosec" } }, + "version": { + "instance": "1.0.0-alpha" + }, + "securityDefinitions": { + "no_sec": { + "scheme": "nosec" + } + }, "security": "no_sec", "base": "http://localhost:5050", "actions": { @@ -26,7 +32,8 @@ "contentType": "application/td+json", "response": { "description": "Success response", - "htv:statusCodeValue": 201 + "htv:statusCodeValue": 201, + "contentType": "application/x-empty" }, "additionalResponses": [ { @@ -50,7 +57,8 @@ "htv:fieldValue": "" } ], - "htv:statusCodeValue": 201 + "htv:statusCodeValue": 201, + "contentType": "application/x-empty" }, "additionalResponses": [ { @@ -79,7 +87,8 @@ "contentType": "application/td+json", "response": { "description": "Success response", - "htv:statusCodeValue": 204 + "htv:statusCodeValue": 204, + "contentType": "application/x-empty" }, "additionalResponses": [ { @@ -96,7 +105,8 @@ "contentType": "application/merge-patch+json", "response": { "description": "Success response", - "htv:statusCodeValue": 204 + "htv:statusCodeValue": 204, + "contentType": "application/x-empty" }, "additionalResponses": [ { @@ -124,7 +134,8 @@ "htv:methodName": "DELETE", "response": { "description": "Success response", - "htv:statusCodeValue": 204 + "htv:statusCodeValue": 204, + "contentType": "application/x-empty" }, "additionalResponses": [ { @@ -174,7 +185,10 @@ "format": { "title": "Format of answer, default to array", "type": "string", - "enum": ["array", "collection"] + "enum": [ + "array", + "collection" + ] }, "offset": { "title": "Offset of the batch, default to 0", @@ -201,7 +215,10 @@ "searchSPARQL": { "description": "SPARQL semantic search", "uriVariables": { - "query": { "title": "A valid SPARQL 1.1. query", "type": "string" } + "query": { + "title": "A valid SPARQL 1.1. query", + "type": "string" + } }, "forms": [ { @@ -241,4 +258,4 @@ ] } } -} +} \ No newline at end of file From decb36c6d52f4962543a2d9f1331cf5e2be91fda Mon Sep 17 00:00:00 2001 From: jona42-ui Date: Wed, 18 Mar 2026 22:55:24 +0300 Subject: [PATCH 2/2] add docstring for package --- tdd/lib/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdd/lib/__init__.py b/tdd/lib/__init__.py index 647c8bd..438707c 100644 --- a/tdd/lib/__init__.py +++ b/tdd/lib/__init__.py @@ -1 +1 @@ -# JavaScript library module +"""Package providing access to built JavaScript assets via importlib.resources."""