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