Skip to content

Commit b9844e2

Browse files
Added logging to compartment 2 and changed the way NHS numbers are obtained
1 parent 04e40a9 commit b9844e2

File tree

4 files changed

+35
-24
lines changed

4 files changed

+35
-24
lines changed

tests/Smokescreen/test_compartment_2.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
from datetime import datetime
66
from utils.screening_subject_page_searcher import verify_subject_event_status_by_nhs_no
77
from utils.fit_kit_generation import create_fit_id_df
8+
import logging
89

9-
10+
@pytest.mark.smoke
1011
@pytest.mark.smokescreen
1112
@pytest.mark.compartment2
1213
def test_compartment_2(page: Page) -> None:
@@ -18,27 +19,44 @@ def test_compartment_2(page: Page) -> None:
1819

1920
for subject in range(4):
2021
fit_device_id = subjectdf["fit_device_id"].iloc[subject]
22+
logging.info(f"Logging FIT Device ID: {fit_device_id}")
2123
LogDevices(page).fill_fit_device_id_field(fit_device_id)
2224
sample_date = datetime.now().strftime("%#d %b %Y")
25+
logging.info("Setting sample date to todays date")
2326
LogDevices(page).fill_sample_date_field(sample_date)
24-
LogDevices(page).verify_successfully_logged_device_text()
27+
try:
28+
LogDevices(page).verify_successfully_logged_device_text()
29+
logging.info(f"{fit_device_id} Successfully logged")
30+
except:
31+
pytest.fail(f"{fit_device_id} unsuccessfully logged")
2532

2633
nhs_no = subjectdf["subject_nhs_number"].iloc[0]
27-
verify_subject_event_status_by_nhs_no(page, nhs_no, "S43 - Kit Returned and Logged (Initial Test)")
34+
try:
35+
verify_subject_event_status_by_nhs_no(page, nhs_no, "S43 - Kit Returned and Logged (Initial Test)")
36+
logging.info(f"Successfully verified NHS number {nhs_no} with status S43 - Kit Returned and Logged (Initial Test)")
37+
except Exception as e:
38+
pytest.fail(f"Verification failed for NHS number {nhs_no}: {str(e)}")
2839

2940
NavigationBar(page).click_main_menu_link()
3041
MainMenu(page).go_to_fit_test_kits_page()
3142
FITTestKits(page).go_to_log_devices_page()
3243
spoilt_fit_device_id = subjectdf["fit_device_id"].iloc[-1]
44+
logging.info(f"Logging Spoilt FIT Device ID: {spoilt_fit_device_id}")
3345
LogDevices(page).fill_fit_device_id_field(spoilt_fit_device_id)
3446
LogDevices(page).click_device_spoilt_button()
3547
LogDevices(page).select_spoilt_device_dropdown_option()
3648
LogDevices(page).click_log_as_spoilt_button()
37-
LogDevices(page).verify_successfully_logged_device_text()
49+
try:
50+
LogDevices(page).verify_successfully_logged_device_text()
51+
logging.info(f"{spoilt_fit_device_id} Successfully logged")
52+
except:
53+
pytest.fail(f"{spoilt_fit_device_id} unsuccessfully logged")
54+
3855

3956
batch_processing(page, "S3", "Retest (Spoilt) (FIT)", "S11 - Retest Kit Sent (Spoilt)")
4057

4158
# Log out
59+
logging.info("Logging Out")
4260
NavigationBar(page).click_log_out_link()
4361
Logout(page).verify_log_out_page()
4462
page.close()

tests/Smokescreen/test_compartment_3.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def test_compartment_3(page: Page) -> None:
5656
OracleDB().exec_bcss_timed_events(nhs_number_df)
5757

5858
# Log out
59+
logging.info("Logging Out")
5960
NavigationBar(page).click_log_out_link()
6061
Logout(page).verify_log_out_page()
6162
page.close()

