Skip to content

Commit fbc63bd

Browse files
committed
refactoring self refer letter processing test
1 parent c462a6e commit fbc63bd

File tree

1 file changed

+49
-63
lines changed

1 file changed

+49
-63
lines changed

tests/regression/communications_production/test_fit_self_refer_letter_processing.py

Lines changed: 49 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@
4242
# # been changed to use hub BCS02 instead.
4343

4444

45-
@pytest.fixture
46-
def select_user(page: Page):
47-
def _login_as(user_role: str):
48-
# Log in with the specified user
49-
UserTools.user_login(page, user_role)
50-
# Navigate to call and recall page
51-
BasePage(page).go_to_call_and_recall_page()
52-
return page
45+
@pytest.fixture(scope="function", autouse=True)
46+
def before_each(page: Page):
47+
"""
48+
Before every test is executed, this fixture logs in to BCSS as a test user and navigates to the call and recall page
49+
"""
50+
# Log in to BCSS
51+
UserTools.user_login(page, "Hub Manager at BCS02")
5352

54-
return _login_as
53+
# Go to call and recall page
54+
BasePage(page).go_to_call_and_recall_page()
5555

5656

5757
@pytest.mark.regression
5858
@pytest.mark.letters_tests
59-
def test_self_refer_subject_in_my_hub_for_fit(select_user) -> None:
59+
def test_self_refer_subject_in_my_hub_for_fit(page: Page) -> None:
6060
"""
6161
Scenario: Self-refer a subject in my hub for FIT
6262
Given I log in to BCSS "England" as user role "Hub Manager at BCS02"
@@ -71,21 +71,19 @@ def test_self_refer_subject_in_my_hub_for_fit(select_user) -> None:
7171
logging.info("[TEST START] Self-refer subject in my hub for FIT")
7272
user_role = "Hub Manager at BCS02"
7373

74-
# Step 1: Log in and navigate to Generate Invitations page
75-
page = select_user(user_role)
76-
logging.info(f"[LOGIN] Logged in as {user_role}")
74+
# Navigate to Generate Invitations page
7775
CallAndRecallPage(page).go_to_generate_invitations_page()
7876
logging.info("[NAVIGATION] Navigated to Generate Invitations page")
7977

80-
# Step 1a - Retrieve hub info from users.json
78+
# Retrieve hub info from users.json
8179
user_details = UserTools.retrieve_user(user_role)
8280

83-
# Step 2: Confirm no subjects ready to invite
81+
# Confirm no subjects ready to invite
8482
generate_invitations_page = GenerateInvitationsPage(page)
8583
generate_invitations_page.check_self_referral_subjects_ready("currently", "no")
8684
logging.info("[ASSERTION] Confirmed no self-referral subjects are ready")
8785

88-
# Step 3: Try to retrieve eligible subject from DB, fallback to create if none found
86+
# Try to retrieve eligible subject from DB, fallback to create if none found
8987
# Convert user details dictionary into User object for easier handling
9088
user = UserTools.get_user_object(user_details)
9189
# Create empty Subject object to store subject details
@@ -116,28 +114,28 @@ def test_self_refer_subject_in_my_hub_for_fit(select_user) -> None:
116114
# Open the newly created subject record
117115
oracle_subject.open_subject_by_nhs(nhs_number)
118116

119-
# Step 3b: Run stored procedure to include subject in invitation shortlist
117+
# Run stored procedure to include subject in invitation shortlist
120118
OracleDB().execute_stored_procedure("pkg_fobt_call.p_find_next_subjects_to_invite")
121119
logging.info(
122120
"[STORED PROCEDURE] Executed: pkg_fobt_call.p_find_next_subjects_to_invite"
123121
)
124122

125-
# Step 4: View subject
123+
# View subject
126124
base_page = BasePage(page)
127125
subject_screening_page = SubjectScreeningPage(page)
128126
base_page.click_main_menu_link()
129127
base_page.go_to_screening_subject_search_page()
130128
subject_screening_page.search_by_nhs_number(nhs_number)
131129
logging.info("[SUBJECT VIEW] Subject loaded in UI")
132130

133-
# Step 5: Send new kit
131+
# Send new kit
134132
subject_screening_page.click_send_kit_button()
135133
subject_screening_page.complete_send_kit_form(
136134
request_from="Subject", previous_kit_status="Lost", note_text="Test"
137135
)
138136
logging.info("[KIT SENT] New kit dispatched")
139137

140-
# Step 6: Rebuild invitation shortlist to include self-referral subject
138+
# Rebuild invitation shortlist to include self-referral subject
141139
# Arguments:
142140
# - pi_number_of_weeks: how far ahead to look for subjects (e.g. 20)
143141
# - pi_max_number_of_subjects: how many subjects to shortlist (e.g. 100)
@@ -175,7 +173,7 @@ def test_self_refer_subject_in_my_hub_for_fit(select_user) -> None:
175173

176174
@pytest.mark.regression
177175
@pytest.mark.letters_tests
178-
def test_invite_self_referral_creates_s83f_batch(select_user) -> None:
176+
def test_invite_self_referral_creates_s83f_batch(page: Page) -> None:
179177
"""
180178
Scenario: Invite a self-refer subject for FIT creates or updates an S83f letter batch
181179
Given I log in to BCSS "England" as user role "HubManagerAtBCS02"
@@ -189,47 +187,44 @@ def test_invite_self_referral_creates_s83f_batch(select_user) -> None:
189187
logging.info(
190188
"[TEST START] Invite self-referral creates or updates an S83f letter batch"
191189
)
192-
user_role = "Hub Manager at BCS02"
193190

