Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core functionality of /data_objects/study/{study_id} endpoint is not being tested #725

Closed
eecavanna opened this issue Oct 9, 2024 · 3 comments · Fixed by #849
Closed
Assignees
Labels
bug Something isn't working X SMALL Less than 1 day

Comments

@eecavanna
Copy link
Collaborator

The only test that targets the /data_objects/study/{study_id} endpoint, targets a corner case where the specified study does not exist.

def test_find_data_objects_for_nonexistent_study(api_site_client):
r"""
Confirms the endpoint returns an unsuccessful status code when no `Study` having the specified `id` exists.
Reference: https://docs.pytest.org/en/stable/reference/reference.html#pytest.raises
Note: The `api_site_client` fixture's `request` method will raise an exception if the server responds with
an unsuccessful status code.
TODO: Add tests focused on the situation where the `Study` _does_ exist.
"""
ensure_schema_collections_and_alldocs()
with pytest.raises(requests.exceptions.HTTPError):
api_site_client.request(
"GET",
"/data_objects/study/nmdc:sty-11-hdd4bf83",
)

There are no tests that target the core functionality (a.k.a. "happy path") of the endpoint.

# FIXME: Seed the database with documents that would be included in an `alldocs` collection,
# such that the `/data_objects/study/{study_id}` endpoint (which uses that collection)
# would return some data. Currently, we are practically _not testing_ that endpoint.

Previously, there was a test that targeted the core functionality; but it was removed because it relied on a static database dump (which conformed to a specific schema) residing on the NERSC filesystem.

Related (bug report involving this endpoint): #723

@eecavanna eecavanna added bug Something isn't working X SMALL Less than 1 day labels Oct 9, 2024
@aclum
Copy link
Contributor

aclum commented Dec 17, 2024

I am advocating for this be escalated, this is the second time we've caught problem in production with this endpoint. cc @shreddd

@eecavanna
Copy link
Collaborator Author

I'll create a branch that contains the skeleton of a test, and then work with @sujaypatil96 to flesh it out.

@eecavanna
Copy link
Collaborator Author

I created a branch (in a draft PR) in which I implemented the following two new tests:

  1. test_find_data_objects_for_study_having_none: the Study exists, but doesn't have anything associated with it (e.g. no Biosamples, no DataGenerations, no DataObjects). In this case, the endpoint returns no DataObjects.
  2. test_find_data_objects_for_study_having_one: the Study exists, a Biosample is associated with that Study, a MassSpectrometry (which inherits from DataObject) has that Biosample as an input, and a DataObject is an output of that MassSpectrometry. In this case, the endpoint returns one DataObject.

Here's a link to the PR: #849

I will invite others to contribute to it there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working X SMALL Less than 1 day
Projects
No open projects
4 participants