Skip to content

Commit c9bd998

Browse files
committed
moved log_fit_kit helper methid from test to utils/fit_kit
refacatored tests
1 parent 1e83e6f commit c9bd998

File tree

4 files changed

+56
-89
lines changed

4 files changed

+56
-89
lines changed

tests/regression/regression_tests/fobt_regression_tests/test_scenario_2.py

Lines changed: 31 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import pytest
22
import logging
33
import datetime
4-
import pandas as pd
54
from playwright.sync_api import Page
65
from pages.communication_production.batch_list_page import ActiveBatchListPage
76
from utils.oracle.subject_creation_util import CreateSubjectSteps
@@ -10,40 +9,13 @@
109
from utils.call_and_recall_utils import CallAndRecallUtils
1110
from utils import screening_subject_page_searcher
1211
from utils.batch_processing import batch_processing
13-
from utils.fit_kit import FitKitGeneration, FitKitLogged
14-
from utils.oracle.oracle import OracleDB
15-
from pages.base_page import BasePage
12+
from utils.fit_kit import FitKitLogged
1613
from pages.screening_subject_search.subject_screening_summary_page import (
1714
SubjectScreeningSummaryPage,
1815
)
19-
from pages.communication_production.communications_production_page import (
20-
CommunicationsProductionPage,
21-
)
22-
from pages.fit_test_kits.log_devices_page import LogDevicesPage
23-
from pages.fit_test_kits.fit_test_kits_page import FITTestKitsPage
2416
from pages.communication_production.batch_list_page import BatchListPage
2517

2618

27-
# Helper function to log FIT kit
28-
def log_fit_kit(page: Page, nhs_no: str) -> str:
29-
BasePage(page).click_main_menu_link()
30-
fit_kit = FitKitGeneration().get_fit_kit_for_subject_sql(nhs_no, False, False)
31-
BasePage(page).go_to_fit_test_kits_page()
32-
FITTestKitsPage(page).go_to_log_devices_page()
33-
logging.info(f"Logging FIT Device ID: {fit_kit}")
34-
LogDevicesPage(page).fill_fit_device_id_field(fit_kit)
35-
sample_date = datetime.datetime.now()
36-
logging.info(f"Setting sample date to {sample_date}")
37-
LogDevicesPage(page).fill_sample_date_field(sample_date)
38-
LogDevicesPage(page).log_devices_title.get_by_text("Scan Device").wait_for()
39-
try:
40-
LogDevicesPage(page).verify_successfully_logged_device_text()
41-
logging.info(f"{fit_kit} Successfully logged")
42-
except Exception as e:
43-
pytest.fail(f"{fit_kit} unsuccessfully logged: {str(e)}")
44-
return fit_kit
45-
46-
4719
@pytest.mark.wip
4820
@pytest.mark.fobt_regression_tests
4921
def test_scenario_2(page: Page) -> None:
@@ -135,8 +107,8 @@ def test_scenario_2(page: Page) -> None:
135107
logging.info(f"[SUBJECT VIEW] Subject {nhs_no} loaded in UI")
136108

137109
# Assert subject details in the UI
138-
# TODO: summary_page.assert_screening_status("Call")
139110
summary_page.assert_screening_status("Inactive")
111+
# summary_page.assert_screening_status("Call") #TODO:
140112
logging.info("[UI ASSERTIONS COMPLETE] Updated subject details checked in the UI")
141113

142114
# When I invite my subject for FOBT screening
@@ -159,33 +131,21 @@ def test_scenario_2(page: Page) -> None:
159131
logging.info("[UI ASSERTIONS COMPLETE] S1 Letter batch exists")
160132

161133
# When I process the open "S1" letter batch for my subject
162-
# Then my subject has been updated as follows:
134+
# Then there is a "S9" letter batch for my subject with the exact title "Invitation & Test Kit (FIT)"
163135
batch_processing(
164136
page, "S1", "Pre-invitation (FIT)", "S9 - Pre-invitation Sent", True
165137
)
166-
logging.info("[DB ASSERTIONS COMPLETE] Updated subject status checked in the DB")
167138
logging.info("[UI ASSERTIONS COMPLETE] Updated subject details checked in the UI")
139+
logging.info("[UI ASSERTIONS COMPLETE] S9 Letter batch exists")
168140

