Skip to content

Commit

Permalink
add test for unrecognized node URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssadai committed Nov 17, 2023
1 parent d621bee commit 0b5277c
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/test_query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import pytest

from app.api import crud


@pytest.fixture
def mock_invalid_get():
"""Mock get function that does not return any response (for testing invalid parameter values)."""

async def mockreturn(
min_age,
max_age,
sex,
diagnosis,
is_control,
min_num_sessions,
assessment,
image_modal,
node_urls,
):
return None

return mockreturn


@pytest.mark.parametrize(
"invalid_node_url_list",
[
[
"https://api.neurobagel.org/",
"https://mysterynode.org/",
], # can probably change this to set an environment variable
["http://unknownnode.org", "https://mysterynode.org/"],
],
)
def test_get_invalid_node_urls(
test_app, mock_invalid_get, monkeypatch, invalid_node_url_list
):
"""Given a node URL list that contains URL(s) not recognized by the API instance, returns an informative 422 error response."""

monkeypatch.setattr(crud, "get", mock_invalid_get)

response = test_app.get(
f"/query/?node_url={invalid_node_url_list[0]}&node_url={invalid_node_url_list[1]}"
)
assert response.status_code == 422
assert "Unrecognized Neurobagel node URL(s)" in response.text

0 comments on commit 0b5277c

Please sign in to comment.