diff --git a/apps/report-execution/Dockerfile b/apps/report-execution/Dockerfile index 97f7107420..33e77617a7 100644 --- a/apps/report-execution/Dockerfile +++ b/apps/report-execution/Dockerfile @@ -9,6 +9,9 @@ COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ WORKDIR /usr/report-execution +# Install mssql driver deps +RUN apt-get update && apt-get install -y libltdl7 libkrb5-3 libgssapi-krb5-2 + # Copy relevant application code COPY pyproject.toml pyproject.toml COPY pytest.toml pytest.toml diff --git a/apps/report-execution/tests/conftest.py b/apps/report-execution/tests/conftest.py index 12b74042b3..2833582193 100644 --- a/apps/report-execution/tests/conftest.py +++ b/apps/report-execution/tests/conftest.py @@ -81,11 +81,16 @@ def setup_containers(request): """Set up DB and report execution containers.""" logging.info('Setting up containers tests...') compose_path = os.path.join(os.path.dirname(__file__), '../../../cdc-sandbox') - compose_file_name = 'docker-compose.yml' + compose_file_names = [ + 'docker-compose.yml', + '../apps/report-execution/tests/integration/docker-compose.yml', + ] containers = DockerCompose( compose_path, - compose_file_name=compose_file_name, + compose_file_name=compose_file_names, services=['report-execution', 'nbs-mssql'], + build=True, + env_file=['../sample.env', '../apps/report-execution/sample.env'], ) report_exec_url = 'http://0.0.0.0:8001/status' diff --git a/apps/report-execution/tests/integration/docker-compose.yml b/apps/report-execution/tests/integration/docker-compose.yml new file mode 100644 index 0000000000..7c9dd6dd04 --- /dev/null +++ b/apps/report-execution/tests/integration/docker-compose.yml @@ -0,0 +1,5 @@ +# Integration test-specific docker compose overrides +services: + report-execution: + # allows using localhost db conn for easy access to db container directly or via report-execution container + network_mode: host diff --git a/apps/report-execution/tests/integration/main.py b/apps/report-execution/tests/integration/main.py new file mode 100644 index 0000000000..f5bb6beadd --- /dev/null +++ b/apps/report-execution/tests/integration/main.py @@ -0,0 +1,41 @@ +import http.client +import json +import os + +import pytest + + +@pytest.mark.usefixtures('setup_containers') +@pytest.mark.integration +class TestMainApp: + """Integration tests for rest API endpoint access.""" + + def test_report_runs(self): + report_spec = { + 'version': 1, + 'is_export': True, + 'is_builtin': True, + 'report_title': 'Test Report', + 'library_name': 'nbs_custom', + # Filter code is used here as it is a stable, small table + 'data_source_name': '[NBS_ODSE].[dbo].[Filter_code]', + 'subset_query': 'SELECT * FROM [NBS_ODSE].[dbo].[Filter_code]', + } + + connection = http.client.HTTPConnection( + f'localhost:{os.getenv("UVICORN_PORT", "8001")}' + ) + + headers = {'Content-type': 'application/json'} + body = json.dumps(report_spec) + + connection.request('POST', '/report/execute', body, headers) + + response = connection.getresponse() + assert response.status == 200 + + result = json.loads(response.read()) + assert ( + result['description'] + == 'Custom Report For Table: [NBS_ODSE].[dbo].[Filter_code]' + ) diff --git a/docker-compose.yml b/docker-compose.yml index 7def759ff4..7bb513107e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -82,5 +82,7 @@ services: build: context: ./apps/report-execution container_name: report-execution + environment: + - DATABASE_CONN_STRING=${DATABASE_CONN_STRING} ports: - "8001:8001" diff --git a/sample.env b/sample.env index 235ce34ddb..cc4e5aa3c8 100644 --- a/sample.env +++ b/sample.env @@ -6,6 +6,7 @@ PARAMETER_SECRET=TmYW3z4qeXyGzcSLDuelRoxUgQg4MxF2 # service settings NBS_DATASOURCE_SERVER=nbs-mssql +DATABASE_CONN_STRING="Server=${NBS_DATASOURCE_SERVER};UID=${DATABASE_USER};PWD=${DATABASE_PASSWORD};Database=NBS_ODSE;TrustServerCertificate=yes;" CLASSIC_SERVICE=wildfly:7001 MODERNIZATION_SERVICE=${MODERNIZATION_API_SERVER:-modernization-api}:${MODERNIZATION_API_PORT:-8080} UI_SERVICE=${MODERNIZATION_UI_SERVER:-modernization-api}:${MODERNIZATION_UI_PORT:-8080}