194-
# Step 1: Log in and navigate to Generate Invitations page
195-
page = select_user(user_role)
196-
logging.info(f"[LOGIN] Logged in as {user_role}")
191+
# Navigate to Generate Invitations page
197192
CallAndRecallPage(page).go_to_generate_invitations_page()
198193
logging.info("[NAVIGATION] Navigated to Generate Invitations page")
199194

200-
# Step 2: Confirm self-referral subjects are ready
195+
# Confirm self-referral subjects are ready
201196
generate_invitations_page = GenerateInvitationsPage(page)
202197
generate_invitations_page.check_self_referral_subjects_ready("currently", "some")
203198
logging.info("[ASSERTION] Confirmed self-referral subjects are ready")
204199

205-
# Step 3: Generate invitations
200+
# Generate invitations
206201
generate_invitations_page.click_generate_invitations_button()
207202
logging.info("[ACTION] Clicked Generate Invitations button")
208203
generate_invitations_page.wait_for_self_referral_invitation_generation_complete()
209204
logging.info("[WAIT] Invitation generation completed")
210205

211-
# Step 4: Navigate to Active Batch List
206+
# Navigate to Active Batch List
212207
base_page = BasePage(page)
213208
active_batch_page = ActiveBatchListPage(page)
214209
base_page.click_main_menu_link()
215210
base_page.go_to_communications_production_page()
216211
CommunicationsProductionPage(page).go_to_active_batch_list_page()
217212
logging.info("[NAVIGATION] Navigated to Active Batch List page")
218213

219-
# Step 5: Filter by "Original" type and "Open" status
214+
# Filter by "Original" type and "Open" status
220215
active_batch_page.enter_type_filter("Original")
221216
active_batch_page.enter_event_code_filter("S83")
222217
logging.info("[FILTER] Applied filters: Type='Original', Event Code='S83'")
223218

224-
# Step 6: Assert S83f batch is present
219+
# Assert S83f batch is present
225220
active_batch_page.assert_s83f_batch_present()
226221
logging.info("[ASSERTION PASSED] S83f batch is present in Active Batch List")
227222

228223

229224
# # Note that this "When I view ..." includes 3 steps from above (view active batch list, and filter by type and status), and clicks the batch ID link
230225
@pytest.mark.regression
231226
@pytest.mark.letters_tests
232-
def test_s83f_letter_batch_has_three_components(select_user) -> None:
227+
def test_s83f_letter_batch_has_three_components(page: Page) -> None:
233228
"""
234229
Scenario: There are 3 components in the S83f letter batch
235230
Given I log in to BCSS "England" as user role "HubManagerAtBCS02"
@@ -240,18 +235,15 @@ def test_s83f_letter_batch_has_three_components(select_user) -> None:
240235
And letter type "Invitation & Test Kit (Self-referral) (FIT)" with file format "FIT-KIT-CSV" is listed
241236
"""
242237
logging.info("[TEST START] S83f letter batch has three components")
243-
user_role = "Hub Manager at BCS02"
244238

