|
4 | 4 | from unittest.mock import patch |
5 | 5 | from boto3 import client as boto3_client |
6 | 6 | from moto import mock_dynamodb |
| 7 | +from errors import UnhandledAuditTableError |
7 | 8 |
|
8 | 9 | from tests.utils_for_recordprocessor_tests.mock_environment_variables import MOCK_ENVIRONMENT_DICT |
9 | 10 | from tests.utils_for_recordprocessor_tests.generic_setup_and_teardown import GenericSetUp, GenericTearDown |
10 | | -from tests.utils_for_recordprocessor_tests.values_for_recordprocessor_tests import MockFileDetails |
| 11 | +from tests.utils_for_recordprocessor_tests.values_for_recordprocessor_tests import MockFileDetails, FileDetails |
11 | 12 | from tests.utils_for_recordprocessor_tests.utils_for_recordprocessor_tests import ( |
12 | 13 | deserialize_dynamodb_types, |
13 | 14 | add_entry_to_table, |
|
23 | 24 | from audit_table import get_next_queued_file_details, change_audit_table_status_to_processed |
24 | 25 | from clients import REGION_NAME |
25 | 26 |
|
| 27 | + |
26 | 28 | dynamodb_client = boto3_client("dynamodb", region_name=REGION_NAME) |
27 | 29 |
|
28 | 30 | FILE_DETAILS = MockFileDetails.ravs_rsv_1 |
@@ -75,17 +77,32 @@ def test_get_next_queued_file_details(self): |
75 | 77 |
|
76 | 78 | def test_change_audit_table_status_to_processed(self): |
77 | 79 | """Checks audit table correctly updates a record as processed""" |
| 80 | + # Test case 1: file should be updated with status of 'Processed'. |
78 | 81 |
|
79 | 82 | add_entry_to_table(MockFileDetails.rsv_ravs, file_status=FileStatus.QUEUED) |
80 | 83 | add_entry_to_table(MockFileDetails.flu_emis, file_status=FileStatus.QUEUED) |
81 | 84 | table_items = dynamodb_client.scan(TableName=AUDIT_TABLE_NAME).get("Items", []) |
82 | 85 |
|
83 | 86 | expected_table_entry = {**MockFileDetails.rsv_ravs.audit_table_entry, "status": {"S": FileStatus.PROCESSED}} |
84 | | - |
85 | | - file_key = "RSV_Vaccinations_v5_X26_20210730T12000000.csv" |
86 | | - message_id = "rsv_ravs_test_id_1" |
| 87 | + ravs_rsv_test_file = FileDetails("RSV", "RAVS", "X26") |
| 88 | + file_key = ravs_rsv_test_file.file_key |
| 89 | + message_id = ravs_rsv_test_file.message_id_order |
87 | 90 |
|
88 | 91 | change_audit_table_status_to_processed(file_key, message_id) |
89 | 92 | table_items = dynamodb_client.scan(TableName=AUDIT_TABLE_NAME).get("Items", []) |
90 | 93 |
|
91 | 94 | self.assertIn(expected_table_entry, table_items) |
| 95 | + |
| 96 | + # Test case 2: # Audit table status should not be updated. Error should be raised. |
| 97 | + emis_flu_test_file_2 = FileDetails("FLU", "EMIS", "YGM41") |
| 98 | + |
| 99 | + message_id = emis_flu_test_file_2.message_id |
| 100 | + file_key = (emis_flu_test_file_2.file_key,) |
| 101 | + with self.assertRaises(UnhandledAuditTableError): |
| 102 | + change_audit_table_status_to_processed(file_key, message_id) |
| 103 | + |
| 104 | + # Test case 3: # Audit table status should updated to processed for all values. |
| 105 | + message_id = emis_flu_test_file_2.message_id_order |
| 106 | + file_key = emis_flu_test_file_2.file_key |
| 107 | + change_audit_table_status_to_processed(file_key, message_id) |
| 108 | + table_items = dynamodb_client.scan(TableName=AUDIT_TABLE_NAME).get("Items", []) |
0 commit comments