|
3 | 3 | from utils import ( |
4 | 4 | upload_file_to_s3, |
5 | 5 | get_file_content_from_s3, |
6 | | - check_ack_file_content, |
7 | | - validate_row_count, |
| 6 | + # check_ack_file_content, |
| 7 | + check_inf_file_content, |
| 8 | + # validate_row_count, |
8 | 9 | generate_csv_files, |
| 10 | + # OpMsgs, |
9 | 11 | TestData, |
10 | 12 | DestinationType, |
| 13 | + # BusRowResult, |
| 14 | + cleanup |
11 | 15 | ) |
12 | | -import logging |
| 16 | +from clients import logger |
13 | 17 |
|
14 | 18 |
|
15 | 19 | from constants import ( |
|
19 | 23 | environment |
20 | 24 | ) |
21 | 25 |
|
22 | | -CREATE = "CREATE" |
| 26 | +NEW = "NEW" |
23 | 27 | UPDATE = "UPDATE" |
24 | 28 | DELETE = "DELETE" |
25 | 29 |
|
26 | 30 |
|
27 | | -seed_datas = [ |
28 | | - TestData("Create", "V0V8L", [CREATE]), |
29 | | - TestData("Update", "8HK48", [CREATE, UPDATE]), |
30 | | - TestData("Delete", "8HA94", [CREATE, UPDATE, DELETE]), |
31 | | - TestData("Reinstate", "X26", [CREATE, DELETE, UPDATE]), |
32 | | - TestData("Update no Create", "YGM41", [UPDATE], success=False), |
33 | | - TestData("Delete no Create", "YGJ", [DELETE], success=False), |
34 | | - TestData("Create with extended ascii characters in name", "YGA", [CREATE], inject_char=True), |
35 | | -] |
36 | | - |
37 | | -logging.basicConfig(level="INFO") |
38 | | -logger = logging.getLogger() |
39 | | -logger.setLevel("INFO") |
40 | | - |
41 | | - |
42 | 31 | class TestE2EBatch(unittest.TestCase): |
43 | 32 |
|
| 33 | + def setUp(self): |
| 34 | + self.seed_datas = [ |
| 35 | + TestData("Create", "V0V8L", ["CREATE"]), |
| 36 | + TestData("Update", "8HK48", ["CREATE", UPDATE]), |
| 37 | + # TestData("Delete", "8HA94", [NEW, UPDATE, DELETE]), |
| 38 | + # TestData("Reinstate", "X26", [NEW, DELETE, UPDATE]), |
| 39 | + # TestData("Update no Create", "YGM41", [UPDATE], expected=BusRowResult.FATAL_ERROR, |
| 40 | + # operation_outcome=OpMsgs.IMM_NOT_EXIST), |
| 41 | + # TestData("Delete no Create", "YGJ", [DELETE], expected=BusRowResult.FATAL_ERROR, |
| 42 | + # operation_outcome=OpMsgs.IMM_NOT_EXIST), |
| 43 | + # TestData("Create with extended ascii characters in name", "YGA", [NEW], inject_char=True), |
| 44 | + ] |
| 45 | + |
| 46 | + def tearDown(self): |
| 47 | + # loop through all files and delete them from s3 |
| 48 | + cleanup(self.seed_datas) |
| 49 | + |
44 | 50 | @unittest.skipIf(environment == "ref", "Skip for ref") |
45 | 51 | def test_create_success(self): |
46 | 52 | """Test CREATE scenario.""" |
47 | 53 | start_time = time.time() |
48 | 54 | max_timeout = 1200 # seconds |
49 | 55 |
|
50 | | - test_datas: list[TestData] = generate_csv_files(seed_datas) |
| 56 | + tests: list[TestData] = generate_csv_files(self.seed_datas) |
51 | 57 |
|
52 | | - for test_data in test_datas: |
53 | | - logging.info(f"Upload {test_data.file_name}") |
54 | | - key = upload_file_to_s3(test_data.file_name, SOURCE_BUCKET, INPUT_PREFIX) |
55 | | - test_data.key = key |
| 58 | + for test in tests: |
| 59 | + logger.info(f"Upload for Test: {test.name} ") |
| 60 | + key = upload_file_to_s3(test.file_name, SOURCE_BUCKET, INPUT_PREFIX) |
| 61 | + test.key = key |
56 | 62 |
|
| 63 | + logger.info(f"Uploaded all files. Time: {time.time() - start_time:.1f} seconds") |
| 64 | + logger.info("Waiting while processing...") |
57 | 65 | # dictionary of file name to track whether inf and bus acks have been received |
58 | 66 | start_time = time.time() |
59 | 67 | # while there are still pending files, poll for acks and forwarded files |
60 | 68 | pending = True |
61 | 69 | while pending and (time.time() - start_time) < max_timeout: |
62 | 70 | pending = False |
63 | | - for test_data in test_datas: |
64 | | - pending = test_data.poll_destination(pending, logging) |
| 71 | + for test in tests: |
| 72 | + pending = test.poll_destination(pending) |
65 | 73 | if pending: |
66 | | - time.sleep(1) |
| 74 | + print(".", end="") |
| 75 | + time.sleep(5) |
67 | 76 |
|
68 | | - logging.info(f"Finished polling for acks. Time taken: {time.time() - start_time:.1f} seconds") |
| 77 | + logger.info(f"Files Processed. Time: {time.time() - start_time:.1f} seconds") |
69 | 78 |
|
70 | 79 | # Now validate all files have been processed correctly |
71 | | - for test_data in test_datas: |
| 80 | + for test in tests: |
| 81 | + logger.info(f"Validation for Test: {test.name} ") |
72 | 82 | # Validate the ACK file |
73 | | - inf_ack_content = get_file_content_from_s3(ACK_BUCKET, test_data.ack_keys[DestinationType.INF]) |
| 83 | + # inf_ack_content = get_file_content_from_s3(ACK_BUCKET, test.ack_keys[DestinationType.INF]) |
74 | 84 |
|
75 | | - check_ack_file_content(inf_ack_content, "Success", None, test_data.actions) |
76 | | - validate_row_count(test_data.file_name, test_data.ack_keys[DestinationType.BUS]) |
| 85 | + # check_ack_file_content(test.name, inf_ack_content, "Success", None, test.actions) |
| 86 | + # validate_row_count(f"{test.name} - inf", test.file_name, test.ack_keys[DestinationType.BUS]) |
77 | 87 | # check row after header |
| 88 | + # bus_ack_content = get_file_content_from_s3(ACK_BUCKET, test.ack_keys[DestinationType.BUS]) |
| 89 | + # loop through each line in the bus ack content |
78 | 90 |
|
79 | | - # how to validate bus ack content? |
80 | | - # bus_ack_content = get_file_content_from_s3(ACK_BUCKET, test_data.ack_keys[DestinationType.BUS]) |
| 91 | + # sometimes OK and sometimes CREATE |
| 92 | + # check_inf_file_content(f"{test.name} - bus", bus_ack_content, "OK", test.operation_outcome, |
| 93 | + # test.actions) |
81 | 94 |
|
82 | | - logging.info(f"Completed all validations. Total time taken: {time.time() - start_time:.1f} seconds") |
| 95 | + logger.info(f"Completed all validations. Total time: {time.time() - start_time:.1f} seconds") |
0 commit comments