|
| 1 | +import logging |
| 2 | +from datetime import datetime |
| 3 | + |
| 4 | +from jaydebeapi import connect |
| 5 | + |
| 6 | +from my_pages import * |
| 7 | +from utils import get_nhs_no_from_batch_id |
| 8 | +from utils.fit_kit_generation import create_fit_id_df |
| 9 | +from utils.oracle import OracleDB |
| 10 | +from utils.screening_subject_page_searcher import verify_subject_event_status_by_nhs_no |
| 11 | + |
| 12 | + |
| 13 | +def test_compartment_3(page: Page) -> None: |
| 14 | + # (STEP - 4) Run two stored procedures to process any kit queue records at status BCSS_READY |
| 15 | + # (processKitQueue function in selenium tests) |
| 16 | + |
| 17 | + logging.info("start: KitServiceManagementRepository.process_kit_queue") |
| 18 | + |
| 19 | + # Create entity manager |
| 20 | + entity_manager = EntityManagerFactory.create_entity_manager() |
| 21 | + |
| 22 | + # Connect to DB |
| 23 | + connection = connect('com.mysql.cj.jdbc.Driver', 'jdbc:mysql://localhost:3306/your_database', |
| 24 | + ['username', 'password'], 'com.mysql.cj.jdbc.Driver') |
| 25 | + entity_manager['jdbcUrl'] = connection.url |
| 26 | + entity_manager['username'] = connection.username |
| 27 | + entity_manager['password'] = connection.password |
| 28 | + |
| 29 | + entity_manager['transaction'] = entity_manager.get('entityManager').raw_connection.begin() |
| 30 | + |
| 31 | + # Run stored procedure 1 - validate kit queue |
| 32 | + logging.info("entityManager.createStoredProcedureQuery('PKG_TEST_KIT_QUEUE.p_validate_kit_queue')") |
| 33 | + sp_query = entity_manager['entityManager'].createStoredProcedureQuery( |
| 34 | + "PKG_TEST_KIT_QUEUE.p_validate_kit_queue") |
| 35 | + |
| 36 | + logging.info("call stored procedure") |
| 37 | + sp_query.execute() |
| 38 | + |
| 39 | + # Run stored procedure 2 - calculate result |
| 40 | + logging.info("entityManager.createStoredProcedureQuery('PKG_TEST_KIT_QUEUE.p_calculate_result')") |
| 41 | + sp_query = entity_manager['entityManager'].createStoredProcedureQuery( |
| 42 | + "PKG_TEST_KIT_QUEUE.p_calculate_result") |
| 43 | + |
| 44 | + logging.info("call stored procedure") |
| 45 | + sp_query.execute() |
| 46 | + |
| 47 | + # Commit transaction and close |
| 48 | + logging.info("commit transaction and close") |
| 49 | + entity_manager['transaction'].commit() |
| 50 | + entity_manager['entityManager'].close() |
| 51 | + |
| 52 | + logging.info("exit: KitServiceManagementRepository.process_kit_queue") |
| 53 | + |
| 54 | + # (STEP - 5) Check the results of the processed FIT kits have correctly updated the status of the associated subjects |
| 55 | + page.goto("/") |
| 56 | + BcssLoginPage(page).login_as_user("BCSS401") |
| 57 | + |
| 58 | + MainMenu(page).go_to_fit_test_kits_page() |
| 59 | + FITTestKits(page).go_to_log_devices_page() |
| 60 | + subjectdf = create_fit_id_df() |
| 61 | + |
| 62 | + for subject in range(4): |
| 63 | + fit_device_id = subjectdf["fit_device_id"].iloc[subject] |
| 64 | + LogDevices(page).fill_fit_device_id_field(fit_device_id) |
| 65 | + sample_date = datetime.now().strftime("%#d %b %Y") |
| 66 | + LogDevices(page).fill_sample_date_field(sample_date) |
| 67 | + LogDevices(page).verify_successfully_logged_device_text() |
| 68 | + |
| 69 | + normal_result_batch_id = "" |
| 70 | + abnormal_result_batch_id = "" |
| 71 | + |
| 72 | + # Retrieve NHS numbers from FIT normal test results |
| 73 | + normal_test_result_nhs_number = get_nhs_no_from_batch_id.get_nhs_no_from_batch_id(normal_result_batch_id) |
| 74 | + for index, row in normal_test_result_nhs_number.iterrows(): |
| 75 | + OracleDB().exec_bcss_timed_events(row["subject_nhs_number"]) |
| 76 | + |
| 77 | + # Retrieve NHS numbers from FIT abnormal test results |
| 78 | + abnormal_test_result_nhs_number = get_nhs_no_from_batch_id.get_nhs_no_from_batch_id(abnormal_result_batch_id) |
| 79 | + for index, row in abnormal_test_result_nhs_number.iterrows(): |
| 80 | + OracleDB().exec_bcss_timed_events(row["subject_nhs_number"]) |
| 81 | + |
| 82 | + # Check statuses of 'normal' FIT kit subjects has moved to S2 |
| 83 | + nhs_no = subjectdf["subject_nhs_number"].iloc[0] |
| 84 | + verify_subject_event_status_by_nhs_no(page, nhs_no, "S2 - Normal") |
| 85 | + |
| 86 | + # Check status of 'abnormal' FIT kit subjects has moved to A8 |
| 87 | + nhs_no = subjectdf["subject_nhs_number"].iloc[0] |
| 88 | + verify_subject_event_status_by_nhs_no(page, nhs_no, "A8 - Abnormal") |
0 commit comments