Skip to content

Commit d54b5af

Browse files
committed
Addressing sonarqube duplicate code errors
1 parent 10a0c5c commit d54b5af

File tree

3 files changed

+73
-66
lines changed

3 files changed

+73
-66
lines changed

tests/regression/regression_tests/fobt_regression_tests/test_scenario_8.py

Lines changed: 51 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
SubjectScreeningSummaryPage,
5656
)
5757
from pages.logout.log_out_page import LogoutPage
58-
from pages.base_page import BasePage
5958
from pages.screening_subject_search.advance_fobt_screening_episode_page import (
6059
AdvanceFOBTScreeningEpisodePage,
6160
)
@@ -172,11 +171,11 @@ def test_scenario_8(page: Page) -> None:
172171
# When I process the open "S9" letter batch for my subject
173172
# Then my subject has been updated as follows:
174173
batch_processing(
175-
page,
176-
"S9",
177-
"Invitation & Test Kit (FIT)",
178-
"S10 - Invitation & Test Kit Sent",
179-
True,
174+
page=page,
175+
batch_type="S9",
176+
batch_description="Invitation & Test Kit (FIT)",
177+
latest_event_status="S10 - Invitation & Test Kit Sent",
178+
run_timed_events=True,
180179
)
181180

182181
# When I log my subject's latest unlogged FIT kit
@@ -223,22 +222,22 @@ def test_scenario_8(page: Page) -> None:
223222
# When I process the open "A183 - Practitioner Clinic 1st Appointment" letter batch for my subject
224223
# Then my subject has been updated as follows:
225224
batch_processing(
226-
page,
227-
"A183",
228-
"Practitioner Clinic 1st Appointment",
229-
"A25 - 1st Colonoscopy Assessment Appointment Booked, letter sent",
225+
page=page,
226+
batch_type="A183",
227+
batch_description="Practitioner Clinic 1st Appointment",
228+
latest_event_status="A25 - 1st Colonoscopy Assessment Appointment Booked, letter sent",
230229
)
231230

232231
# And there is a "A183" letter batch for my subject with the exact title "GP Result (Abnormal)"
233232
batch_processing(
234-
page,
235-
"A183",
236-
"GP Result (Abnormal)",
237-
"A25 - 1st Colonoscopy Assessment Appointment Booked, letter sent",
233+
page=page,
234+
batch_type="A183",
235+
batch_description="GP Result (Abnormal)",
236+
latest_event_status="A25 - 1st Colonoscopy Assessment Appointment Booked, letter sent",
238237
)
239238

240239
# When I switch users to BCSS "England" as user role "Screening Centre Manager"
241-
switch_user(page, "Screening Centre Manager")
240+
UserTools.switch_user(page, "Screening Centre Manager")
242241

243242
# When I view the subject
244243
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
@@ -310,7 +309,7 @@ def test_scenario_8(page: Page) -> None:
310309
subject_assertion(nhs_no, criteria)
311310

312311
# When I switch users to BCSS "England" as user role "Hub Manager"
313-
switch_user(page, "Hub Manager", "BCS01")
312+
UserTools.switch_user(page, "Hub Manager", "BCS01")
314313

315314
# And I process the open "A183 - GP Result (Abnormal)" letter batch for my subject
316315
# NOTE LEAVE COMMENTED - Subject is already at A172 DNA Diagnostic Test (line 313)
@@ -328,7 +327,9 @@ def test_scenario_8(page: Page) -> None:
328327
# subject_assertion(nhs_no, criteria)
329328

330329
# When I switch users to BCSS "England" as user role "Screening Centre Manager" (and remember session)
331-
user_role = switch_user(page, "Screening Centre Manager", remember_user=True)
330+
user_role = UserTools.switch_user(
331+
page, "Screening Centre Manager", remember_user=True
332+
)
332333

333334
# And I view the subject
334335
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
@@ -371,19 +372,19 @@ def test_scenario_8(page: Page) -> None:
371372
# When I process the open "A397" letter batch for my subject
372373
# Then my subject has been updated as follows:
373374
batch_processing(
374-
page,
375-
"A397",
376-
"Discharge from screening round - no contact (letter to patient)",
377-
"A391 - Patient Discharge Letter Printed - No Patient Contact",
375+
page=page,
376+
batch_type="A397",
377+
batch_description="Discharge from screening round - no contact (letter to patient)",
378+
latest_event_status="A391 - Patient Discharge Letter Printed - No Patient Contact",
378379
)
379380

