|
10 | 10 | upload_config_file, |
11 | 11 | generate_csv_with_ordered_100000_rows, |
12 | 12 | verify_final_ack_file, |
| 13 | + delete_file_from_s3 |
13 | 14 | ) |
| 15 | + |
14 | 16 | from constants import ( |
15 | 17 | SOURCE_BUCKET, |
16 | 18 | INPUT_PREFIX, |
|
19 | 21 | POST_VALIDATION_ERROR, |
20 | 22 | DUPLICATE, |
21 | 23 | FILE_NAME_VAL_ERROR, |
22 | | - env_value |
| 24 | + environment |
23 | 25 | ) |
24 | 26 |
|
25 | 27 |
|
26 | 28 | class TestE2EBatch(unittest.TestCase): |
27 | | - if env_value != "ref": |
| 29 | + def setUp(self): |
| 30 | + self.uploaded_files = [] # Tracks uploaded input keys |
| 31 | + self.ack_files = [] # Tracks ack keys |
| 32 | + |
| 33 | + def tearDown(self): |
| 34 | + for file_key in self.uploaded_files: |
| 35 | + delete_file_from_s3(SOURCE_BUCKET, file_key) |
| 36 | + for ack_key in self.ack_files: |
| 37 | + delete_file_from_s3(ACK_BUCKET, ack_key) |
28 | 38 |
|
| 39 | + if environment != "ref": |
29 | 40 | def test_create_success(self): |
30 | 41 | """Test CREATE scenario.""" |
31 | 42 | input_file = generate_csv("PHYLIS", "0.3", action_flag="CREATE") |
32 | | - upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 43 | + |
| 44 | + key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 45 | + self.uploaded_files.append(key) |
| 46 | + |
33 | 47 | ack_key = wait_for_ack_file(None, input_file) |
| 48 | + self.ack_files.append(ack_key) |
| 49 | + |
34 | 50 | validate_row_count(input_file, ack_key) |
| 51 | + |
35 | 52 | ack_content = get_file_content_from_s3(ACK_BUCKET, ack_key) |
36 | 53 | check_ack_file_content(ack_content, "OK", None, "CREATE") |
37 | 54 |
|
38 | 55 | def test_duplicate_create(self): |
39 | 56 | """Test DUPLICATE scenario.""" |
| 57 | + |
40 | 58 | input_file = generate_csv("PHYLIS", "0.3", action_flag="CREATE", same_id=True) |
41 | | - upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 59 | + |
| 60 | + key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 61 | + self.uploaded_files.append(key) |
| 62 | + |
42 | 63 | ack_key = wait_for_ack_file(None, input_file) |
| 64 | + self.ack_files.append(ack_key) |
| 65 | + |
43 | 66 | validate_row_count(input_file, ack_key) |
| 67 | + |
44 | 68 | ack_content = get_file_content_from_s3(ACK_BUCKET, ack_key) |
45 | 69 | check_ack_file_content(ack_content, "Fatal Error", DUPLICATE, "CREATE") |
46 | 70 |
|
47 | 71 | def test_update_success(self): |
48 | 72 | """Test UPDATE scenario.""" |
49 | 73 | input_file = generate_csv("PHYLIS", "0.5", action_flag="UPDATE") |
50 | | - upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 74 | + |
| 75 | + key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 76 | + self.uploaded_files.append(key) |
| 77 | + |
51 | 78 | ack_key = wait_for_ack_file(None, input_file) |
| 79 | + self.ack_files.append(ack_key) |
| 80 | + |
52 | 81 | validate_row_count(input_file, ack_key) |
| 82 | + |
53 | 83 | ack_content = get_file_content_from_s3(ACK_BUCKET, ack_key) |
54 | 84 | check_ack_file_content(ack_content, "OK", None, "UPDATE") |
55 | 85 |
|
56 | 86 | def test_reinstated_success(self): |
57 | 87 | """Test REINSTATED scenario.""" |
58 | 88 | input_file = generate_csv("PHYLIS", "0.5", action_flag="REINSTATED") |
59 | | - upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 89 | + |
| 90 | + key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 91 | + self.uploaded_files.append(key) |
| 92 | + |
60 | 93 | ack_key = wait_for_ack_file(None, input_file) |
| 94 | + self.ack_files.append(ack_key) |
| 95 | + |
61 | 96 | validate_row_count(input_file, ack_key) |
| 97 | + |
62 | 98 | ack_content = get_file_content_from_s3(ACK_BUCKET, ack_key) |
63 | 99 | check_ack_file_content(ack_content, "OK", None, "reinstated") |
64 | 100 |
|
65 | 101 | def test_update_reinstated_success(self): |
66 | 102 | """Test UPDATE-REINSTATED scenario.""" |
67 | 103 | input_file = generate_csv("PHYLIS", "0.5", action_flag="UPDATE-REINSTATED") |
68 | | - upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 104 | + |
| 105 | + key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 106 | + self.uploaded_files.append(key) |
| 107 | + |
69 | 108 | ack_key = wait_for_ack_file(None, input_file) |
| 109 | + self.ack_files.append(ack_key) |
| 110 | + |
70 | 111 | validate_row_count(input_file, ack_key) |
| 112 | + |
71 | 113 | ack_content = get_file_content_from_s3(ACK_BUCKET, ack_key) |
72 | 114 | check_ack_file_content(ack_content, "OK", None, "update-reinstated") |
73 | 115 |
|
74 | 116 | def test_delete_success(self): |
75 | 117 | """Test DELETE scenario.""" |
76 | 118 | input_file = generate_csv("PHYLIS", "0.8", action_flag="DELETE") |
77 | | - upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 119 | + |
| 120 | + key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 121 | + self.uploaded_files.append(key) |
| 122 | + |
78 | 123 | ack_key = wait_for_ack_file(None, input_file) |
| 124 | + self.ack_files.append(ack_key) |
| 125 | + |
79 | 126 | validate_row_count(input_file, ack_key) |
| 127 | + |
80 | 128 | ack_content = get_file_content_from_s3(ACK_BUCKET, ack_key) |
81 | 129 | check_ack_file_content(ack_content, "OK", None, "DELETE") |
82 | 130 |
|
83 | 131 | def test_pre_validation_error(self): |
84 | 132 | """Test PRE-VALIDATION error scenario.""" |
85 | 133 | input_file = generate_csv("PHYLIS", "TRUE", action_flag="CREATE") |
86 | | - upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 134 | + |
| 135 | + key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 136 | + self.uploaded_files.append(key) |
| 137 | + |
87 | 138 | ack_key = wait_for_ack_file(None, input_file) |
| 139 | + self.ack_files.append(ack_key) |
| 140 | + |
88 | 141 | validate_row_count(input_file, ack_key) |
| 142 | + |
89 | 143 | ack_content = get_file_content_from_s3(ACK_BUCKET, ack_key) |
90 | 144 | check_ack_file_content(ack_content, "Fatal Error", PRE_VALIDATION_ERROR, None) |
91 | 145 |
|
92 | 146 | def test_post_validation_error(self): |
93 | 147 | """Test POST-VALIDATION error scenario.""" |
94 | 148 | input_file = generate_csv("", "0.3", action_flag="CREATE") |
95 | | - upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 149 | + |
| 150 | + key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 151 | + self.uploaded_files.append(key) |
| 152 | + |
96 | 153 | ack_key = wait_for_ack_file(None, input_file) |
| 154 | + self.ack_files.append(ack_key) |
| 155 | + |
97 | 156 | ack_content = get_file_content_from_s3(ACK_BUCKET, ack_key) |
98 | 157 | check_ack_file_content(ack_content, "Fatal Error", POST_VALIDATION_ERROR, None) |
99 | 158 |
|
100 | 159 | def test_file_name_validation_error(self): |
101 | 160 | """Test FILE-NAME-VALIDATION error scenario.""" |
102 | 161 | input_file = generate_csv("PHYLIS", "0.3", action_flag="CREATE", file_key=True) |
103 | | - upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 162 | + |
| 163 | + key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 164 | + self.uploaded_files.append(key) |
| 165 | + |
104 | 166 | ack_key = wait_for_ack_file(True, input_file) |
| 167 | + self.ack_files.append(ack_key) |
| 168 | + |
105 | 169 | ack_content = get_file_content_from_s3(ACK_BUCKET, ack_key) |
106 | 170 | check_ack_file_content(ack_content, "Failure", FILE_NAME_VAL_ERROR, None) |
107 | 171 |
|
108 | 172 | def test_header_name_validation_error(self): |
109 | 173 | """Test HEADER-NAME-VALIDATION error scenario.""" |
110 | 174 | input_file = generate_csv("PHYLIS", "0.3", action_flag="CREATE", headers="NH_NUMBER") |
111 | | - upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 175 | + |
| 176 | + key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 177 | + self.uploaded_files.append(key) |
| 178 | + |
112 | 179 | ack_key = wait_for_ack_file(True, input_file) |
| 180 | + self.ack_files.append(ack_key) |
| 181 | + |
113 | 182 | ack_content = get_file_content_from_s3(ACK_BUCKET, ack_key) |
114 | 183 | check_ack_file_content(ack_content, "Failure", FILE_NAME_VAL_ERROR, None) |
115 | 184 |
|
| 185 | + # This test updates the permissions_config.json file from the imms-internal-dev-supplier-config |
| 186 | + # S3 bucket shared across multiple environments (PR environments, internal-dev, int, and ref). |
| 187 | + # Running this may modify permissions in these environments, causing unintended side effects. |
| 188 | + @unittest.skip("Modifies shared S3 permissions configuration") |
116 | 189 | def test_invalid_permission(self): |
117 | 190 | """Test INVALID-PERMISSION error scenario.""" |
118 | | - upload_config_file("MMR_FULL") |
| 191 | + upload_config_file("MMR_FULL") # permissions_config.json is updated here |
119 | 192 | time.sleep(20) |
| 193 | + |
120 | 194 | input_file = generate_csv("PHYLIS", "0.3", action_flag="CREATE") |
121 | | - upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 195 | + |
| 196 | + key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 197 | + self.uploaded_files.append(key) |
| 198 | + |
122 | 199 | ack_key = wait_for_ack_file(True, input_file) |
| 200 | + self.ack_files.append(ack_key) |
| 201 | + |
123 | 202 | ack_content = get_file_content_from_s3(ACK_BUCKET, ack_key) |
124 | 203 | check_ack_file_content(ack_content, "Failure", FILE_NAME_VAL_ERROR, None) |
| 204 | + |
125 | 205 | upload_config_file("COVID19_FULL") |
126 | 206 | time.sleep(20) |
127 | 207 |
|
128 | 208 | else: |
129 | | - |
130 | 209 | def test_end_to_end_speed_test_with_100000_rows(self): |
131 | 210 | """Test end_to_end_speed_test_with_100000_rows scenario with full integration""" |
132 | 211 | input_file = generate_csv_with_ordered_100000_rows(None) |
133 | | - upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 212 | + |
| 213 | + key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
| 214 | + self.uploaded_files.append(key) |
| 215 | + |
134 | 216 | final_ack_key = wait_for_ack_file(None, input_file, timeout=1800) |
| 217 | + self.ack_files.append(final_ack_key) |
| 218 | + |
135 | 219 | response = verify_final_ack_file(final_ack_key) |
136 | 220 | assert response is True |
137 | 221 |
|
|
0 commit comments