245-
# Step 1: Log in
246-
page = select_user(user_role)
247-
logging.info(f"[LOGIN] Logged in as {user_role}")
239+
# Navigate to Active Batch List and filter
248240
base_page = BasePage(page)
249241
active_batch_page = ActiveBatchListPage(page)
250-
251-
# Step 2: Navigate to Active Batch List and filter
252242
base_page.click_main_menu_link()
253243
base_page.go_to_communications_production_page()
254244
CommunicationsProductionPage(page).go_to_active_batch_list_page()
245+
246+
# Filter by "Original" type, "S83" event code, and description
255247
logging.info("[NAVIGATION] Navigated to Active Batch List page")
256248
active_batch_page.enter_type_filter("Original")
257249
active_batch_page.enter_event_code_filter("S83")
@@ -262,15 +254,15 @@ def test_s83f_letter_batch_has_three_components(select_user) -> None:
262254
"[FILTER] Applied filters: Type='Original', Event Code='S83', Description='Invitation & Test Kit (Self-referral) (FIT)'"
263255
)
264256

265-
# Step 3: Open the matching batch
257+
# Open the matching batch
266258
active_batch_page.open_letter_batch(
267259
batch_type="Original",
268260
status="Open",
269261
description="Invitation & Test Kit (Self-referral) (FIT)",
270262
)
271263
logging.info("[ACTION] Opened S83f batch")
272264