380381
# And there is a "A391" letter batch for my subject with the exact title "Discharge from screening round - no contact (letter to GP)"
381382
# When I process the open "A391 - Discharge from screening round - no contact (letter to GP)" letter batch for my subject
382383
batch_processing(
383-
page,
384-
"A391",
385-
"Discharge from screening round - no contact (letter to GP)",
386-
"A351 - GP Discharge Letter Printed - No Patient Contact",
384+
page=page,
385+
batch_type="A391",
386+
batch_description="Discharge from screening round - no contact (letter to GP)",
387+
latest_event_status="A351 - GP Discharge Letter Printed - No Patient Contact",
387388
)
388389

389390
# Then my subject has been updated as follows:
@@ -419,7 +420,7 @@ def test_scenario_8(page: Page) -> None:
419420
screening_subject_page_searcher.navigate_to_subject_summary_page(page, nhs_no)
420421

421422
# And I reopen the subject's episode for "Reopen to Reschedule Diagnostic Test"
422-
# SubjectScreeningSummaryPage(page).click_reopen_fobt_screening_episode_button()
423+
SubjectScreeningSummaryPage(page).click_reopen_fobt_screening_episode_button()
423424
ReopenFOBTScreeningEpisodePage(
424425
page
425426
).click_reopen_to_reschedule_diagnostic_test_button()
@@ -632,7 +633,9 @@ def test_scenario_8(page: Page) -> None:
632633

633634
# And I set the practitioner appointment date to "today"
634635
# And I book the earliest available post investigation appointment on this date
635-
book_post_investigation_appointment(page, "The Royal Hospital (Wolverhampton)", 1)
636+
book_post_investigation_appointment(
637+
page, "The Royal Hospital (Wolverhampton)", 1, "12:00"
638+
)
636639

637640
# Then my subject has been updated as follows:
638641
criteria = {
@@ -645,10 +648,10 @@ def test_scenario_8(page: Page) -> None:
645648
# Then my subject has been updated as follows:
646649
# | Latest event status | A415 Post-investigation Appointment Invitation Letter Printed |
647650
batch_processing(
648-
page,
649-
"A410",
650-
"Post-Investigation Appointment Invitation Letter",
651-
"A415 - Post-investigation Appointment Invitation Letter Printed",
651+
page=page,
652+
batch_type="A410",
653+
batch_description="Post-Investigation Appointment Invitation Letter",
654+
latest_event_status="A415 - Post-investigation Appointment Invitation Letter Printed",
652655
)
653656

654657
# When I view the subject
@@ -681,10 +684,10 @@ def test_scenario_8(page: Page) -> None:
681684
# Then my subject has been updated as follows:
682685
# | Latest event status | A395 Refer Another Diagnostic Test |
683686
batch_processing(
684-
page,
685-
"A430",
686-
"Result Letters Following Post-investigation Appointment",
687-
"A395 - Refer Another Diagnostic Test",
687+
page=page,
688+
batch_type="A430",
689+
batch_description="Result Letters Following Post-investigation Appointment",
690+
latest_event_status="A395 - Refer Another Diagnostic Test",
688691
)
689692

690693
# When I view the subject
@@ -919,10 +922,10 @@ def test_scenario_8(page: Page) -> None:
919922
# # When I process the open "A318" letter batch for my subject
920923
# # Then my subject has been updated as follows:
921924
batch_processing(
922-
page,
923-
"A318",
924-
"Result Letters - No Post-investigation Appointment",
925-
"A380 - Failed Diagnostic Test - Refer Another",
925+
page=page,
926+
batch_type="A318",
927+
batch_description="Result Letters - No Post-investigation Appointment",
928+
latest_event_status="A380 - Failed Diagnostic Test - Refer Another",
926929
)
927930

928931
# When I view the subject
@@ -945,10 +948,10 @@ def test_scenario_8(page: Page) -> None:
945948
# # When I process the open "A397" letter batch for my subject
946949
# # Then my subject has been updated as follows:
947950
batch_processing(
948-
page,
949-
"A397",
950-
"Discharge from screening round - no contact (letter to patient)",
951-
"A391 - Patient Discharge Letter Printed - No Patient Contact",
951+
page=page,
952+
batch_type="A397",
953+
batch_description="Discharge from screening round - no contact (letter to patient)",
954+
latest_event_status="A391 - Patient Discharge Letter Printed - No Patient Contact",
952955
)
953956

954957
# # When I receive an SSPI update to change their date of birth to "73" years old
@@ -963,10 +966,10 @@ def test_scenario_8(page: Page) -> None:
963966
# And there is a "A391" letter batch for my subject with the exact title "Discharge from screening round - no contact (letter to GP)"
964967
# When I process the open "A391 - Discharge from screening round - no contact (letter to GP)" letter batch for my subject
965968
batch_processing(
966-
page,
967-
"A391",
968-
"Discharge from screening round - no contact (letter to GP)",
969-
"A351 - GP Discharge Letter Printed - No Patient Contact",
969+
page=page,
970+
batch_type="A391",
971+
batch_description="Discharge from screening round - no contact (letter to GP)",
972+
latest_event_status="A351 - GP Discharge Letter Printed - No Patient Contact",
970973
)
971974

972975
# Then my subject has been updated as follows:
@@ -1000,20 +1003,4 @@ def test_scenario_8(page: Page) -> None:
10001003
}
10011004
subject_assertion(nhs_no, criteria, user_role)
10021005

