Skip to content

Commit

Permalink
Creating a simple test generator for our tests (#642)
Browse files Browse the repository at this point in the history
* Generate patient data

* Add data generation

* Added folder prefix
  • Loading branch information
KennethSkylight authored Jun 13, 2023
1 parent 3bad598 commit 7578190
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 47 deletions.
33 changes: 5 additions & 28 deletions tests/linkage/test_linkage.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
from random import seed
from math import log
from json.decoder import JSONDecodeError
from tests.test_data_generator import (
generate_list_patients_contact,
)


def _set_up_postgres_client():
Expand Down Expand Up @@ -367,20 +370,7 @@ def test_block_parquet_data():


def test_compile_match_lists():
data = [
["11-7-2153", "John", "Shepard", "", "", "", "", "90909", 1],
["11-7-2153", "Jhon", "Sheperd", "", "", "", "", "90909", 5],
["11-7-2153", "Jon", "Shepherd", "", "", "", "", "90909", 11],
["11-7-2153", "Johnathan", "Shepard", "", "", "", "", "90909", 12],
["11-7-2153", "Nathan", "Shepard", "", "", "", "", "90909", 13],
["01-10-1986", "Jane", "Smith", "", "", "", "", "12345", 14],
["12-12-1992", "Daphne", "Walker", "", "", "", "", "23456", 18],
["1-1-1980", "Alejandro", "Villanueve", "", "", "", "", "15935", 23],
["1-1-1980", "Alejandro", "Villanueva", "", "", "", "", "15935", 24],
["2-2-1990", "Philip", "", "", "", "", "", "64873", 27],
["1-1-1980", "Alejandr", "Villanueve", "", "", "", "", "15935", 31],
["1-1-1980", "Aelxdrano", "Villanueve", "", "", "", "", "15935", 32],
]
data = generate_list_patients_contact()
data = pd.DataFrame(
data,
columns=[
Expand Down Expand Up @@ -434,20 +424,7 @@ def test_feature_match_four_char():


def test_map_matches_to_ids():
data = [
["11-7-2153", "John", "Shepard", "", "", "", "", "90909", 1],
["11-7-2153", "Jhon", "Sheperd", "", "", "", "", "90909", 5],
["11-7-2153", "Jon", "Shepherd", "", "", "", "", "90909", 11],
["11-7-2153", "Johnathan", "Shepard", "", "", "", "", "90909", 12],
["11-7-2153", "Nathan", "Shepard", "", "", "", "", "90909", 13],
["01-10-1986", "Jane", "Smith", "", "", "", "", "12345", 14],
["12-12-1992", "Daphne", "Walker", "", "", "", "", "23456", 18],
["1-1-1980", "Alejandro", "Villanueve", "", "", "", "", "15935", 23],
["1-1-1980", "Alejandro", "Villanueva", "", "", "", "", "15935", 24],
["2-2-1990", "Philip", "", "", "", "", "", "64873", 27],
["1-1-1980", "Alejandr", "Villanueve", "", "", "", "", "15935", 31],
["1-1-1980", "Aelxdrano", "Villanueve", "", "", "", "", "15935", 32],
]
data = generate_list_patients_contact()
data = pd.DataFrame(
data,
columns=[
Expand Down
33 changes: 33 additions & 0 deletions tests/test_data_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
def generate_list_patients_contact():
patient_data = [
["11-7-2153", "John", "Shepard", "", "", "", "", "90909", 1],
["11-7-2153", "Jhon", "Sheperd", "", "", "", "", "90909", 5],
["11-7-2153", "Jon", "Shepherd", "", "", "", "", "90909", 11],
["11-7-2153", "Johnathan", "Shepard", "", "", "", "", "90909", 12],
["11-7-2153", "Nathan", "Shepard", "", "", "", "", "90909", 13],
["01-10-1986", "Jane", "Smith", "", "", "", "", "12345", 14],
["12-12-1992", "Daphne", "Walker", "", "", "", "", "23456", 18],
["1-1-1980", "Alejandro", "Villanueve", "", "", "", "", "15935", 23],
["1-1-1980", "Alejandro", "Villanueva", "", "", "", "", "15935", 24],
["2-2-1990", "Philip", "", "", "", "", "", "64873", 27],
["1-1-1980", "Alejandr", "Villanueve", "", "", "", "", "15935", 31],
["1-1-1980", "Aelxdrano", "Villanueve", "", "", "", "", "15935", 32],
]
return patient_data


def generate_eicr_results():
eicr_result = {
"root": "2.16.840.1.113883.9.9.9.9.9",
"extension": "db734647-fc99-424c-a864-7e3cda82e704",
}
return eicr_result


def generate_ecr_msg_ids():
msg_ids = {
"internal_message": {"id1": ["ID1"], "id2": "SecondID"},
"external_id": ["extID"],
"last_id": "123",
}
return msg_ids
11 changes: 3 additions & 8 deletions tests/validation/test_validation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pathlib

import yaml
from tests.test_data_generator import generate_eicr_results
from phdi.validation.validation import validate_ecr


Expand Down Expand Up @@ -211,10 +212,7 @@ def test_custom_error_messages():


def test_validate_good_with_rr_data():
eicr_result = {
"root": "2.16.840.1.113883.9.9.9.9.9",
"extension": "db734647-fc99-424c-a864-7e3cda82e704",
}
eicr_result = generate_eicr_results()
rr_result = {
"root": "4efa0e5c-c34c-429f-b5de-f1a13aef4a28",
"extension": None,
Expand All @@ -238,10 +236,7 @@ def test_validate_good_with_rr_data():


def test_validate_with_rr_data_missing_rr():
eicr_result = {
"root": "2.16.840.1.113883.9.9.9.9.9",
"extension": "db734647-fc99-424c-a864-7e3cda82e704",
}
eicr_result = generate_eicr_results()

expected_response = {
"message_valid": False,
Expand Down
14 changes: 3 additions & 11 deletions tests/validation/test_validation_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
_clear_all_errors_and_ids,
ERROR_MESSAGES,
)

from tests.test_data_generator import generate_ecr_msg_ids

test_include_errors = ["fatal", "errors", "warnings", "information"]

Expand Down Expand Up @@ -211,11 +211,7 @@ def test_append_error_message():
def test_add_message_ids():
_clear_all_errors_and_ids()
# first let's test with a proper dict
msg_ids = {
"internal_message": {"id1": ["ID1"], "id2": "SecondID"},
"external_id": ["extID"],
"last_id": "123",
}
msg_ids = generate_ecr_msg_ids()
expected_result = {
"fatal": [],
"errors": [],
Expand Down Expand Up @@ -243,11 +239,7 @@ def test_add_message_ids():
def test_clear_all_errors_and_ids():
# first let's load up all errors and msg ids
# and clear them out and make sure they are clear
msg_ids = {
"internal_message": {"id1": ["ID1"], "id2": "SecondID"},
"external_id": ["extID"],
"last_id": "123",
}
msg_ids = generate_ecr_msg_ids()
fatal = ["foo"]
errors = ["my error1", "my_error2"]
warns = ["my warn1"]
Expand Down

0 comments on commit 7578190

Please sign in to comment.