utils/batch_processing.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def batch_processing(page: Page, batch_type: str, batch_description: str, latest
3939
nhs_no_df = get_nhs_no_from_batch_id(link_text)
4040
logging.info(f"Successfully retrieved NHS Numbers from batch: {link_text}")
4141
except Exception as e:
42-
logging.error(f"Failed to retrieve NHS Numbers from batch: {link_text}")
42+
pytest.fail(f"Failed to retrieve NHS Numbers from batch: {link_text}, {str(e)}")
4343
link.click()
4444
break
4545
else:
@@ -65,7 +65,7 @@ def batch_processing(page: Page, batch_type: str, batch_description: str, latest
6565
download_file.save_as(file)
6666
os.remove(file) # Deletes the file after extracting the necessary data
6767
except Exception as e:
68-
logging.error(f"No retrieve button available to click: {str(e)}")
68+
pytest.fail(f"No retrieve button available to click: {str(e)}")
6969

7070
# This loops through each Confirm printed button and clicks each one
7171
try:
@@ -74,13 +74,13 @@ def batch_processing(page: Page, batch_type: str, batch_description: str, latest
7474
page.once("dialog", lambda dialog: dialog.accept())
7575
ManageActiveBatch(page).confirm_button.nth(0).click()
7676
except Exception as e:
77-
logging.error(f"No confirm printed button available to click: {str(e)}")
77+
pytest.fail(f"No confirm printed button available to click: {str(e)}")
7878

7979
try:
8080
ActiveBatchList(page).batch_successfully_archived_msg.wait_for()
8181
logging.info(f"Batch {link_text} successfully archived")
8282
except Exception as e:
83-
logging.error(f"Batch successfully archived message is not shown: {str(e)}")
83+
pytest.fail(f"Batch successfully archived message is not shown: {str(e)}")
8484

8585
NavigationBar(page).click_main_menu_link()
8686
MainMenu(page).go_to_communications_production_page()
@@ -89,13 +89,13 @@ def batch_processing(page: Page, batch_type: str, batch_description: str, latest
8989
try:
9090
ArchivedBatchList(page).verify_table_data(link_text)
9191
logging.info(f"Batch {link_text} visible in archived batch list")
92-
except Exception:
93-
logging.error(f"Batch {link_text} not visible in archived batch list")
92+
except Exception as e:
93+
logging.error(f"Batch {link_text} not visible in archived batch list: {str(e)}")
9494

9595
first_nhs_no = nhs_no_df["subject_nhs_number"].iloc[0]
9696
try:
9797
verify_subject_event_status_by_nhs_no(page, first_nhs_no, latest_event_status)
9898
logging.info(f"Successfully verified NHS number {first_nhs_no} with status {latest_event_status}")
9999
except Exception as e:
100-
logging.error(f"Verification failed for NHS number {first_nhs_no} with status {latest_event_status}: {str(e)}")
100+
pytest.fail(f"Verification failed for NHS number {first_nhs_no}: {str(e)}")
101101
return nhs_no_df

utils/fit_kit_generation.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
from oracle import OracleDB
22
import pandas as pd
33
from datetime import datetime
4+
import logging
45

56
def create_fit_id_df():
67
df = get_kit_id_from_db()
78
df["fit_device_id"] = df["kitid"].apply(calculate_check_digit)
89
df["fit_device_id"] = df["fit_device_id"].apply(convert_kit_id_to_fit_device_id)
9-
10-
temp_string = df["screening_subject_id"].apply(str).iloc[0]
11-
for subject in range(df.shape[0]):
12-
subject_id = df["screening_subject_id"].apply(str).iloc[subject]
13-
temp_string += f" or SCREENING_SUBJECT_ID = {subject_id}"
14-
15-
df = get_nhs_number_from_subject_id(temp_string, df)
1610
return df
1711

1812
def get_kit_id_from_db():
19-
kit_id_df = OracleDB().execute_query("""select tk.kitid, tk.screening_subject_id
13+
logging.info("Retrieving useable test kit ids")
14+
kit_id_df = OracleDB().execute_query("""select tk.kitid, tk.screening_subject_id, sst.subject_nhs_number
2015
from tk_items_t tk
2116
inner join ep_subject_episode_t se on se.screening_subject_id = tk.screening_subject_id
2217
inner join screening_subject_t sst on (sst.screening_subject_id = tk.screening_subject_id)
@@ -32,6 +27,7 @@ def get_kit_id_from_db():
3227
return kit_id_df
3328

3429
def calculate_check_digit(kitID: str):
30+
logging.info(f"Calculating check digit for kit id: {kitID}")
3531
total = 0
3632
charString = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%"
3733
for i in range(len(kitID)):
@@ -40,11 +36,7 @@ def calculate_check_digit(kitID: str):
4036
return f"{kitID}-{check_digit}"
4137

4238
def convert_kit_id_to_fit_device_id(kit_id: str):
39+
logging.info(f"Generating FIT Device ID from: {kit_id}")
4340
today = datetime.now()
4441
year = today.strftime("%y") # Get the year from todays date in YY format
4542
return f"{kit_id}12{int(year)+1}12345/KD00001"
46-
47-
def get_nhs_number_from_subject_id(subject_ids, df):
48-
temp_df = OracleDB().execute_query(f"SELECT SCREENING_SUBJECT_ID, SUBJECT_NHS_NUMBER FROM SCREENING_SUBJECT_T WHERE SCREENING_SUBJECT_ID = {subject_ids}")
49-
df = df.merge(temp_df[["screening_subject_id","subject_nhs_number"]], on="screening_subject_id", how="left")
50-
return df

0 commit comments

Comments
 (0)