1003-
1004-
# Helper Methods
1005-
def switch_user(
1006-
page, role: str, bcss_code: str = "BCS001", remember_user: bool = False
1007-
):
1008-
"""
1009-
Logs out the current user, navigates to the login page, and logs in as the specified role.
1010-
1011-
Args:
1012-
page: Playwright page object.
1013-
role (str): The user role to log in as (e.g., "Screening Centre Manager").
1014-
bcss_code (str): The BCSS code to use in the login string (default is "BCS001").
1015-
remember_user (bool): Whether to remember the user session (default is False).
1016-
"""
1017-
LogoutPage(page).log_out(close_page=False)
1018-
BasePage(page).go_to_log_in_page()
1019-
return UserTools.user_login(page, f"{role} at {bcss_code}", remember_user)
1006+
LogoutPage(page).log_out()

utils/appointments.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def book_appointments(page: Page, screening_centre: str, site: str) -> None:
133133

134134

135135
def book_post_investigation_appointment(
136-
page: Page, site: str, screening_practitioner_index: int
136+
page: Page, site: str, screening_practitioner_index: int, appointment_start_time: str = "08:00"
137137
) -> None:
138138
"""
139139
Book a post-investigation appointment for a subject.
@@ -154,7 +154,7 @@ def book_post_investigation_appointment(
154154
screening_practitioner_index
155155
)
156156
book_appointments_page.enter_appointment_date(datetime.today())
157-
book_appointments_page.enter_appointment_start_time("08:00")
157+
book_appointments_page.enter_appointment_start_time(appointment_start_time)
158158
book_appointments_page.click_save_button()
159159

160160

utils/user_tools.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
from pathlib import Path
66
from dotenv import load_dotenv
77
from playwright.sync_api import Page
8+
from pages.base_page import BasePage
89
from pages.login.cognito_login_page import CognitoLoginPage
910
from classes.user.user import User
1011
from classes.organisation.organisation import Organisation
1112
from classes.user.user_role_type import UserRoleType
1213
from typing import Optional
1314

15+
from pages.logout.log_out_page import LogoutPage
16+
1417
logger = logging.getLogger(__name__)
1518
USERS_FILE = Path(os.getcwd()) / "users.json"
1619

@@ -105,6 +108,23 @@ def get_user_object(user_details: dict) -> User:
105108

106109
return user
107110

111+
@staticmethod
112+
def switch_user(
113+
page, role: str, bcss_code: str = "BCS001", remember_user: bool = False
114+
):
115+
"""
116+
Logs out the current user, navigates to the login page, and logs in as the specified role.
117+
118+
Args:
119+
page: Playwright page object.
120+
role (str): The user role to log in as (e.g., "Screening Centre Manager").
121+
bcss_code (str): The BCSS code to use in the login string (default is "BCS001").
122+
remember_user (bool): Whether to remember the user session (default is False).
123+
"""
124+
LogoutPage(page).log_out(close_page=False)
125+
BasePage(page).go_to_log_in_page()
126+
return UserTools.user_login(page, f"{role} at {bcss_code}", remember_user)
127+
108128

109129
class UserToolsException(Exception):
110130
pass

0 commit comments

Comments
 (0)