273-
# Step 4: Assert letter components
265+
# Assert letter components
274266
letter_batch_page = LetterBatchDetailsPage(page)
275267
letter_batch_page.assert_letter_component_present(
276268
"Invitation & Test Kit (Self-referral) (FIT)", "PDF-A4-V03"
@@ -296,7 +288,7 @@ def test_s83f_letter_batch_has_three_components(select_user) -> None:
296288

297289
@pytest.mark.regression
298290
@pytest.mark.letters_tests
299-
def test_before_confirming_s83f_batch_subject_status_is_s83(select_user) -> None:
291+
def test_before_confirming_s83f_batch_subject_status_is_s83(page: Page) -> None:
300292
"""
301293
Scenario: Before confirming the S83f letter batch the self-referred subject's latest event status is S83
302294
Given I log in to BCSS "England" as user role "HubManagerAtBCS02"
@@ -307,19 +299,16 @@ def test_before_confirming_s83f_batch_subject_status_is_s83(select_user) -> None
307299
Then the subject is at latest event status "S83 - Selected for Screening (Self-referral)"
308300
"""
309301
logging.info("[TEST START] Before confirming S83f batch, subject status is S83")
310-
user_role = "Hub Manager at BCS02"
311302

312-
# Step 1: Log in
313-
page = select_user(user_role)
314-
logging.info(f"[LOGIN] Logged in as {user_role}")
303+
# Navigate to Active Batch List and filter
315304
base_page = BasePage(page)
316305
active_batch_page = ActiveBatchListPage(page)
317-
318-
# Step 2: Navigate to Active Batch List and filter
319306
base_page.click_main_menu_link()
320307
base_page.go_to_communications_production_page()
321308
CommunicationsProductionPage(page).go_to_active_batch_list_page()
322309
logging.info("[NAVIGATION] Navigated to Active Batch List page")
310+
311+
# Filter by "Original" type, "S83" event code, and description
323312
active_batch_page.enter_type_filter("Original")
324313
active_batch_page.enter_event_code_filter("S83")
325314
active_batch_page.enter_description_filter(
@@ -328,24 +317,24 @@ def test_before_confirming_s83f_batch_subject_status_is_s83(select_user) -> None
328317
logging.info(
329318
"[FILTER] Applied filters: Type='Original', Event Code='S83', Description='Invitation & Test Kit (Self-referral) (FIT)'"
330319
)
331-
# Step 3: Identify the S83f batch ID
320+
# Identify the S83f batch ID
332321
batch_id_link = page.locator("a[href*='/letters/activebatch/']").first
333322
batch_id = batch_id_link.inner_text().strip()
334323
logging.info(f"[BATCH IDENTIFIED] Batch ID: {batch_id}")
335324

336-
# Step 4: Query DB for subjects in the batch
325+
# Query DB for subjects in the batch
337326
nhs_df = get_nhs_no_from_batch_id(batch_id)
338327
nhs_number = nhs_df.iloc[0]["subject_nhs_number"]
339328
logging.info(f"[SUBJECT IDENTIFIED] NHS number: {nhs_number}")
340329

341-
# Step 5: View the subject
330+
# View the subject
342331
subject_screening_page = SubjectScreeningPage(page)
343332
base_page.click_main_menu_link()
344333
base_page.go_to_screening_subject_search_page()
345334
subject_screening_page.search_by_nhs_number(nhs_number)
346335
logging.info("[SUBJECT VIEW] Subject loaded in UI")
347336

348-
# Step 6: Assert latest event status is S83
337+
# Assert latest event status is S83
349338
summary_page = SubjectScreeningSummaryPage(page)
350339
summary_page.verify_latest_event_status_value(
351340
"S83 - Selected for Screening (Self-referral)"
@@ -357,7 +346,7 @@ def test_before_confirming_s83f_batch_subject_status_is_s83(select_user) -> None
357346

358347
@pytest.mark.regression
359348
@pytest.mark.letters_tests
360-
def test_confirm_s83f_batch_subject_has_s84_event_and_letters(select_user) -> None:
349+
def test_confirm_s83f_batch_subject_has_s84_event_and_letters(page: Page) -> None:
361350
"""
362351
Scenario: When the S83f batch has been confirmed the self-referred subject has a self-referral invitation and test kit sent
363352
Given I log in to BCSS "England" as user role "HubManagerAtBCS02"
@@ -371,19 +360,16 @@ def test_confirm_s83f_batch_subject_has_s84_event_and_letters(select_user) -> No
371360
And the latest "S84 - Invitation and Test Kit Sent (Self-referral)" event shows "2" "View Letter" links
372361
"""
373362
logging.info("[TEST START] Confirm S83f batch: subject has S84 event and letters")
374-
user_role = "Hub Manager at BCS02"
375363

376-
# Step 1: Log in
377-
page = select_user(user_role)
378-
logging.info(f"[LOGIN] Logged in as {user_role}")
364+
# Navigate to Active Batch List and filter
379365
base_page = BasePage(page)
380366
active_batch_page = ActiveBatchListPage(page)
381-
382-
# Step 2: Navigate to Active Batch List and filter
383367
base_page.click_main_menu_link()
384368
base_page.go_to_communications_production_page()
385369
CommunicationsProductionPage(page).go_to_active_batch_list_page()
386370
logging.info("[NAVIGATION] Navigated to Active Batch List page")
371+
372+
# Filter by "Original" type, "S83" event code, and description
387373
active_batch_page.enter_type_filter("Original")
388374
active_batch_page.enter_event_code_filter("S83")
389375
active_batch_page.enter_description_filter(
@@ -393,7 +379,7 @@ def test_confirm_s83f_batch_subject_has_s84_event_and_letters(select_user) -> No
393379
"[FILTER] Applied filters: Type='Original', Event Code='S83', Description='Invitation & Test Kit (Self-referral) (FIT)'"
394380
)
395381

396-
# Step 4: Identify a subject in the batch using DB query
382+
# Identify a subject in the batch using DB query
397383
batch_id_link = page.locator("a[href*='/letters/activebatch/']").first
398384
batch_id = batch_id_link.inner_text().strip()
399385
logging.info(f"[BATCH IDENTIFIED] Batch ID: {batch_id}")
@@ -402,24 +388,24 @@ def test_confirm_s83f_batch_subject_has_s84_event_and_letters(select_user) -> No
402388
nhs_number = nhs_df.iloc[0]["subject_nhs_number"]
403389
logging.info(f"[SUBJECT IDENTIFIED] NHS number: {nhs_number}")
404390

405-
# Step 3: Open the matching batch
391+
# Open the matching batch
406392
active_batch_page.open_letter_batch(
407393
batch_type="Original",
408394
description="Invitation & Test Kit (Self-referral) (FIT)",
409395
)
410396
logging.info("[ACTION] Opened S83f batch")
411397

412-
# Step 5: Prepare the batch
398+
# Prepare the batch
413399
batch_processing.prepare_and_print_batch(page, link_text=batch_id)
414400

415-
# Step 6: View the subject
401+
# View the subject
416402
subject_screening_page = SubjectScreeningPage(page)
417403
base_page.click_main_menu_link()
418404
base_page.go_to_screening_subject_search_page()
419405
subject_screening_page.search_by_nhs_number(nhs_number)
420406
logging.info("[SUBJECT VIEW] Subject loaded in UI")
421407

422-
# Step 7: Assert latest event status is S84
408+
# Assert latest event status is S84
423409
summary_page = SubjectScreeningSummaryPage(page)
424410
summary_page.verify_latest_event_status_value(
425411
"S84 - Invitation and Test Kit Sent (Self-referral)"
@@ -428,7 +414,7 @@ def test_confirm_s83f_batch_subject_has_s84_event_and_letters(select_user) -> No
428414
"[ASSERTION PASSED] Subject is at status: S84 - Invitation and Test Kit Sent (Self-referral)"
429415
)
430416

431-
# Step 8: Assert 2 "View Letter" links for S84
417+
# Assert 2 "View Letter" links for S84
432418
summary_page.click_list_episodes()
433419
summary_page.click_view_events_link()
434420
summary_page.assert_view_letter_links_for_event(

0 commit comments

Comments
 (0)