Skip to content

Commit

Permalink
Create integration test for the FHIR converter (#826)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmastephenson authored Sep 13, 2023
1 parent fdac67e commit 1ff2cdf
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 2 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/listContainers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
outputs:
containers:
value: ${{ jobs.list-containers.outputs.container-dirs }}
integration-dirs:
value: ${{ jobs.list-integration-test-directories.outputs.integration-dirs }}

jobs:
list-containers:
Expand All @@ -23,4 +25,19 @@ jobs:
# use jq to produce json output and filter out the empty item caused by final newline
run: |
ls -d * | jq -R -s -c 'split("\n")[:-1]'
echo "containers=$(ls -d */ | cut -f1 -d'/' | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
echo "containers=$(ls -d */ | cut -f1 -d'/' | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
list-integration-test-directories:
runs-on: ubuntu-latest
outputs:
integration-dirs: ${{steps.generate-integration-list.outputs.containers_to_test}}
steps:
- name: Check Out Changes
uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt-get install jq
- id: generate-integration-list
name: Generate list of integration test directories within containers/
working-directory: ./containers
run: |
echo "containers_to_test=$(find . -name "integration" -type d | cut -d "/" -f2 | jq -R -s -c 'split("\n")[:-1]' )" >> $GITHUB_OUTPUT
27 changes: 26 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,29 @@ jobs:
MPI_PERSON_TABLE: person
working-directory: ./containers/${{matrix.container-to-test}}/tests
run: |
python -m pytest
python -m pytest -m "not integration"
integration-test-python-containers:
needs: list-containers
runs-on: ubuntu-latest
strategy:
matrix:
directories-to-test: ${{fromJson(needs.list-containers.outputs.integration-dirs)}}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup python ${{env.TEST_RUNNER_PYTHON_VERSION}}
uses: actions/setup-python@v2
with:
python-version: ${{env.TEST_RUNNER_PYTHON_VERSION}}
cache: pip
- name: Install Pytest
run: pip install pytest
- name: Install dependencies
working-directory: ./containers/${{matrix.directories-to-test}}
run: |
pwd
pip install -r requirements.txt
- name: Run integration tests for containers
working-directory: ./containers/${{matrix.directories-to-test}}/tests/integration
run: |
python -m pytest -m "integration"
1 change: 1 addition & 0 deletions containers/fhir-converter/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ requests==2.31.0
six==1.16.0
sniffio==1.2.0
starlette==0.27.0
testcontainers[compose]==3.7.1
tomli==2.0.1
typing_extensions==4.3.0
ujson==5.4.0
Expand Down
22 changes: 22 additions & 0 deletions containers/fhir-converter/tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest
import os
from testcontainers.compose import DockerCompose


@pytest.fixture(scope="session")
def setup(request):
print("Setting up tests...")
compose_path = os.path.join(os.path.dirname(__file__), "./")
compose_file_name = "docker-compose.yaml"
fhir_converter = DockerCompose(compose_path, compose_file_name=compose_file_name)
converter_url = "http://0.0.0.0:8080"

fhir_converter.start()
fhir_converter.wait_for(converter_url)
print("FHIR Converter ready to test!")

def teardown():
print("Tests finished! Tearing down.")
fhir_converter.stop()

request.addfinalizer(teardown)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3.3'

services:
fhir-converter-service:
build:
context: ../..
ports:
- "8080:8080"
84 changes: 84 additions & 0 deletions containers/fhir-converter/tests/integration/test_FHIR-Converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import httpx
import pytest
from pathlib import Path

CONVERTER_URL = "http://0.0.0.0:8080"
CONVERT_TO_FHIR = CONVERTER_URL + "/convert-to-fhir"


@pytest.mark.integration
def test_health_check(setup):
health_check_response = httpx.get(CONVERTER_URL)
assert health_check_response.status_code == 200


@pytest.mark.integration
def test_vxu_conversion(setup):
input_data = open(
Path(__file__).parent.parent.parent / "assets" / "sample_request.hl7"
).read()
request = {
"input_data": input_data,
"input_type": "vxu",
"root_template": "VXU_V04",
}
vxu_conversion_response = httpx.post(CONVERT_TO_FHIR, json=request)

assert vxu_conversion_response.status_code == 200
assert (
vxu_conversion_response.json()["response"]["FhirResource"]["resourceType"]
== "Bundle"
)


@pytest.mark.integration
def test_ecr_conversion(setup):
input_data = open(
Path(__file__).parent.parent.parent.parent.parent
/ "tests"
/ "assets"
/ "fhir-converter"
/ "ccda"
/ "ccda_sample.xml"
).read()
request = {"input_data": input_data, "input_type": "ecr", "root_template": "EICR"}
ecr_conversion_response = httpx.post(CONVERT_TO_FHIR, json=request)

assert ecr_conversion_response.status_code == 200
assert (
ecr_conversion_response.json()["response"]["FhirResource"]["resourceType"]
== "Bundle"
)


@pytest.mark.integration
def test_ecr_conversion_with_rr(setup):
rr_data = open(
Path(__file__).parent.parent.parent.parent.parent
/ "tests"
/ "assets"
/ "fhir-converter"
/ "rr_extraction"
/ "CDA_RR.xml"
).read()
input_data = open(
Path(__file__).parent.parent.parent.parent.parent
/ "tests"
/ "assets"
/ "fhir-converter"
/ "rr_extraction"
/ "CDA_eICR.xml"
).read()
request = {
"input_data": input_data,
"input_type": "ecr",
"root_template": "EICR",
"rr_data": rr_data,
}
ecr_conversion_response = httpx.post(CONVERT_TO_FHIR, json=request)

assert ecr_conversion_response.status_code == 200
assert (
ecr_conversion_response.json()["response"]["FhirResource"]["resourceType"]
== "Bundle"
)
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
markers =
integration : run all integration tests

0 comments on commit 1ff2cdf

Please # to comment.