Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/report-execution/pytest.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[pytest]
pythonpath = ["."]
testpaths = ["tests"]
norecursedirs = ["assets"]
python_files = ["*.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
Expand All @@ -10,4 +11,4 @@ addopts = [
"--strict-config",
"--showlocals",
"--import-mode=importlib"
]
]
2 changes: 1 addition & 1 deletion apps/report-execution/src/execute_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get_library(library_name: str, is_builtin: bool):
if is_builtin:
return import_module(f'src.libraries.{library_name}')
else:
raise errors.ToDoError('support custom libraries')
return import_module(f'src.libraries.custom.{library_name}')
except ModuleNotFoundError:
# Initial error not helpful for debugging
raise errors.MissingLibraryError(library_name, is_builtin) from None
2 changes: 2 additions & 0 deletions apps/report-execution/src/libraries/custom/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This module contains libraries that deployments mount into this location, but will be
# empty in the base product
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from src.db_transaction import Transaction
from src.models import ReportResult, TimeRange


def execute(
trx: Transaction,
subset_query: str,
data_source_name: str,
time_range: TimeRange | None = None,
**kwargs,
):
"""This is a stub custom library just to start to get the interface hooked up."""
content = trx.execute(subset_query)

return ReportResult(
content_type='table', content=content, description='Custom pass through query'
)
6 changes: 6 additions & 0 deletions apps/report-execution/tests/integration/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ services:
report-execution:
# allows using localhost db conn for easy access to db container directly or via report-execution container
network_mode: host
# Tests external client library mounting into container works
volumes:
- type: bind
source: ../apps/report-execution/tests/integration/assets/custom_library.py
target: /usr/report-execution/src/libraries/custom/custom_library.py
read_only: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import http.client
import json

import pytest


@pytest.mark.usefixtures('setup_containers')
@pytest.mark.integration
class TestCustomLibrary:
"""Integration tests for custom library execution."""

def test_custom_library_runs(self):
report_spec = {
'version': 1,
'is_export': True,
'is_builtin': False,
'report_title': 'Test Report',
'library_name': 'custom_library',
# 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('localhost: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 pass through query'
2 changes: 1 addition & 1 deletion apps/report-execution/tests/integration/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ def test_report_runs(self):

result = json.loads(response.read())
assert (
result['description']
result['header']
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not specific to this changeset, but lingering bug from PR interaction effect already on main

== 'Custom Report For Table: [NBS_ODSE].[dbo].[Filter_code]'
)
Loading