From c79ce20f85cfeede4aa6c9a81dbb031dcc8b8b6e Mon Sep 17 00:00:00 2001 From: Cheshire Date: Mon, 28 Oct 2024 10:27:37 +0000 Subject: [PATCH] RDRP-781: mapper unit test --- tests/test_staging/test_staging_helpers.py | 54 ++-------------------- 1 file changed, 4 insertions(+), 50 deletions(-) diff --git a/tests/test_staging/test_staging_helpers.py b/tests/test_staging/test_staging_helpers.py index d0e9552f..f045578c 100644 --- a/tests/test_staging/test_staging_helpers.py +++ b/tests/test_staging/test_staging_helpers.py @@ -110,7 +110,7 @@ def test_getmappername(self): ), "getmappername not behaving as expected when split=False" -class TestLoadValidateMapper(object): +class TestLoadValidateMapper: """Tests for load_validate_mapper.""" @patch("src.utils.local_file_mods.rd_file_exists") @@ -122,7 +122,6 @@ def test_load_validate_mapper( mock_read_csv_func, mock_file_exists_func, ): - # Create a logger for this test test_logger = logging.getLogger("test_load_validate_mapper") test_logger.setLevel(logging.DEBUG) @@ -135,7 +134,7 @@ def test_load_validate_mapper( "test_mapper_path": "/path/to/mapper.csv" }, "global": { - "network_or_hdfs": "network", + "platform": "network", }, } @@ -153,6 +152,8 @@ def test_load_validate_mapper( mapper_path_key, config, test_logger, + mock_file_exists_func, + mock_read_csv_func, ) # Assertions @@ -181,53 +182,6 @@ def test_load_snapshot_feather(self, tmp_path): ), "Snapshot df has more columnss than expected." -class TestLoadValSnapshotJson(object): - """Tests for the load_val_snapshot_json function.""" - - @patch("src.utils.local_file_mods.rd_load_json") - @patch("src.staging.validation.validate_data_with_schema") - @patch("src.staging.spp_snapshot_processing.full_responses") - @patch("src.staging.validation.combine_schemas_validate_full_df") - def test_load_val_snapshot_json_correct_response_rate( - self, - mock_combine_schemas_validate_full_df, - mock_full_responses, - mock_validate_data_with_schema, - mock_load_json - ): - """Ensure load_val_snapshot_json behaves correctly.""" - snapshot_path = "path/to/snapshot.json" - network_or_hdfs = "network" - expected_res_rate = "0.50" - config = { - "global": {"dev_test": False}, - "schema_paths": { - "contributors_schema": "path/to/contributors_schema.toml", - "long_response_schema": "path/to/long_response_schema.toml", - "wide_responses_schema": "path/to/wide_responses_schema.toml", - }, - } - - # Setup mock return value - mock_load_json.return_value = { - "contributors": [{"reference": i} for i in range(1, 5)], - "responses": [{"reference": i} for i in range(1, 3)], - } - - # Execute the function under test - full_responses, res_rate = load_val_snapshot_json( - snapshot_path, mock_load_json, config, network_or_hdfs - ) - - # Assertions - assert ( - res_rate == expected_res_rate - ), "The response rate calculated by load_val_snapshot_json does not match the expected value." - mock_load_json.assert_called_once_with(snapshot_path) - mock_validate_data_with_schema.assert_called() - mock_combine_schemas_validate_full_df.assert_called() - - class TestDfToFeather(object): """Tests for df_to_Feather."""