169-
# Navigate to subject summary page in UI
170-
# navigate_to_subject_summary_page(page, nhs_no)
171-
# logging.info(f"[SUBJECT VIEW] Subject {nhs_no} loaded in UI")
172-
173-
# Assert subject details in the UI
174-
# summary_page.assert_latest_event_status("S9 - Pre-invitation Sent")
175-
176-
# When I run Timed Events for my subject
177-
# nhs_df = pd.DataFrame(
178-
# {"subject_nhs_number": [nhs_no]}
179-
# ) # Create DataFrame with NHS number to pass to timed events procedure
180-
# OracleDB().exec_bcss_timed_events(
181-
# nhs_df
182-
# ) # Execute timed events procedure to process the subject
183-
# logging.info("[TIMED EVENTS]Executed for existing subject")
184-
185-
# Then there is a "S9" letter batch for my subject with the exact title "Invitation & Test Kit (FIT)"
186-
# navigate_to_active_batch_list(page)
187-
# ActiveBatchListPage(page).is_batch_present("S9 - Invitation & Test Kit (FIT)")
188-
# logging.info("[UI ASSERTIONS COMPLETE] S9 Letter batch exists")
141+
# Then my subject has been updated as follows:
142+
subject_assertion(
143+
nhs_no,
144+
{
145+
"latest event status": "S9 - Pre-invitation Sent",
146+
},
147+
)
148+
logging.info("[DB ASSERTIONS COMPLETE] Updated subject status checked in the DB")
189149

190150
# When I process the open "S9" letter batch for my subject
191151
batch_processing(
@@ -195,20 +155,19 @@ def test_scenario_2(page: Page) -> None:
195155
"S10 - Invitation & Test Kit Sent",
196156
True,
197157
)
198-
logging.info("[DB ASSERTIONS COMPLETE] Updated subject status checked in the DB")
158+
logging.info("[UI ASSERTIONS COMPLETE] Updated subject status checked in the UI")
199159

200-
# # Then my subject has been updated as follows:
201-
# batch_processing(
202-
# page,
203-
# "S9",
204-
# "Invitation & Test Kit (FIT)",
205-
# "S10 - Invitation & Test Kit Sent",
206-
# True,
207-
# )
208-
# logging.info("[DB ASSERTIONS COMPLETE] Updated subject status checked in the DB")
160+
# Then my subject has been updated as follows:
161+
subject_assertion(
162+
nhs_no,
163+
{
164+
"latest event status": "S10 - Invitation & Test Kit Sent",
165+
},
166+
)
167+
logging.info("[DB ASSERTIONS COMPLETE] Updated subject status checked in the DB")
209168

210169
# When I log my subject's latest unlogged FIT kit
211-
fit_kit = log_fit_kit(page, nhs_no)
170+
fit_kit = FitKitLogged().log_fit_kit(page, nhs_no)
212171

213172
# Then my subject has been updated as follows:
214173
subject_assertion(
@@ -262,24 +221,16 @@ def test_scenario_2(page: Page) -> None:
262221
"S158 - Subject Discharge Sent (Normal)",
263222
True,
264223
)
224+
logging.info("[UI ASSERTIONS COMPLETE] Updated subject status checked in the UI")
265225

266226
# Then my subject has been updated as follows:
267-
# batch_processing(
268-
# page,
269-
# "S2",
270-
# "Subject Result (Normal)",
271-
# "S158 Subject Discharge Sent (Normal)",
272-
# True,
273-
# )
274-
# logging.info("[DB ASSERTIONS COMPLETE] Updated subject status checked in the DB")
275-
276-
# Navigate to subject summary page in UI
277-
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
278-
logging.info(f"[SUBJECT VIEW] Subject {nhs_no} loaded in UI")
279-
280-
# Assert subject details in the UI
281-
summary_page.assert_latest_event_status("S158 - Subject Discharge Sent (Normal)")
282-
logging.info("[UI ASSERTIONS COMPLETE] Updated subject details checked in the UI")
227+
subject_assertion(
228+
nhs_no,
229+
{
230+
"latest event status": "S158 Subject Discharge Sent (Normal)",
231+
},
232+
)
233+
logging.info("[DB ASSERTIONS COMPLETE] Updated subject status checked in the DB")
283234

