Skip to content

Commit 66140b0

Browse files
committed
good sql unit testing strategy
1 parent 1cc2beb commit 66140b0

15 files changed

+1477
-596
lines changed

.gitignore

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,5 @@ __pycache__/
22
.pytest_cache/
33
archive/
44
output.json
5-
data/validated_reference_dataset.xlsx
5+
#ata/validated_reference_dataset.xlsx
66

7-
# YAML validation rules instead of Python
8-
# rules_config.yaml
9-
# validation_rules_yaml.py
10-
# tests/test_sql_logic_yaml.py

data/validated_reference_dataset.xlsx

12.3 KB
Binary file not shown.
-12.4 KB
Binary file not shown.

expected_results/expected_results.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,10 @@
2020
"expected": [
2121
{"week": "2017-31", "active_patients": 30}
2222
]
23+
},
24+
"active_patients_study_1368_0004": {
25+
"expected": [
26+
{"week": "2017-34", "active_patients": 60}
27+
]
2328
}
2429
}

expected_results/expected_results_negative.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

rules_config.yaml

Lines changed: 0 additions & 29 deletions
This file was deleted.

sql_queries/active_patients_date.sql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
SELECT week, active_patients
22
FROM clinical_trials
3-
WHERE week = "2017-31"
3+
WHERE week = "2017-31" AND study = "1368-0004"
44

5-
-- Como hacer para que el test podamos generalizarlo para que sea active_patients en una fecha concreta.
6-
-- De esta forma podemos pasarle distintas fechas y mirar si en todas el test passa.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
SELECT week, active_patients
2+
FROM clinical_trials
3+
WHERE week = "2017-XX" AND study = "1368-0004"
4+
-- error introduced week = "2017-XX" should be week = "2017-34"

tests/conftest.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,3 @@ def db_connection():
1414
connection = engine.connect()
1515
yield connection
1616
connection.close()
17-
18-
@pytest.fixture(scope='module')
19-
def db_connection_negative():
20-
engine = create_engine('sqlite:///:memory:')
21-
file_path = os.path.join(os.path.dirname(__file__), '..', 'data', 'validated_reference_dataset_errors.xlsx')
22-
df = pd.read_excel(file_path)
23-
df.to_sql('clinical_trials', engine, if_exists='replace', index=False)
24-
25-
connection = engine.connect()
26-
yield connection
27-
connection.close()
28-

tests/pytest_html_report.html

Lines changed: 1458 additions & 206 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)