From 1188542f1f4b25d2362b87aa454663f7880035fb Mon Sep 17 00:00:00 2001 From: Bloom Date: Wed, 18 Dec 2024 11:25:59 -0500 Subject: [PATCH] add tests FHIR-2646 --- .idea/misc.xml | 9 +++++---- Markdown.iml | 1 + build_support/pants/flake8.ini | 3 +-- jupyter/BUILD | 6 ++++++ jupyter/test_dbgap_fhir.py | 18 ++++++++++++++++++ 5 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 jupyter/test_dbgap_fhir.py diff --git a/.idea/misc.xml b/.idea/misc.xml index ec803ea..9143549 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,7 @@ - + - - + + - + + \ No newline at end of file diff --git a/Markdown.iml b/Markdown.iml index 497dbf4..9dc51f1 100644 --- a/Markdown.iml +++ b/Markdown.iml @@ -5,6 +5,7 @@ + \ No newline at end of file diff --git a/build_support/pants/flake8.ini b/build_support/pants/flake8.ini index 3c91c3f..1a37f50 100644 --- a/build_support/pants/flake8.ini +++ b/build_support/pants/flake8.ini @@ -12,5 +12,4 @@ max-complexity = 11 ignore = E203,W503 per_file_ignores = ; Make flake8 ignore late module imports just like Ruff - utils/tests/*.py: E402 - analyze_har_files/tests/*.py: E402 + ; utils/tests/*.py: E402 diff --git a/jupyter/BUILD b/jupyter/BUILD index ba6140b..cacce53 100644 --- a/jupyter/BUILD +++ b/jupyter/BUILD @@ -8,3 +8,9 @@ python_sources( sources = ["dbgap_fhir.py"], dependencies = [":dbgap_fhir_requirements"], ) + +python_test( + name = "dbgap_fhir_test", + source = "dbgap_fhir_test.py", + dependencies = [":dbgap_fhir_src"], +) diff --git a/jupyter/test_dbgap_fhir.py b/jupyter/test_dbgap_fhir.py new file mode 100644 index 0000000..2e92f1a --- /dev/null +++ b/jupyter/test_dbgap_fhir.py @@ -0,0 +1,18 @@ +from unittest.mock import patch, MagicMock +from jupyter.dbgap_fhir import DbGapFHIR, obs_to_df, prettyprint + + + +@patch('requests.Session') +def test_run_query_with_limit(MockSession): + mock_session = MockSession.return_value + mock_response = MagicMock() + mock_response.json.return_value = {"entry": [{"resource": {"id": "1"}}]} + mock_response.content = b'{"entry": [{"resource": {"id": "1"}}]}' + mock_session.get.return_value = mock_response + + client = DbGapFHIR(fhir_server="http://example.com") + result = client.run_query("Patient", limit=True) + + assert len(result) == 1 + assert result[0]["id"] == "1" \ No newline at end of file