284235
# And there is a "S158" letter batch for my subject with the exact title "GP Result (Normal)"
285236
BatchListPage(page).navigate_to_active_batch_list_page()
@@ -294,6 +245,7 @@ def test_scenario_2(page: Page) -> None:
294245
"S159 - GP Discharge Sent (Normal)",
295246
True,
296247
)
248+
logging.info("[UI ASSERTIONS COMPLETE] Updated subject status checked in the UI")
297249

298250
# Then my subject has been updated as follows:
299251
subject_assertion(
@@ -328,12 +280,4 @@ def test_scenario_2(page: Page) -> None:
328280
)
329281
logging.info("[DB ASSERTIONS COMPLETE] Updated subject details checked in the DB")
330282

331-
# Navigate to subject summary page in UI
332-
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
333-
logging.info(f"[SUBJECT VIEW] Subject {nhs_no} loaded in UI")
334-
335-
# Assert subject details in the UI
336-
summary_page.assert_latest_event_status("S159 - GP Discharge Sent (Normal)")
337-
logging.info("[UI ASSERTIONS COMPLETE] Updated subject details checked in the UI")
338-
339283
logging.info("[TEST COMPLETE] Scenario 2 passed all assertions")

utils/batch_processing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def batch_processing(
3131
save_csv_as_df: bool = False,
3232
) -> Optional[pd.DataFrame]:
3333
"""
34-
This is used to process batches.
34+
Processes a batch in the BCSS UI by navigating to the batch, extracting subject NHS numbers (from the database or PDF),
35+
verifying each subject's event status in the UI, and optionally running timed events or returning batch data as a DataFrame.
3536
3637
Args:
3738
page (Page): This is the playwright page object

utils/fit_kit.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
)
1919
from classes.kit_service_management_record import KitServiceManagementRecord
2020
from classes.kit_status import KitStatus
21+
from pages.fit_test_kits.fit_test_kits_page import FITTestKitsPage
22+
from pages.fit_test_kits.log_devices_page import LogDevicesPage
23+
from playwright.sync_api import Page
2124

2225

2326
class FitKitGeneration:
@@ -295,3 +298,22 @@ def read_latest_logged_kit(
295298
raise RuntimeError(f"Error occurred while reading latest logged kit: {e}")
296299

297300
logging.info("exit: read_latest_logged_kit")
301+
302+
def log_fit_kit(self, page: Page, nhs_no: str) -> str:
303+
"""Logs the FIT kit for a given subject."""
304+
BasePage(page).click_main_menu_link()
305+
fit_kit = FitKitGeneration().get_fit_kit_for_subject_sql(nhs_no, False, False)
306+
BasePage(page).go_to_fit_test_kits_page()
307+
FITTestKitsPage(page).go_to_log_devices_page()
308+
logging.info(f"Logging FIT Device ID: {fit_kit}")
309+
LogDevicesPage(page).fill_fit_device_id_field(fit_kit)
310+
sample_date = datetime.now()
311+
logging.info(f"Setting sample date to {sample_date}")
312+
LogDevicesPage(page).fill_sample_date_field(sample_date)
313+
LogDevicesPage(page).log_devices_title.get_by_text("Scan Device").wait_for()
314+
try:
315+
LogDevicesPage(page).verify_successfully_logged_device_text()
316+
logging.info(f"{fit_kit} Successfully logged")
317+
except Exception as e:
318+
pytest.fail(f"{fit_kit} unsuccessfully logged: {str(e)}")
319+
return fit_kit

utils/subject_assertion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
def subject_assertion(nhs_number: str, criteria: dict) -> bool:
99
"""
10-
Asserts that a subject with the given NHS number exists and matches the provided criteria.
10+
Asserts that a subject with the given NHS number exists in the database and matches the provided criteria.
1111
Args:
1212
nhs_number (str): The NHS number of the subject to find.
1313
criteria (dict): A dictionary of criteria to match against the subject's attributes.

0 commit comments

Comments
 (0)