|
| 1 | +import datetime |
| 2 | +import decimal |
| 3 | + |
1 | 4 | import pytest |
| 5 | +import yaml |
2 | 6 |
|
3 | 7 | from src.execute_report import execute_report |
4 | 8 | from src.models import ReportSpec |
5 | 9 |
|
| 10 | +faker_schema = 'dm_inv_std.yaml' |
| 11 | + |
6 | 12 |
|
7 | | -@pytest.mark.usefixtures('setup_containers') |
| 13 | +@pytest.mark.usefixtures('setup_containers', 'fake_db_table') |
8 | 14 | @pytest.mark.integration |
9 | 15 | class TestIntegrationNbsCustomLibrary: |
10 | 16 | """Integration tests for the nbs_custom library.""" |
11 | 17 |
|
12 | | - def test_execute_report(self): |
| 18 | + def test_execute_report_check_data(self, snapshot): |
13 | 19 | report_spec = ReportSpec.model_validate( |
14 | 20 | { |
15 | 21 | 'is_export': True, |
16 | 22 | 'is_builtin': True, |
17 | 23 | 'report_title': 'NBS Custom', |
18 | 24 | 'library_name': 'nbs_custom', |
19 | | - # Filter operator is used here as it is a stable, small table |
20 | | - 'data_source_name': '[NBS_ODSE].[dbo].[Filter_operator]', |
21 | | - 'subset_query': 'SELECT * FROM [NBS_ODSE].[dbo].[Filter_operator]', |
| 25 | + 'data_source_name': '[NBS_RDB].[dbo].[DM_INV_STD]', |
| 26 | + 'subset_query': """ |
| 27 | + SELECT PROGRAM_JURISDICTION_OID, |
| 28 | + PATIENT_LOCAL_ID, |
| 29 | + EVENT_DATE |
| 30 | + FROM rdb.dbo.DM_INV_STD |
| 31 | + ORDER BY PROGRAM_JURISDICTION_OID, |
| 32 | + PATIENT_LOCAL_ID, |
| 33 | + EVENT_DATE |
| 34 | + """, |
22 | 35 | } |
23 | 36 | ) |
24 | 37 |
|
25 | 38 | result = execute_report(report_spec) |
26 | | - assert result.header == ( |
27 | | - 'Custom Report For Table: [NBS_ODSE].[dbo].[Filter_operator]' |
| 39 | + assert result.content_type == 'table' |
| 40 | + |
| 41 | + data = result.content.data |
| 42 | + assert len(data) == 500 |
| 43 | + assert len(data[0]) == len(result.content.columns) |
| 44 | + assert result.content.columns == [ |
| 45 | + 'PROGRAM_JURISDICTION_OID', |
| 46 | + 'PATIENT_LOCAL_ID', |
| 47 | + 'EVENT_DATE', |
| 48 | + ] |
| 49 | + |
| 50 | + snapshot.assert_match(yaml.dump(data), 'snapshot.yml') |
| 51 | + |
| 52 | + for data in result.content.data: |
| 53 | + assert isinstance(data[0], decimal.Decimal) |
| 54 | + assert isinstance(data[1], str) |
| 55 | + assert isinstance(data[2], datetime.datetime) |
| 56 | + |
| 57 | + def test_execute_report_no_data(self, snapshot): |
| 58 | + report_spec = ReportSpec.model_validate( |
| 59 | + { |
| 60 | + 'is_export': True, |
| 61 | + 'is_builtin': True, |
| 62 | + 'report_title': 'NBS Custom', |
| 63 | + 'library_name': 'nbs_custom', |
| 64 | + 'data_source_name': '[NBS_RDB].[dbo].[DM_INV_STD]', |
| 65 | + 'subset_query': """ |
| 66 | + SELECT PROGRAM_JURISDICTION_OID, |
| 67 | + PATIENT_LOCAL_ID, |
| 68 | + EVENT_DATE |
| 69 | + FROM rdb.dbo.DM_INV_STD |
| 70 | + WHERE 1 = 2 |
| 71 | + """, |
| 72 | + } |
28 | 73 | ) |
29 | | - assert result.subheader is None |
30 | | - assert result.description is None |
| 74 | + |
| 75 | + result = execute_report(report_spec) |
31 | 76 | assert result.content_type == 'table' |
32 | 77 |
|
33 | | - assert len(result.content.data) == 11 |
34 | | - assert len(result.content.data[0]) == len(result.content.columns) |
| 78 | + assert len(result.content.data) == 0 |
| 79 | + assert result.content.columns == [ |
| 80 | + 'PROGRAM_JURISDICTION_OID', |
| 81 | + 'PATIENT_LOCAL_ID', |
| 82 | + 'EVENT_DATE', |
| 83 | + ] |
0 commit comments