Skip to content

Commit c5d6307

Browse files
committed
wip
1 parent 8e70efb commit c5d6307

File tree

2 files changed

+32
-37
lines changed

2 files changed

+32
-37
lines changed

tests/regression/regression_tests/fobt_regression_tests/test_scenario_2.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22
import logging
3-
import datetime
3+
from datetime import datetime
44
from playwright.sync_api import Page
55
from pages.communication_production.batch_list_page import ActiveBatchListPage
66
from utils.oracle.subject_creation_util import CreateSubjectSteps
@@ -9,7 +9,7 @@
99
from utils.call_and_recall_utils import CallAndRecallUtils
1010
from utils import screening_subject_page_searcher
1111
from utils.batch_processing import batch_processing
12-
from utils.fit_kit import FitKitLogged
12+
from utils.fit_kit import FitKitLogged, FitKitGeneration
1313
from pages.screening_subject_search.subject_screening_summary_page import (
1414
SubjectScreeningSummaryPage,
1515
)
@@ -85,7 +85,7 @@ def test_scenario_2(page: Page) -> None:
8585
logging.info(f"[FAILSAFE TRAWL RUN] FOBT failsafe trawl run for subject {nhs_no}")
8686

8787
# Then my subject has been updated as follows:
88-
today = datetime.datetime.now().strftime("%d/%m/%Y")
88+
today = datetime.now().strftime("%d/%m/%Y")
8989

9090
subject_assertion(
9191
nhs_no,
@@ -164,8 +164,10 @@ def test_scenario_2(page: Page) -> None:
164164
logging.info("[DB ASSERTIONS COMPLETE] Updated subject status checked in the DB")
165165

166166
# When I log my subject's latest unlogged FIT kit
167-
fit_kit = FitKitLogged().log_fit_kit(page, nhs_no)
168-
167+
fit_kit = FitKitGeneration().get_fit_kit_for_subject_sql(nhs_no, False, False)
168+
sample_date = datetime.now()
169+
FitKitLogged().log_fit_kits(page, fit_kit, sample_date)
170+
169171
# Then my subject has been updated as follows:
170172
subject_assertion(
171173
nhs_no,

utils/fit_kit.py

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
get_kit_id_logged_from_db,
44
)
55
from pages.base_page import BasePage
6+
from pages.fit_test_kits.log_devices_page import LogDevicesPage
7+
from pages.fit_test_kits.fit_test_kits_page import FITTestKitsPage
68
from datetime import datetime
79
import logging
810
import pandas as pd
@@ -17,9 +19,7 @@
1719
KitServiceManagementRepository,
1820
)
1921
from classes.kit_status import KitStatus
20-
from pages.fit_test_kits.fit_test_kits_page import FITTestKitsPage
21-
from pages.fit_test_kits.log_devices_page import LogDevicesPage
22-
from playwright.sync_api import Page
22+
from oracle.oracle_specific_functions import execute_fit_kit_stored_procedures
2323

2424

2525
class FitKitGeneration:
@@ -127,16 +127,16 @@ def get_fit_kit_for_subject_sql(self, nhs_no: str, logged: bool, read: bool) ->
127127
sql_query = []
128128
sql_query.append(
129129
"""
130-
SELECT kitid
131-
FROM tk_items_t
132-
WHERE tk_type_id > 1
133-
AND kitid = (
134-
SELECT MAX(tkx.kitid)
135-
FROM tk_items_t tkx
136-
LEFT OUTER JOIN kit_queue kq ON kq.device_id = tkx.device_id
137-
WHERE tkx.tk_type_id > 1
138-
AND tkx.screening_subject_id = :subject_id
139-
"""
130+
SELECT kitid
131+
FROM tk_items_t
132+
WHERE tk_type_id > 1
133+
AND kitid = (
134+
SELECT MAX(tkx.kitid)
135+
FROM tk_items_t tkx
136+
LEFT OUTER JOIN kit_queue kq ON kq.device_id = tkx.device_id
137+
WHERE tkx.tk_type_id > 1
138+
AND tkx.screening_subject_id = :subject_id
139+
"""
140140
)
141141
if logged:
142142
sql_query.append(" AND tkx.logged_in_flag = 'Y' ")
@@ -239,11 +239,6 @@ def read_latest_logged_kit(
239239
) -> None:
240240
"""
241241
Reads the subject's latest logged FIT kit and updates its status/result.
242-
Args:
243-
user (UserRoleType): The user performing the action.
244-
kit_type (int): The type of the kit.
245-
kit (str): The FIT kit ID to be read.
246-
kit_result (str): The result of the kit reading. Valid values are "NORMAL", "ABNORMAL", "SPOILT", "TECHNICAL_FAILURE".
247242
"""
248243
logging.info("start: read_latest_logged_kit")
249244

@@ -293,37 +288,35 @@ def read_latest_logged_kit(
293288
kit_queue_record.authoriser_user_code = "AUTOTEST"
294289
kit_queue_record.test_result = result_reading
295290
kit_queue_record.error_code = result_code
291+
logging.debug(f"kit queue record: {kit_queue_record.__str__()}")
296292
kit_queue_repo.update_kit_service_management_record(kit_queue_record)
297293

298294
# Immediately process the kit queue (don't wait for the scheduled DB job to kick in)
299-
kit_queue_repo.process_kit_queue()
295+
execute_fit_kit_stored_procedures()
300296

301297
except Exception as e:
302298
raise RuntimeError(f"Error occurred while reading latest logged kit: {e}")
303299

304300
logging.info("exit: read_latest_logged_kit")
305301

306-
def log_fit_kit(self, page: Page, nhs_no: str) -> str:
307-
"""Logs the FIT kit for a given subject.
302+
def log_fit_kits(self, page, fit_kit: str, sample_date: datetime) -> None:
303+
"""
304+
Navigates to the log devices page and logs FIT kits
308305
Args:
309-
page (Page): The Playwright page object.
310-
nhs_no (str): The NHS number of the subject.
311-
Returns:
312-
str: The FIT kit ID that was successfully logged.
306+
fit_kit (str): The device id of the FIT kit
307+
sample_date (datetime): The date you want to select for the sample date field
313308
"""
314309
BasePage(page).click_main_menu_link()
315-
fit_kit = FitKitGeneration().get_fit_kit_for_subject_sql(nhs_no, False, False)
316310
BasePage(page).go_to_fit_test_kits_page()
317311
FITTestKitsPage(page).go_to_log_devices_page()
318-
logging.info(f"Logging FIT Device ID: {fit_kit}")
312+
logging.info(f"[FIT KITS] Logging FIT Device ID: {fit_kit}")
319313
LogDevicesPage(page).fill_fit_device_id_field(fit_kit)
320-
sample_date = datetime.now()
321-
logging.info(f"Setting sample date to {sample_date}")
322314
LogDevicesPage(page).fill_sample_date_field(sample_date)
323315
LogDevicesPage(page).log_devices_title.get_by_text("Scan Device").wait_for()
324316
try:
325317
LogDevicesPage(page).verify_successfully_logged_device_text()
326-
logging.info(f"{fit_kit} Successfully logged")
318+
logging.info(f"[UI ASSERTIONS COMPLETE] {fit_kit} Successfully logged")
327319
except Exception as e:
328-
pytest.fail(f"{fit_kit} unsuccessfully logged: {str(e)}")
329-
return fit_kit
320+
pytest.fail(
321+
f"[UI ASSERTIONS FAILED] {fit_kit} unsuccessfully logged: {str(e)}"
322+
)

0 commit comments

Comments
 (0)