From 83a7aa7533f8f4ecac049dc0e93aff6429e6e5ae Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 18 Feb 2022 07:17:50 +0300 Subject: Test partial correlations endpoint with non-existent primary traits Test that the partial correlations endpoint responds with an appropriate "not-found" message and the corresponding 404 status code in the case where a request is made and the primary trait requested for does not exist in the database. Summary of the changes in each file: * gn3/api/correlation.py: generalise the building of the response * gn3/computations/partial_correlations.py: return with a "not-found" if the primary trait does not exist in the database * gn3/db/partial_correlations.py: Fix a number of bugs that led to exceptions in the case that the primary trait did not exist * pytest.ini: register a `slow` pytest marker * tests/integration/test_partial_correlations.py: Add a new test to check for an appropriate 404 response in case of a primary trait that does not exist in the database. --- tests/integration/test_partial_correlations.py | 51 +++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/integration/test_partial_correlations.py b/tests/integration/test_partial_correlations.py index 5b520e0..17ea539 100644 --- a/tests/integration/test_partial_correlations.py +++ b/tests/integration/test_partial_correlations.py @@ -83,8 +83,57 @@ from tests.integration.conftest import client "target_db": None })) def test_partial_correlation_api_with_missing_request_data(client, post_data): - "Test /api/correlations/partial" + """ + Test /api/correlations/partial endpoint with various expected request data + missing. + """ response = client.post("/api/correlation/partial", json=post_data) assert ( response.status_code == 400 and response.is_json and response.json.get("status") == "error") + + +@pytest.mark.integration_test +@pytest.mark.slow +@pytest.mark.parametrize( + "post_data", + ({# ProbeSet + "primary_trait": {"dataset": "a_dataset", "name": "a_name"}, + "control_traits": [ + {"dataset": "a_dataset", "name": "a_name"}, + {"dataset": "a_dataset2", "name": "a_name2"}], + "method": "a_method", + "target_db": "a_db" + }, {# Publish + "primary_trait": {"dataset": "a_Publish_dataset", "name": "a_name"}, + "control_traits": [ + {"dataset": "a_dataset", "name": "a_name"}, + {"dataset": "a_dataset2", "name": "a_name2"}], + "method": "a_method", + "target_db": "a_db" + }, {# Geno + "primary_trait": {"dataset": "a_Geno_dataset", "name": "a_name"}, + "control_traits": [ + {"dataset": "a_dataset", "name": "a_name"}, + {"dataset": "a_dataset2", "name": "a_name2"}], + "method": "a_method", + "target_db": "a_db" + }, {# Temp -- Fails due to missing table. Remove this sample if it is + # confirmed that the deletion of the database table is on purpose, and + # that Temp traits are no longer a thing + "primary_trait": {"dataset": "a_Temp_dataset", "name": "a_name"}, + "control_traits": [ + {"dataset": "a_dataset", "name": "a_name"}, + {"dataset": "a_dataset2", "name": "a_name2"}], + "method": "a_method", + "target_db": "a_db" + })) +def test_partial_correlation_api_with_non_existent_traits(client, post_data): + """ + Check that the system responds appropriately in the case where the user + makes a request with a non-existent primary trait. + """ + response = client.post("/api/correlation/partial", json=post_data) + assert ( + response.status_code == 404 and response.is_json and + response.json.get("status") != "error") -- cgit v1.2.3