From 058f6592d8815a64544f6721a9984b89ea92522a Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Sat, 19 Feb 2022 03:21:27 +0300 Subject: Test partial corrs endpoint with non-existing control traits Test that if the endpoint is queried and not a single one of the control traits exists in the database, then the endpoint will respond with a 404 (not-found) status code. Summary of changes: * gn3/computations/partial_correlations.py: Check whether any control trait is found. If none is found, return "not-found" message. * gn3/db/partial_correlations.py: Fix bug in Geno query. * tests/integration/test_partial_correlations.py: Add test for non-existing control traits. Rename function to make it clearer what it is testing for. Remove obsoleted comments. --- gn3/computations/partial_correlations.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'gn3/computations') diff --git a/gn3/computations/partial_correlations.py b/gn3/computations/partial_correlations.py index 16cbbdb..1cc969c 100644 --- a/gn3/computations/partial_correlations.py +++ b/gn3/computations/partial_correlations.py @@ -621,14 +621,19 @@ def partial_correlations_entry(# pylint: disable=[R0913, R0914, R0911] "status": "not-found", "message": f"Could not find primary trait {primary_trait['trait_fullname']}" } + cntrl_traits = tuple( + trait for trait in all_traits + if trait["trait_fullname"] != primary_trait_name) + if not any(trait["haveinfo"] for trait in cntrl_traits): + return { + "status": "not-found", + "message": "None of the requested control traits were found."} + group = primary_trait["db"]["group"] primary_trait_data = all_traits_data[primary_trait["trait_name"]] primary_samples, primary_values, _primary_variances = export_informative( primary_trait_data) - cntrl_traits = tuple( - trait for trait in all_traits - if trait["trait_fullname"] != primary_trait_name) cntrl_traits_data = tuple( data for trait_name, data in all_traits_data.items() if trait_name != primary_trait["trait_name"]) -- cgit v1.2.3