|
1 | | -import time |
2 | 1 | import unittest |
3 | 2 | from utils import ( |
4 | | - generate_csv, |
5 | 3 | upload_file_to_s3, |
6 | 4 | get_file_content_from_s3, |
7 | 5 | wait_for_ack_file, |
8 | 6 | check_ack_file_content, |
9 | 7 | validate_row_count, |
10 | | - upload_config_file, |
11 | | - generate_csv_with_ordered_100000_rows, |
12 | | - verify_final_ack_file, |
13 | | - delete_file_from_s3 |
| 8 | + delete_file_from_s3, |
| 9 | + generate_csv_files, |
| 10 | + SeedTestData |
14 | 11 | ) |
15 | 12 |
|
16 | 13 | from constants import ( |
17 | 14 | SOURCE_BUCKET, |
18 | 15 | INPUT_PREFIX, |
19 | 16 | ACK_BUCKET, |
20 | | - PRE_VALIDATION_ERROR, |
21 | | - POST_VALIDATION_ERROR, |
22 | | - DUPLICATE, |
23 | | - FILE_NAME_VAL_ERROR, |
24 | 17 | environment |
25 | 18 | ) |
26 | 19 |
|
| 20 | +CREATE = "CREATE" |
| 21 | +UPDATE = "UPDATE" |
| 22 | +DELETE = "DELETE" |
| 23 | + |
| 24 | + |
| 25 | +ods_vaccines = { |
| 26 | + "DPSFULL": ["3IN1", "COVID19", "FLU", "HPV", "MENACWY", "MMR", "RSV"], |
| 27 | + "DPSREDUCED": ["3IN1", "COVID19", "FLU", "HPV", "MENACWY", "MMR", "RSV"], |
| 28 | + "V0V8L": ["3IN1", "FLU", "HPV", "MENACWY", "MMR"], |
| 29 | + "8HK48": ["FLU"], |
| 30 | + "8HA94": ["COVID19"], |
| 31 | + "X26": ["MMR", "RSV"], |
| 32 | + "X8E5B": ["MMR", "RSV"], |
| 33 | + "YGM41": ["3IN1", "COVID19", "HPV", "MENACWY", "MMR", "RSV"], |
| 34 | + "YGJ": ["3IN1", "COVID19", "HPV", "MENACWY", "MMR", "RSV"], |
| 35 | + "YGA": ["3IN1", "HPV", "MENACWY", "MMR", "RSV"], |
| 36 | + "YGMYW": ["3IN1", "HPV", "MENACWY", "MMR", "RSV"], |
| 37 | +} |
| 38 | + |
| 39 | +seed_datas = [ |
| 40 | + SeedTestData("Create", "V0V8L", [CREATE]), |
| 41 | + SeedTestData("Update", "8HK48", [CREATE, UPDATE]), |
| 42 | + SeedTestData("Delete", "8HA94", [CREATE, UPDATE, DELETE]), |
| 43 | + SeedTestData("Reinstate", "X26", [CREATE, DELETE, UPDATE]), |
| 44 | + SeedTestData("Update-Reinstate", "X8E5B", [CREATE, DELETE, UPDATE, UPDATE]), |
| 45 | + SeedTestData("Update-No Create", "YGM41", [UPDATE], success=False), |
| 46 | + SeedTestData("Delete-No Create", "YGJ", [DELETE], success=False), |
| 47 | + SeedTestData("Create with extended ascii characters in name", "YGA", [CREATE], inject_char=True), |
| 48 | +] |
| 49 | + |
27 | 50 |
|
28 | 51 | class TestE2EBatch(unittest.TestCase): |
29 | | - def setUp(self): |
30 | | - self.uploaded_files = [] # Tracks uploaded input keys |
31 | | - self.ack_files = [] # Tracks ack keys |
32 | 52 |
|
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) |
| 53 | + @unittest.skipIf(environment == "ref") |
| 54 | + def test_create_success(self): |
| 55 | + """Test CREATE scenario.""" |
38 | 56 |
|
39 | | - if environment != "ref": |
40 | | - def test_create_success(self): |
41 | | - """Test CREATE scenario.""" |
42 | | - input_file = generate_csv("PHYLIS", "0.3", action_flag="CREATE") |
| 57 | + test_datas = generate_csv_files(seed_datas) |
43 | 58 |
|
44 | | - key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
45 | | - self.uploaded_files.append(key) |
| 59 | + for test in test_datas: |
| 60 | + key = upload_file_to_s3(test.file_name, SOURCE_BUCKET, INPUT_PREFIX) |
| 61 | + test.key = key |
46 | 62 |
|
47 | | - ack_key = wait_for_ack_file(None, input_file) |
| 63 | + for test in test_datas: |
| 64 | + ack_key = wait_for_ack_file(None, test.file_name, ACK_BUCKET, timeout=1200) |
48 | 65 | self.ack_files.append(ack_key) |
49 | 66 |
|
50 | | - validate_row_count(input_file, ack_key) |
| 67 | + validate_row_count(test.file_name, ack_key) |
51 | 68 |
|
52 | 69 | ack_content = get_file_content_from_s3(ACK_BUCKET, ack_key) |
53 | 70 | check_ack_file_content(ack_content, "OK", None, "CREATE") |
54 | | - |
55 | | - def test_duplicate_create(self): |
56 | | - """Test DUPLICATE scenario.""" |
57 | | - |
58 | | - input_file = generate_csv("PHYLIS", "0.3", action_flag="CREATE", same_id=True) |
59 | | - |
60 | | - key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
61 | | - self.uploaded_files.append(key) |
62 | | - |
63 | | - ack_key = wait_for_ack_file(None, input_file) |
64 | | - self.ack_files.append(ack_key) |
65 | | - |
66 | | - validate_row_count(input_file, ack_key) |
67 | | - |
68 | | - ack_content = get_file_content_from_s3(ACK_BUCKET, ack_key) |
69 | | - check_ack_file_content(ack_content, "Fatal Error", DUPLICATE, "CREATE") |
70 | | - |
71 | | - def test_update_success(self): |
72 | | - """Test UPDATE scenario.""" |
73 | | - input_file = generate_csv("PHYLIS", "0.5", action_flag="UPDATE") |
74 | | - |
75 | | - key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
76 | | - self.uploaded_files.append(key) |
77 | | - |
78 | | - ack_key = wait_for_ack_file(None, input_file) |
79 | | - self.ack_files.append(ack_key) |
80 | | - |
81 | | - validate_row_count(input_file, ack_key) |
82 | | - |
83 | | - ack_content = get_file_content_from_s3(ACK_BUCKET, ack_key) |
84 | | - check_ack_file_content(ack_content, "OK", None, "UPDATE") |
85 | | - |
86 | | - def test_reinstated_success(self): |
87 | | - """Test REINSTATED scenario.""" |
88 | | - input_file = generate_csv("PHYLIS", "0.5", action_flag="REINSTATED") |
89 | | - |
90 | | - key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
91 | | - self.uploaded_files.append(key) |
92 | | - |
93 | | - ack_key = wait_for_ack_file(None, input_file) |
94 | | - self.ack_files.append(ack_key) |
95 | | - |
96 | | - validate_row_count(input_file, ack_key) |
97 | | - |
98 | | - ack_content = get_file_content_from_s3(ACK_BUCKET, ack_key) |
99 | | - check_ack_file_content(ack_content, "OK", None, "reinstated") |
100 | | - |
101 | | - def test_update_reinstated_success(self): |
102 | | - """Test UPDATE-REINSTATED scenario.""" |
103 | | - input_file = generate_csv("PHYLIS", "0.5", action_flag="UPDATE-REINSTATED") |
104 | | - |
105 | | - key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
106 | | - self.uploaded_files.append(key) |
107 | | - |
108 | | - ack_key = wait_for_ack_file(None, input_file) |
109 | | - self.ack_files.append(ack_key) |
110 | | - |
111 | | - validate_row_count(input_file, ack_key) |
112 | | - |
113 | | - ack_content = get_file_content_from_s3(ACK_BUCKET, ack_key) |
114 | | - check_ack_file_content(ack_content, "OK", None, "update-reinstated") |
115 | | - |
116 | | - def test_delete_success(self): |
117 | | - """Test DELETE scenario.""" |
118 | | - input_file = generate_csv("PHYLIS", "0.8", action_flag="DELETE") |
119 | | - |
120 | | - key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
121 | | - self.uploaded_files.append(key) |
122 | | - |
123 | | - ack_key = wait_for_ack_file(None, input_file) |
124 | | - self.ack_files.append(ack_key) |
125 | | - |
126 | | - validate_row_count(input_file, ack_key) |
127 | | - |
128 | | - ack_content = get_file_content_from_s3(ACK_BUCKET, ack_key) |
129 | | - check_ack_file_content(ack_content, "OK", None, "DELETE") |
130 | | - |
131 | | - def test_pre_validation_error(self): |
132 | | - """Test PRE-VALIDATION error scenario.""" |
133 | | - input_file = generate_csv("PHYLIS", "TRUE", action_flag="CREATE") |
134 | | - |
135 | | - key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
136 | | - self.uploaded_files.append(key) |
137 | | - |
138 | | - ack_key = wait_for_ack_file(None, input_file) |
139 | | - self.ack_files.append(ack_key) |
140 | | - |
141 | | - validate_row_count(input_file, ack_key) |
142 | | - |
143 | | - ack_content = get_file_content_from_s3(ACK_BUCKET, ack_key) |
144 | | - check_ack_file_content(ack_content, "Fatal Error", PRE_VALIDATION_ERROR, None) |
145 | | - |
146 | | - def test_post_validation_error(self): |
147 | | - """Test POST-VALIDATION error scenario.""" |
148 | | - input_file = generate_csv("", "0.3", action_flag="CREATE") |
149 | | - |
150 | | - key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
151 | | - self.uploaded_files.append(key) |
152 | | - |
153 | | - ack_key = wait_for_ack_file(None, input_file) |
154 | | - self.ack_files.append(ack_key) |
155 | | - |
156 | | - ack_content = get_file_content_from_s3(ACK_BUCKET, ack_key) |
157 | | - check_ack_file_content(ack_content, "Fatal Error", POST_VALIDATION_ERROR, None) |
158 | | - |
159 | | - def test_file_name_validation_error(self): |
160 | | - """Test FILE-NAME-VALIDATION error scenario.""" |
161 | | - input_file = generate_csv("PHYLIS", "0.3", action_flag="CREATE", file_key=True) |
162 | | - |
163 | | - key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
164 | | - self.uploaded_files.append(key) |
165 | | - |
166 | | - ack_key = wait_for_ack_file(True, input_file) |
167 | | - self.ack_files.append(ack_key) |
168 | | - |
169 | | - ack_content = get_file_content_from_s3(ACK_BUCKET, ack_key) |
170 | | - check_ack_file_content(ack_content, "Failure", FILE_NAME_VAL_ERROR, None) |
171 | | - |
172 | | - def test_header_name_validation_error(self): |
173 | | - """Test HEADER-NAME-VALIDATION error scenario.""" |
174 | | - input_file = generate_csv("PHYLIS", "0.3", action_flag="CREATE", headers="NH_NUMBER") |
175 | | - |
176 | | - key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
177 | | - self.uploaded_files.append(key) |
178 | | - |
179 | | - ack_key = wait_for_ack_file(True, input_file) |
180 | | - self.ack_files.append(ack_key) |
181 | | - |
182 | | - ack_content = get_file_content_from_s3(ACK_BUCKET, ack_key) |
183 | | - check_ack_file_content(ack_content, "Failure", FILE_NAME_VAL_ERROR, None) |
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") |
189 | | - def test_invalid_permission(self): |
190 | | - """Test INVALID-PERMISSION error scenario.""" |
191 | | - upload_config_file("MMR_FULL") # permissions_config.json is updated here |
192 | | - time.sleep(20) |
193 | | - |
194 | | - input_file = generate_csv("PHYLIS", "0.3", action_flag="CREATE") |
195 | | - |
196 | | - key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
197 | | - self.uploaded_files.append(key) |
198 | | - |
199 | | - ack_key = wait_for_ack_file(True, input_file) |
200 | | - self.ack_files.append(ack_key) |
201 | | - |
202 | | - ack_content = get_file_content_from_s3(ACK_BUCKET, ack_key) |
203 | | - check_ack_file_content(ack_content, "Failure", FILE_NAME_VAL_ERROR, None) |
204 | | - |
205 | | - upload_config_file("COVID19_FULL") |
206 | | - time.sleep(20) |
207 | | - |
208 | | - else: |
209 | | - def test_end_to_end_speed_test_with_100000_rows(self): |
210 | | - """Test end_to_end_speed_test_with_100000_rows scenario with full integration""" |
211 | | - input_file = generate_csv_with_ordered_100000_rows(None) |
212 | | - |
213 | | - key = upload_file_to_s3(input_file, SOURCE_BUCKET, INPUT_PREFIX) |
214 | | - self.uploaded_files.append(key) |
215 | | - |
216 | | - final_ack_key = wait_for_ack_file(None, input_file, timeout=1800) |
217 | | - self.ack_files.append(final_ack_key) |
218 | | - |
219 | | - response = verify_final_ack_file(final_ack_key) |
220 | | - assert response is True |
221 | | - |
222 | | - |
223 | | -if __name__ == "__main__": |
224 | | - unittest.main() |
0 commit comments