From eeda99e60e3e1bb0251b703666e8c4fbeceb1c4d Mon Sep 17 00:00:00 2001 From: Andrew Davison Date: Sun, 6 Oct 2024 17:47:37 +0200 Subject: [PATCH] Fix some "expected fail" tests. --- .../validation_service/data_models.py | 12 +++++++++--- .../validation_service/resources/tests.py | 6 ++++-- .../validation_service/tests/test_validationtests.py | 12 +++++++----- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/validation_service_api/validation_service/data_models.py b/validation_service_api/validation_service/data_models.py index 62603a58..219b07f5 100644 --- a/validation_service_api/validation_service/data_models.py +++ b/validation_service_api/validation_service/data_models.py @@ -896,16 +896,22 @@ class ValidationTest(BaseModel): # todo: add "publication" field @classmethod - def from_kg_query(cls, item, client): + def from_kg_query(cls, item, user_client, service_client): item.pop("@context", None) - item["id"] = client.uuid_from_uri(item["uri"]) + item["id"] = user_client.uuid_from_uri(item["uri"]) space = item["project_id"] # what the query calls "project_id" is really the space item["private"] = is_private(space) item["project_id"] = project_id_from_space(space) item["instances"] = [ - ValidationTestInstance.from_kg_query(instance, client) + ValidationTestInstance.from_kg_query(instance, user_client) for instance in item.get("instances", []) ] + if len(item["instances"]) == 0: + item["implementation_status"] = ImplementationStatus.proposal + elif service_client.is_released(item["uri"]): + item["implementation_status"] = ImplementationStatus.published + else: + item["implementation_status"] = ImplementationStatus.dev data_locations = [] for loc in item["data_location"]: for field in ("IRI", "URL", "name"): diff --git a/validation_service_api/validation_service/resources/tests.py b/validation_service_api/validation_service/resources/tests.py index f20d5339..af48e086 100644 --- a/validation_service_api/validation_service/resources/tests.py +++ b/validation_service_api/validation_service/resources/tests.py @@ -203,6 +203,8 @@ def query_tests( if alias: filters["alias"] = alias if implementation_status: + # todo: this doesn't work, and requires checking release status, + # hence this filter needs to be applied to the results of the query filters["implementation_status"] = implementation_status if project_id: filters["space"] = [f"collab-{collab_id}" for collab_id in project_id] @@ -235,7 +237,7 @@ def query_tests( ).data return [ - cls.from_kg_query(instance, kg_user_client) + cls.from_kg_query(instance, kg_user_client, kg_service_client) for instance in instances ] @@ -251,7 +253,7 @@ def query_tests( instances[instance["uri"]] = instance # use dict to remove duplicates return [ - cls.from_kg_query(instance, kg_user_client) + cls.from_kg_query(instance, kg_user_client, kg_service_client) for instance in list(instances.values())[from_index:from_index + size] ] diff --git a/validation_service_api/validation_service/tests/test_validationtests.py b/validation_service_api/validation_service/tests/test_validationtests.py index 1fd00d5a..f0fadb4a 100644 --- a/validation_service_api/validation_service/tests/test_validationtests.py +++ b/validation_service_api/validation_service/tests/test_validationtests.py @@ -61,9 +61,9 @@ def assert_is_valid_url(url): except ValueError: raise AssertionError -@pytest.mark.xfail # todo: should pass when using a released instance + def test_get_validation_test_by_id_no_auth(): - test_ids = ("01c68387-fcc4-4fd3-85f0-6eb8ce4467a1",) + test_ids = ("90ae68fa-a9e6-49dd-947a-908ab9a6dee2",) for validation_test_uuid in test_ids: response = client.get(f"/tests/{validation_test_uuid}") assert response.status_code == 200 @@ -92,11 +92,13 @@ def test_get_validation_test_by_id(caplog): assert response.status_code == 400 -@pytest.mark.xfail # test to be updated def test_list_validation_tests_no_auth(): response = client.get(f"/tests/") - assert response.status_code == 403 - assert response.json() == {"detail": "Not authenticated"} + assert response.status_code == 200 + validation_tests = response.json() + for validation_test in validation_tests: + check_validation_test(validation_test) + assert validation_test["implementation_status"] == "published" def test_list_validation_tests_nofilters():