-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
66 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,11 @@ | |
from daily_read import daily_report, config, ngi_data, order_portal | ||
|
||
|
||
def test_write_report_to_out_dir(data_repo_full, mock_project_data_record, create_report_path): | ||
def test_write_report_to_out_dir(data_repo_full, mock_project_data_record, create_report_path, get_env_file_path): | ||
"""Test existence of html report when provided with out_dir""" | ||
orderer = "[email protected]" | ||
order_id = "NGI123456" | ||
config_values = config.Config() | ||
config_values = config.Config(env_file_path=get_env_file_path) | ||
daily_rep = daily_report.DailyReport() | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
|
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 |
---|---|---|
|
@@ -9,9 +9,9 @@ | |
####################################################### TESTS ######################################################### | ||
|
||
|
||
def test_create_project_data_master(data_repo_full): | ||
def test_create_project_data_master(data_repo_full, get_env_file_path): | ||
"""With existing git repo, test creation of a ProjectDataMaster class""" | ||
config_values = config.Config() | ||
config_values = config.Config(get_env_file_path) | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
|
||
|
@@ -21,9 +21,9 @@ def test_create_project_data_master(data_repo_full): | |
assert data_master._data_fetched == False | ||
|
||
|
||
def test_create_project_data_master_no_commit(data_repo_no_commit): | ||
def test_create_project_data_master_no_commit(data_repo_no_commit, get_env_file_path): | ||
"""With existing git repo but without commits, test creation of a ProjectDataMaster class""" | ||
config_values = config.Config() | ||
config_values = config.Config(get_env_file_path) | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
|
||
|
@@ -35,8 +35,8 @@ def test_create_project_data_master_no_commit(data_repo_no_commit): | |
assert data_master.data_repo.commit().message == "Empty file as a first commit" | ||
|
||
|
||
def test_modified_or_new_no_commit(data_repo_no_commit): | ||
config_values = config.Config() | ||
def test_modified_or_new_no_commit(data_repo_no_commit, get_env_file_path): | ||
config_values = config.Config(get_env_file_path) | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
|
||
|
@@ -47,8 +47,8 @@ def test_modified_or_new_no_commit(data_repo_no_commit): | |
assert len(set(file_names)) == 0 | ||
|
||
|
||
def test_modified_or_new(data_repo_full): | ||
config_values = config.Config() | ||
def test_modified_or_new(data_repo_full, get_env_file_path): | ||
config_values = config.Config(get_env_file_path) | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
|
||
|
@@ -59,8 +59,8 @@ def test_modified_or_new(data_repo_full): | |
assert len(set(file_names)) == 12 | ||
|
||
|
||
def test_modified_or_new_untracked(data_repo_untracked): | ||
config_values = config.Config() | ||
def test_modified_or_new_untracked(data_repo_untracked, get_env_file_path): | ||
config_values = config.Config(get_env_file_path) | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
|
||
|
@@ -73,8 +73,8 @@ def test_modified_or_new_untracked(data_repo_untracked): | |
assert "untracked_file" in file_names[0] | ||
|
||
|
||
def test_modified_or_new_staged(data_repo_new_staged): | ||
config_values = config.Config() | ||
def test_modified_or_new_staged(data_repo_new_staged,get_env_file_path): | ||
config_values = config.Config(get_env_file_path) | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
|
||
|
@@ -86,8 +86,8 @@ def test_modified_or_new_staged(data_repo_new_staged): | |
assert any("staged_file" in s for s in file_names) | ||
|
||
|
||
def test_modified_or_new_modified_not_staged(data_repo_modified_not_staged): | ||
config_values = config.Config() | ||
def test_modified_or_new_modified_not_staged(data_repo_modified_not_staged, get_env_file_path): | ||
config_values = config.Config(get_env_file_path) | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
|
||
|
@@ -100,8 +100,8 @@ def test_modified_or_new_modified_not_staged(data_repo_modified_not_staged): | |
assert "modified_file" in file_names[0] | ||
|
||
|
||
def test_modified_or_new_modified_staged(data_repo_modified_staged): | ||
config_values = config.Config() | ||
def test_modified_or_new_modified_staged(data_repo_modified_staged, get_env_file_path): | ||
config_values = config.Config(get_env_file_path) | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
|
||
|
@@ -114,8 +114,8 @@ def test_modified_or_new_modified_staged(data_repo_modified_staged): | |
assert "modified_staged_file" in file_names[0] | ||
|
||
|
||
def test_modified_or_new_tracked(data_repo_tracked): | ||
config_values = config.Config() | ||
def test_modified_or_new_tracked(data_repo_tracked, get_env_file_path): | ||
config_values = config.Config(get_env_file_path) | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
|
||
|
@@ -127,19 +127,19 @@ def test_modified_or_new_tracked(data_repo_tracked): | |
assert len(set(file_names)) == 0 | ||
|
||
|
||
def test_get_unique_orderers(data_repo_full): | ||
def test_get_unique_orderers(data_repo_full, get_env_file_path): | ||
"""Test getting unique orders in the project data from statusdb""" | ||
config_values = config.Config() | ||
config_values = config.Config(get_env_file_path) | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
data_master.get_data() | ||
orderers = data_master.find_unique_orderers() | ||
assert orderers == set(["[email protected]"]) | ||
|
||
|
||
def test_user_list(data_repo_full, tmp_path, mocked_statusdb_conn_rows): | ||
def test_user_list(data_repo_full, tmp_path, mocked_statusdb_conn_rows, get_env_file_path): | ||
"""Test getting and reading users from the user list url""" | ||
config_values = config.Config() | ||
config_values = config.Config(get_env_file_path) | ||
temp_file = tmp_path / "test_file.txt" | ||
temp_file.write_text("[email protected]\n[email protected]") | ||
config_values.USERS_LIST_LOCATION = temp_file | ||
|
@@ -154,9 +154,9 @@ def test_user_list(data_repo_full, tmp_path, mocked_statusdb_conn_rows): | |
assert orderers == set(["[email protected]", "[email protected]"]) | ||
|
||
|
||
def test_save_data_to_disk(data_repo_full, mocked_statusdb_conn_rows): | ||
def test_save_data_to_disk(data_repo_full, mocked_statusdb_conn_rows, get_env_file_path): | ||
"""Test saving in git repo the data gotten from statusdb""" | ||
config_values = config.Config() | ||
config_values = config.Config(get_env_file_path) | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
data_master.sources[0].statusdb_session.rows.return_value = mocked_statusdb_conn_rows | ||
|
@@ -166,9 +166,9 @@ def test_save_data_to_disk(data_repo_full, mocked_statusdb_conn_rows): | |
assert os.path.exists(os.path.join(config_values.DATA_LOCATION, "NGIS/2023/NGI123458.json")) | ||
|
||
|
||
def test_get_data_with_project(data_repo_full, mocked_statusdb_conn_rows): | ||
def test_get_data_with_project(data_repo_full, mocked_statusdb_conn_rows, get_env_file_path): | ||
"""Test getting data for a specific order""" | ||
config_values = config.Config() | ||
config_values = config.Config(get_env_file_path) | ||
order_id = "NGI123457" | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
|
@@ -179,9 +179,9 @@ def test_get_data_with_project(data_repo_full, mocked_statusdb_conn_rows): | |
assert data_master.data[order_id].internal_id_or_portal_id == "P123457" | ||
|
||
|
||
def test_get_data_with_project_unknown(data_repo_full, mocked_statusdb_conn_rows): | ||
def test_get_data_with_project_unknown(data_repo_full, mocked_statusdb_conn_rows, get_env_file_path): | ||
"""Test error thrown when the order specified is not found in statusdb""" | ||
config_values = config.Config() | ||
config_values = config.Config(get_env_file_path) | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
data_master.sources[0].statusdb_session.rows.return_value = mocked_statusdb_conn_rows | ||
|
@@ -190,9 +190,9 @@ def test_get_data_with_project_unknown(data_repo_full, mocked_statusdb_conn_rows | |
|
||
|
||
@mock.patch("daily_read.statusdb.StatusDBSession") | ||
def test_data_loc_not_abs(mock_status): | ||
def test_data_loc_not_abs(mock_status, get_env_file_path): | ||
"""Test error thrown when given data location is not an absolute path""" | ||
config_values = config.Config() | ||
config_values = config.Config(get_env_file_path) | ||
config_values.DATA_LOCATION = "tests/test_data_location" | ||
with pytest.raises( | ||
ValueError, match=f"Data location is not an absolute path: {config_values.DATA_LOCATION}" | ||
|
@@ -201,9 +201,9 @@ def test_data_loc_not_abs(mock_status): | |
|
||
|
||
@mock.patch("daily_read.statusdb.StatusDBSession") | ||
def test_data_loc_not_dir(mock_status, tmp_path): | ||
def test_data_loc_not_dir(mock_status, tmp_path, get_env_file_path): | ||
"""Test error thrown when data location is not a directory""" | ||
config_values = config.Config() | ||
config_values = config.Config(get_env_file_path) | ||
temp_file = tmp_path / "test_file.txt" | ||
temp_file.write_text("test") | ||
config_values.DATA_LOCATION = temp_file | ||
|
@@ -213,11 +213,11 @@ def test_data_loc_not_dir(mock_status, tmp_path): | |
ngi_data.ProjectDataMaster(config_values) | ||
|
||
|
||
def test_get_data_with_no_project_dates(data_repo_full, mocked_statusdb_conn_rows, caplog): | ||
def test_get_data_with_no_project_dates(data_repo_full, mocked_statusdb_conn_rows, caplog, get_env_file_path): | ||
"""Test log output when no project dates are found in statusdb for a specific project""" | ||
from copy import deepcopy | ||
|
||
config_values = config.Config() | ||
config_values = config.Config(get_env_file_path) | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
data_master.sources[0].statusdb_session.rows.return_value = mocked_statusdb_conn_rows | ||
|
@@ -232,10 +232,10 @@ def test_get_data_with_no_project_dates(data_repo_full, mocked_statusdb_conn_row | |
assert "No project dates found for NGI123459" in caplog.text | ||
|
||
|
||
def test_skip_order_with_no_year(data_repo_full, mocked_statusdb_conn_rows, caplog): | ||
def test_skip_order_with_no_year(data_repo_full, mocked_statusdb_conn_rows, caplog, get_env_file_path): | ||
"""Test that orders with no order year (i.e. with no contract signed) are skipped""" | ||
|
||
config_values = config.Config() | ||
config_values = config.Config(get_env_file_path) | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
data_master.sources[0].statusdb_session.rows.return_value = mocked_statusdb_conn_rows | ||
|
@@ -247,20 +247,20 @@ def test_skip_order_with_no_year(data_repo_full, mocked_statusdb_conn_rows, capl | |
|
||
|
||
@mock.patch("daily_read.statusdb.StatusDBSession") | ||
def test_no_source_specified(mock_status): | ||
def test_no_source_specified(mock_status, get_env_file_path): | ||
"""Test error thrown when no sources are specified""" | ||
|
||
config_values = config.Config() | ||
config_values = config.Config(get_env_file_path) | ||
config_values.FETCH_FROM_NGIS = "" | ||
config_values.FETCH_FROM_SNPSEQ = "" | ||
config_values.FETCH_FROM_UGC = "" | ||
with pytest.raises(ValueError, match="There are no sources specified to fetch data from!") as err: | ||
ngi_data.ProjectDataMaster(config_values) | ||
|
||
|
||
def test_commit_staged_data(data_repo_full, mocked_statusdb_conn_rows): | ||
def test_commit_staged_data(data_repo_full, mocked_statusdb_conn_rows, get_env_file_path): | ||
"""Test file is staged for commit and committed and then try adding it for staging again""" | ||
config_values = config.Config() | ||
config_values = config.Config(get_env_file_path) | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
data_master.sources[0].statusdb_session.rows.return_value = mocked_statusdb_conn_rows | ||
|
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 |
---|---|---|
|
@@ -7,11 +7,11 @@ | |
from daily_read import order_portal, config, ngi_data | ||
|
||
|
||
def test_get_and_process_orders_open_upload_fail(data_repo_full, mock_project_data_record, caplog): | ||
def test_get_and_process_orders_open_upload_fail(data_repo_full, mock_project_data_record, caplog, get_env_file_path): | ||
"""Test getting and processing an open order and upload to Order portal failing""" | ||
orderer = "[email protected]" | ||
order_id = "NGI123456" | ||
config_values = config.Config() | ||
config_values = config.Config(get_env_file_path) | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
|
||
|
@@ -32,11 +32,11 @@ def test_get_and_process_orders_open_upload_fail(data_repo_full, mock_project_da | |
assert f"Report not uploaded for order with project id: {order_id}\nReason: 404" in caplog.text | ||
|
||
|
||
def test_get_and_process_orders_open_and_upload(data_repo_full, mock_project_data_record): | ||
def test_get_and_process_orders_open_and_upload(data_repo_full, mock_project_data_record, get_env_file_path): | ||
"""Test getting and processing an open order and uploading its Project progress report and uploading the report to the Order portal""" | ||
orderer = "[email protected]" | ||
order_id = "NGI123456" | ||
config_values = config.Config() | ||
config_values = config.Config(get_env_file_path) | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
|
||
|
@@ -69,11 +69,11 @@ def test_get_and_process_orders_open_and_upload(data_repo_full, mock_project_dat | |
) | ||
|
||
|
||
def test_get_and_process_orders_open_with_report_and_upload(data_repo_full, mock_project_data_record, caplog): | ||
def test_get_and_process_orders_open_with_report_and_upload(data_repo_full, mock_project_data_record, caplog, get_env_file_path): | ||
"""Test getting, processing an open order with an existing Project progress report and uploading the report to the Order portal""" | ||
orderer = "[email protected]" | ||
order_id = "NGI123453" | ||
config_values = config.Config() | ||
config_values = config.Config(get_env_file_path) | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
|
||
|
@@ -109,11 +109,11 @@ def test_get_and_process_orders_open_with_report_and_upload(data_repo_full, mock | |
assert f"Updated report for order with project id: {order_id}" in caplog.text | ||
|
||
|
||
def test_get_and_process_orders_open_to_aborted_with_report_and_upload(data_repo_full, mock_project_data_record): | ||
def test_get_and_process_orders_open_to_aborted_with_report_and_upload(data_repo_full, mock_project_data_record, get_env_file_path): | ||
"""Test getting, processing an open order with an existing Project progress report and uploading the report to the Order portal""" | ||
orderer = "[email protected]" | ||
order_id = "NGI123461" | ||
config_values = config.Config() | ||
config_values = config.Config(get_env_file_path) | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
|
||
|
@@ -142,11 +142,11 @@ def test_get_and_process_orders_open_to_aborted_with_report_and_upload(data_repo | |
) | ||
|
||
|
||
def test_get_and_process_orders_closed(data_repo_full, mock_project_data_record): | ||
def test_get_and_process_orders_closed(data_repo_full, mock_project_data_record, get_env_file_path): | ||
"""Test getting and processing an order closed within the timeframe of Project progress report deletion""" | ||
orderer = "[email protected]" | ||
order_id = "NGI123455" | ||
config_values = config.Config() | ||
config_values = config.Config(get_env_file_path) | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
|
||
|
@@ -160,11 +160,11 @@ def test_get_and_process_orders_closed(data_repo_full, mock_project_data_record) | |
assert modified_orders[orderer]["delete_report_for"]["All Raw data Delivered"][0] == data_master.data[order_id] | ||
|
||
|
||
def test_get_and_process_orders_mult_reports(data_repo_full, mock_project_data_record): | ||
def test_get_and_process_orders_mult_reports(data_repo_full, mock_project_data_record, get_env_file_path): | ||
"""Test getting and processing orders with multiple Project progress reports""" | ||
orderer = "[email protected]" | ||
order_id = "NGI123454" | ||
config_values = config.Config() | ||
config_values = config.Config(get_env_file_path) | ||
with mock.patch("daily_read.statusdb.StatusDBSession"): | ||
data_master = ngi_data.ProjectDataMaster(config_values) | ||
|
||
|
@@ -180,10 +180,10 @@ def test_get_and_process_orders_mult_reports(data_repo_full, mock_project_data_r | |
op.process_orders(config_values.STATUS_PRIORITY_REV) | ||
|
||
|
||
def test_base_url_and_api_key_not_set(data_repo_full, mock_project_data_record): | ||
def test_base_url_and_api_key_not_set(data_repo_full, mock_project_data_record, get_env_file_path): | ||
"""Test the conditions when environment variables ORDER_PORTAL_URL and ORDER_PORTAL_API_KEY are not set""" | ||
order_id = "NGI123456" | ||
config_values = config.Config() | ||
config_values = config.Config(get_env_file_path) | ||
|
||
order_portal_url = config_values.ORDER_PORTAL_URL | ||
api_key = config_values.ORDER_PORTAL_API_KEY | ||
|
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