From d1c386994fbe5878d3d3a3cb323ab0fa1c610766 Mon Sep 17 00:00:00 2001 From: Andrew Davison Date: Mon, 7 Oct 2024 13:10:58 +0200 Subject: [PATCH] fix update_test_instance_by_id endpoint --- .../validation_service/resources/tests.py | 3 +- .../tests/test_validationtests.py | 44 ++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/validation_service_api/validation_service/resources/tests.py b/validation_service_api/validation_service/resources/tests.py index d03ed1ff..d52df130 100644 --- a/validation_service_api/validation_service/resources/tests.py +++ b/validation_service_api/validation_service/resources/tests.py @@ -556,9 +556,10 @@ def update_test_instance_by_id( user = User(token, allow_anonymous=False) kg_client = get_kg_client_for_user_account(token) test_instance_kg = _get_test_instance_by_id(test_instance_id, kg_client, scope="any") - test_definition = omcmp.ValidationTest.list( + test_definition_kg = omcmp.ValidationTest.list( kg_client, scope="any", space=test_instance_kg.space, versions=test_instance_kg)[0] + test_definition = ValidationTest.from_kg_object(test_definition_kg, kg_client) return _update_test_instance(test_instance_kg, test_definition, test_instance_patch, kg_client) diff --git a/validation_service_api/validation_service/tests/test_validationtests.py b/validation_service_api/validation_service/tests/test_validationtests.py index 5ed25906..308e8122 100644 --- a/validation_service_api/validation_service/tests/test_validationtests.py +++ b/validation_service_api/validation_service/tests/test_validationtests.py @@ -580,7 +580,47 @@ def test_update_test_instance(): assert response.status_code == 200 # now retrieve the test and check the instance has been updated - sleep(15) # need to wait a short time to allow Nexus to become consistent + sleep(15) # need to wait a short time to allow KG to become consistent + response = client.get(f"/tests/{test_uuid}", headers=AUTH_HEADER) + assert response.status_code == 200 + retrieved_test = response.json() + assert len(retrieved_test["instances"]) == 1 + assert ( + retrieved_test["instances"][0]["version"] == payload1["instances"][0]["version"] + ) # should be unchanged + assert retrieved_test["instances"][0]["repository"] == payload2["repository"] + assert retrieved_test["instances"][0]["description"] == payload2["description"] + + # delete again + response = client.delete(f"/tests/{test_uuid}", headers=AUTH_HEADER) + assert response.status_code == 200 + + +def test_update_test_instance_without_test_id(): + # first create a test project + payload1 = _build_sample_validation_test() + response = client.post(f"/tests/", json=payload1, headers=AUTH_HEADER) + assert response.status_code == 201 + posted_test = response.json() + check_validation_test(posted_test) + assert len(posted_test["instances"]) == 1 + test_uuid = posted_test["id"] + test_instance_uuid = posted_test["instances"][0]["id"] + + # now edit the instance + payload2 = { + "description": "a more detailed description of this version", + "repository": "http://example.com/my_code_in_a_new_location.py", + "path": "hbp_validation_framework.sample.SampleTest", + "parameters": "http://example.com/modified_config.json", + } + response = client.put( + f"/tests/query/instances/{test_instance_uuid}", json=payload2, headers=AUTH_HEADER + ) + assert response.status_code == 200 + + # now retrieve the test and check the instance has been updated + sleep(15) # need to wait a short time to allow KG to become consistent response = client.get(f"/tests/{test_uuid}", headers=AUTH_HEADER) assert response.status_code == 200 retrieved_test = response.json() @@ -590,6 +630,8 @@ def test_update_test_instance(): ) # should be unchanged assert retrieved_test["instances"][0]["repository"] == payload2["repository"] assert retrieved_test["instances"][0]["description"] == payload2["description"] + assert retrieved_test["instances"][0]["path"] == payload2["path"] + assert retrieved_test["instances"][0]["parameters"] == payload2["parameters"] # delete again response = client.delete(f"/tests/{test_uuid}", headers=AUTH_HEADER)