-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* DPTS-1096 Add int tests for stt * DPTS-1096 Correct sql script * DPTS-1096 Adjust assertions post test * DPTS-1096 Fix broken tests
- Loading branch information
1 parent
f8b95c2
commit 682e5d9
Showing
9 changed files
with
197 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from utilities import logger, database | ||
|
||
# Note | ||
# db tables are scenarios and scenariobundles | ||
# See test-data.sql (clears down all bundles/scenarios0 and test/integration/test-files/36.2.0_stt.zip | ||
# Will test | ||
# That there is only one record in scenarionbundlees table | ||
|
||
expected_stt_bundle_name = '36.2.0' | ||
|
||
expected_disposition_id = 1 | ||
expected_disposition_group_id = 18 | ||
expected_scenario_id = 893 | ||
expected_symptomgroup_id = 1014 | ||
expected_symptom_discriminator_id = 4499 | ||
expected_age_id = 1 | ||
expected_gender_id = 2 | ||
|
||
|
||
def get_stt_scenario_data(env, db_connection): | ||
"""Returns expected data on all stt scenario bundles and scenarios within bundles""" | ||
result_set = {} | ||
try: | ||
query = create_stt_scenarios_query() | ||
result_set = database.execute_resultset_query(env, db_connection, query, ()) | ||
except Exception as e: | ||
logger.log_for_error( | ||
env, | ||
"Error checking results for {0} => {1}".format("referral roles", str(e)), | ||
) | ||
return result_set | ||
|
||
def create_stt_scenarios_query(): | ||
query = ("""select sb.name, s.scenarioid, s.symptomgroupid, s.dispositionid, s.dispositiongroupid, s.symptomdiscriminatorid, | ||
s.ageid, s.genderid | ||
from scenariobundles sb | ||
join scenarios s | ||
on s.scenariobundleid = sb.id""" | ||
) | ||
return query | ||
|
||
def check_scenario_data_item(env, scenario, column_name, expected_value): | ||
ok = True | ||
if scenario[column_name] != expected_value: | ||
ok = False | ||
logger.log_for_audit( | ||
env, | ||
"Column name {0} set to {1} and not expected value of {2}".format(column_name,scenario[column_name],expected_value), | ||
) | ||
return ok | ||
|
||
|
||
def check_stt_scenario_data(env, db_connection): | ||
"""Returns True if single record in resultset and all checks pass ; otherwise returns False""" | ||
flags = [] | ||
result_set = get_stt_scenario_data(env, db_connection) | ||
for scenario in result_set: | ||
flags.append(check_scenario_data_item(env, scenario, "name", expected_stt_bundle_name)) | ||
flags.append(check_scenario_data_item(env, scenario, "scenarioid", expected_scenario_id)) | ||
flags.append(check_scenario_data_item(env, scenario, "dispositionid", expected_disposition_id)) | ||
flags.append(check_scenario_data_item(env, scenario, "dispositiongroupid", expected_disposition_group_id)) | ||
flags.append(check_scenario_data_item(env, scenario, "symptomgroupid", expected_symptomgroup_id)) | ||
flags.append(check_scenario_data_item(env, scenario, "symptomdiscriminatorid", expected_symptom_discriminator_id)) | ||
flags.append(check_scenario_data_item(env, scenario, "ageid", expected_age_id)) | ||
flags.append(check_scenario_data_item(env, scenario, "genderid", expected_gender_id)) | ||
if len(flags)==0: | ||
flags.append(False) | ||
return all(flags) | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from unittest.mock import Mock, patch | ||
import pytest | ||
import string | ||
import psycopg2 | ||
|
||
from models import stt | ||
|
||
file_path = "application.models.stt" | ||
env = 'unittest' | ||
|
||
@patch("psycopg2.connect") | ||
@patch(f"{file_path}.database.execute_resultset_query", return_value = [{"name":'36.2.0',"ageid":1,"genderid":2,"scenarioid":893,"symptomgroupid":1014, "dispositionid":1, "dispositiongroupid":18, "symptomdiscriminatorid":4499}]) | ||
def test_check_stt_expected(mock_db, mock_resultset): | ||
assert stt.check_stt_scenario_data(env, mock_db) == True | ||
|
||
@patch("psycopg2.connect") | ||
@patch(f"{file_path}.database.execute_resultset_query", return_value = [{"name":'36.3.0',"ageid":1,"genderid":2,"scenarioid":893,"symptomgroupid":1014, "dispositionid":1, "dispositiongroupid":18, "symptomdiscriminatorid":4499}]) | ||
def test_check_stt_wrong_name(mock_db, mock_resultset): | ||
assert stt.check_stt_scenario_data(env, mock_db) == False | ||
|
||
@patch("psycopg2.connect") | ||
@patch(f"{file_path}.database.execute_resultset_query", return_value = [{"name":'36.2.0',"ageid":2,"genderid":2,"scenarioid":893,"symptomgroupid":1014, "dispositionid":1, "dispositiongroupid":18, "symptomdiscriminatorid":4499}]) | ||
def test_check_stt_wrong_age(mock_db, mock_resultset): | ||
assert stt.check_stt_scenario_data(env, mock_db) == False | ||
|
||
@patch("psycopg2.connect") | ||
@patch(f"{file_path}.database.execute_resultset_query", return_value = [{"name":'36.2.0',"ageid":1,"genderid":1,"scenarioid":893,"symptomgroupid":1014, "dispositionid":1, "dispositiongroupid":18, "symptomdiscriminatorid":4499}]) | ||
def test_check_stt_wrong_gender(mock_db, mock_resultset): | ||
assert stt.check_stt_scenario_data(env, mock_db) == False | ||
|
||
@patch("psycopg2.connect") | ||
@patch(f"{file_path}.database.execute_resultset_query", return_value = [{"name":'36.2.0',"ageid":1,"genderid":2,"scenarioid":892,"symptomgroupid":1014, "dispositionid":1, "dispositiongroupid":18, "symptomdiscriminatorid":4499}]) | ||
def test_check_stt_wrong_scenarioid(mock_db, mock_resultset): | ||
assert stt.check_stt_scenario_data(env, mock_db) == False | ||
|
||
@patch("psycopg2.connect") | ||
@patch(f"{file_path}.database.execute_resultset_query", return_value = [{"name":'36.2.0',"ageid":1,"genderid":1,"scenarioid":893,"symptomgroupid":1015, "dispositionid":1, "dispositiongroupid":18, "symptomdiscriminatorid":4499}]) | ||
def test_check_stt_wrong_symptomgroupid(mock_db, mock_resultset): | ||
assert stt.check_stt_scenario_data(env, mock_db) == False | ||
|
||
@patch("psycopg2.connect") | ||
@patch(f"{file_path}.database.execute_resultset_query", return_value = [{"name":'36.2.0',"ageid":1,"genderid":2,"scenarioid":893,"symptomgroupid":1014, "dispositionid":2, "dispositiongroupid":18, "symptomdiscriminatorid":4499}]) | ||
def test_check_stt_wrong_dispositionid(mock_db, mock_resultset): | ||
assert stt.check_stt_scenario_data(env, mock_db) == False | ||
|
||
@patch("psycopg2.connect") | ||
@patch(f"{file_path}.database.execute_resultset_query", return_value = [{"name":'36.2.0',"ageid":1,"genderid":2,"scenarioid":893,"symptomgroupid":1014, "dispositionid":1, "dispositiongroupid":19, "symptomdiscriminatorid":4499}]) | ||
def test_check_stt_wrong_dispositiongroupid(mock_db, mock_resultset): | ||
assert stt.check_stt_scenario_data(env, mock_db) == False | ||
|
||
@patch("psycopg2.connect") | ||
@patch(f"{file_path}.database.execute_resultset_query", return_value = [{"name":'36.2.0',"ageid":1,"genderid":2,"scenarioid":893,"symptomgroupid":1014, "dispositionid":1, "dispositiongroupid":18, "symptomdiscriminatorid":4500}]) | ||
def test_check_stt_wrong_symptomdiscriminatorid(mock_db, mock_resultset): | ||
assert stt.check_stt_scenario_data(env, mock_db) == False | ||
|
||
@patch("psycopg2.connect") | ||
@patch(f"{file_path}.database.execute_resultset_query", return_value = []) | ||
def test_check_stt_empty_resultset(mock_db, mock_resultset): | ||
assert stt.check_stt_scenario_data(env, mock_db) == False | ||
|
||
@patch("psycopg2.connect") | ||
@patch(f"{file_path}.database.execute_resultset_query", return_value = [{"name":'36.2.1',"ageid":1,"genderid":2,"scenarioid":893,"symptomgroupid":1014, "dispositionid":1, "dispositiongroupid":18, "symptomdiscriminatorid":4499},{"name":'36.2.0',"ageid":1,"genderid":2,"scenarioid":893,"symptomgroupid":1014, "dispositionid":1, "dispositiongroupid":18, "symptomdiscriminatorid":4499}]) | ||
def test_two_records_first_wrong(mock_db, mock_resultset): | ||
assert stt.check_stt_scenario_data(env, mock_db) == False | ||
|
||
|
||
@patch("psycopg2.connect") | ||
@patch(f"{file_path}.database.execute_resultset_query", return_value = [{"name":'36.2.0',"ageid":1,"genderid":1,"scenarioid":893,"symptomgroupid":1014, "dispositionid":1, "dispositiongroupid":18, "symptomdiscriminatorid":4499},{"name":'36.2.3',"ageid":1,"genderid":2,"scenarioid":893,"symptomgroupid":1014, "dispositionid":1, "dispositiongroupid":18, "symptomdiscriminatorid":4500}]) | ||
def test_two_records_second_wrong(mock_db, mock_resultset): | ||
assert stt.check_stt_scenario_data(env, mock_db) == False | ||
|
||
@patch("psycopg2.connect") | ||
@patch(f"{file_path}.database.execute_resultset_query",side_effect=Exception) | ||
def test_get_stt_scenario_data(mock_resultset, mock_db): | ||
result_set = stt.get_stt_scenario_data(env,mock_db) | ||
assert result_set == {} |