Skip to content

Commit

Permalink
fix update_test_instance_by_id endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
apdavison committed Oct 7, 2024
1 parent ee1ec54 commit d1c3869
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
3 changes: 2 additions & 1 deletion validation_service_api/validation_service/resources/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit d1c3869

Please sign in to comment.