Skip to content

Commit 1ee6bb4

Browse files
Addressing PR comments
1 parent 90ab847 commit 1ee6bb4

File tree

5 files changed

+20
-88
lines changed

5 files changed

+20
-88
lines changed

pages/datasets/investigation_dataset_page.py

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from playwright.sync_api import Page, expect, Locator
23
from pages.base_page import BasePage
34
from enum import StrEnum
@@ -7,7 +8,6 @@
78
)
89
from typing import Optional
910
import logging
10-
import re
1111

1212

1313
class InvestigationDatasetsPage(BasePage):
@@ -354,7 +354,6 @@ def select_polyp1_pathologist_option_index(self, option: int) -> None:
354354
"""
355355
This method is designed to select a pathologist from the pathologist options.
356356
It clicks on the pathologist link and selects the given option by index.
357-
358357
Args:
359358
option (int): The index of the option to select from the pathologist options.
360359
"""
@@ -370,7 +369,6 @@ def select_lookup_option_index(self, option: int) -> None:
370369
"""
371370
This method is designed to select a lookup option by index.
372371
It clicks on the lookup link and selects the given option by index.
373-
374372
Args:
375373
option (int): The index of the option to select from the lookup options.
376374
"""
@@ -394,7 +392,6 @@ def assert_polyp_algorithm_size(
394392
"""
395393
This method asserts that the polyp size is as expected.
396394
It retrieves the polyp size from the page and compares it with the expected value.
397-
398395
Args:
399396
polyp_number (int): The number of the polyp to check (1 or 2).
400397
expected_value (int): The expected value of the polyp size.
@@ -426,7 +423,6 @@ def assert_polyp_category(
426423
"""
427424
This method asserts that the polyp category is as expected.
428425
It retrieves the polyp category from the page and compares it with the expected value.
429-
430426
Args:
431427
polyp_number (int): The number of the polyp to check (1 or 2).
432428
expected_value (str): The expected value of the polyp category.
@@ -474,7 +470,6 @@ def get_dataset_id(self) -> int:
474470
def click_polyp_add_intervention_button(self, polyp_number: int) -> None:
475471
"""
476472
Clicks the add intervention button for the specified polyp number.
477-
478473
Args:
479474
polyp_number (int): The number of the polyp.
480475
"""
@@ -490,15 +485,12 @@ def populate_select_by_id(
490485
) -> None:
491486
"""
492487
Populates a <select> element using a predictable ID pattern based on field name and polyp number.
493-
494488
This method is useful when label-based selectors (e.g., using `right-of(:text(...))`) are unreliable
495489
due to ambiguous or repeated text labels on the page.
496-
497490
Args:
498491
field_base (str): The base name of the field (e.g., "POLYP_PATHOLOGY_LOST").
499492
polyp_number (int): The polyp index (e.g., 1 for the first polyp).
500493
option (str): The value to be selected from the dropdown.
501-
502494
Example:
503495
populate_select_by_id("POLYP_PATHOLOGY_LOST", 1, YesNoOptions.YES)
504496
# Selects 'Yes' in <select id="UI_POLYP_PATHOLOGY_LOST1_1">
@@ -519,14 +511,12 @@ def is_edit_dataset_button_visible(self) -> bool:
519511
def is_dataset_section_present(self, dataset_section_name: str) -> bool | None:
520512
"""
521513
Checks if a section of the investigation dataset is present
522-
523514
Args:
524515
dataset_section_name (str): The name of the section you want to check
525516
- Investigation Dataset
526517
- Drug Information
527518
- Endoscopy Information
528519
- etc...
529-
530520
Returns:
531521
bool: True if it is present, False if it is not
532522
"""
@@ -550,13 +540,10 @@ def is_dataset_section_present(self, dataset_section_name: str) -> bool | None:
550540
def get_dataset_section(self, dataset_section_name: str) -> Locator | None:
551541
"""
552542
Retrieves a dataset section by matching its header text.
553-
554543
Searches through all elements representing dataset sections, looking for one whose
555544
first <h4> header text matches the provided section name (case-insensitive).
556-
557545
Args:
558546
dataset_section_name (str): The name of the dataset section to locate.
559-
560547
Returns:
561548
Locator | None: A Playwright Locator for the matching section, or None if not found.
562549
"""
@@ -583,17 +570,13 @@ def get_dataset_subsection(
583570
) -> Locator | None:
584571
"""
585572
Retrieves a specific subsection within a dataset section by matching the subsection's header text.
586-
587573
The method first searches through elements with the `.DatasetSubSection` class.
588574
If the subsection is not found, it continues searching within `.DatasetSubSectionGroup` elements.
589-
590575
Args:
591576
dataset_section_name (str): The name of the dataset section that contains the subsection.
592577
dataset_subsection_name (str): The name of the subsection to locate.
593-
594578
Returns:
595579
Locator | None: A Playwright Locator for the found subsection, or None if not found.
596-
597580
Raises:
598581
ValueError: If the specified dataset section cannot be found.
599582
"""
@@ -647,7 +630,6 @@ def are_fields_on_page(
647630
) -> bool:
648631
"""
649632
Checks if the given fields are present in a section or subsection, with optional visibility checks.
650-
651633
Args:
652634
section_name (str): The name of the dataset section.
653635
subsection_name (str | None): The name of the subsection, if any.
@@ -656,7 +638,6 @@ def are_fields_on_page(
656638
- True → fields must be visible
657639
- False → fields must be not visible
658640
- None → visibility doesn't matter (just check presence)
659-
660641
Returns:
661642
bool: True if all conditions are met; False otherwise.
662643
"""
@@ -680,6 +661,13 @@ def are_fields_on_page(
680661
]
681662

682663
def label_matches(idx: int) -> bool:
664+
"""
665+
Checks if the label at the given index matches the visibility condition.
666+
Args:
667+
idx (int): The index of the label to check.
668+
Returns:
669+
bool: True if the label matches the visibility condition, False otherwise.
670+
"""
683671
if visible is True:
684672
return label_elements[idx].is_visible()
685673
if visible is False:
@@ -726,7 +714,6 @@ def check_visibility_of_drug_type(
726714
drug_type (str): The drug type to check
727715
drug_number (int): The number of the drug type cell to check.
728716
expected_text (str): The expected text content of the cell.
729-
730717
Returns:
731718
bool: True if the visibility matches the expectation, False otherwise.
732719
"""
@@ -738,12 +725,10 @@ def check_visibility_of_drug_dose(
738725
) -> bool:
739726
"""
740727
Checks the visibility of the drug dose input cell.
741-
742728
Args:
743729
drug_type (str): The drug type to check
744730
drug_number (int): The number of the drug dose cell to check.
745731
visible (bool): True if the field should be visible, False if it should not.
746-
747732
Returns:
748733
bool: True if the visibility matches the expectation, False otherwise.
749734
"""
@@ -755,12 +740,10 @@ def assert_drug_type_text(
755740
) -> None:
756741
"""
757742
Asserts that the drug type input cell contains the expected text.
758-
759743
Args:
760744
drug_type (str): The drug type to check
761745
drug_number (int): The number of the drug type cell to check.
762746
expected_text (str): The expected text content of the cell.
763-
764747
Raises:
765748
AssertionError: If the actual text does not match the expected text.
766749
"""
@@ -778,12 +761,10 @@ def assert_drug_dose_text(
778761
) -> None:
779762
"""
780763
Asserts that the drug dose input cell contains the expected text.
781-
782764
Args:
783765
drug_type (str): The drug type to check
784766
drug_number (int): The number of the drug dose cell to check.
785767
expected_text (str): The expected text content of the cell.
786-
787768
Raises:
788769
AssertionError: If the actual text does not match the expected text.
789770
"""
@@ -799,7 +780,6 @@ def assert_drug_dose_text(
799780
def get_drug_type_locator(self, drug_type: str, drug_number: int) -> Locator:
800781
"""
801782
Returns the locator for the matching drug type and number
802-
803783
Args:
804784
drug_type (str): The drug type to check
805785
drug_number (int): The number of the drug to check
@@ -815,7 +795,6 @@ def get_drug_type_locator(self, drug_type: str, drug_number: int) -> Locator:
815795
def get_drug_dose_locator(self, drug_type: str, drug_number: int) -> Locator:
816796
"""
817797
Returns the locator for the matching drug type and number
818-
819798
Args:
820799
drug_type (str): The drug type to check
821800
drug_number (int): The number of the drug to check
@@ -833,7 +812,6 @@ def assert_drug_type_options(
833812
) -> None:
834813
"""
835814
Asserts that the options in the drug type dropdown are as expected.
836-
837815
Args:
838816
drug_type (str): The drug type to check
839817
drug_number (int): The number of the drug to check
@@ -861,7 +839,6 @@ def assert_all_drug_information(
861839
) -> None:
862840
"""
863841
Loops through a dictionary of drug types/doses and calls the relevant assertion methods
864-
865842
Args:
866843
drug_information (dict): A dictionary containing all drug types and dosages to assert
867844
drug_type_label (str): The type of drug to do the assertion against. E.g. 'Bowel Preparation Administered'
@@ -879,12 +856,12 @@ def assert_all_drug_information(
879856

880857
max_drug_number = max(drug_numbers)
881858

882-
for i in range(1, max_drug_number + 1):
883-
drug_type = drug_information.get(f"drug_type{i}")
884-
drug_dose = drug_information.get(f"drug_dose{i}")
859+
for drug_index in range(1, max_drug_number + 1):
860+
drug_type = drug_information.get(f"drug_type{drug_index}")
861+
drug_dose = drug_information.get(f"drug_dose{drug_index}")
885862

886863
if drug_type is not None:
887-
self.assert_drug_type_text(drug_type_label, i, drug_type)
864+
self.assert_drug_type_text(drug_type_label, drug_index, drug_type)
888865

889866
# Match-case to assert drug dose unit
890867
match drug_type:
@@ -920,15 +897,16 @@ def assert_all_drug_information(
920897
expected_unit = None
921898

922899
if expected_unit is not None:
923-
self.assert_drug_dose_unit_text(drug_type_label, i, expected_unit)
900+
self.assert_drug_dose_unit_text(
901+
drug_type_label, drug_index, expected_unit
902+
)
924903

925904
if drug_dose is not None:
926-
self.assert_drug_dose_text(drug_type_label, i, drug_dose)
905+
self.assert_drug_dose_text(drug_type_label, drug_index, drug_dose)
927906

928907
def get_drug_dose_unit_locator(self, drug_type: str, drug_number: int) -> Locator:
929908
"""
930909
Returns the locator for the matching drug type and number
931-
932910
Args:
933911
drug_type (str): The drug type to check
934912
drug_number (int): The number of the drug to check
@@ -946,12 +924,10 @@ def assert_drug_dose_unit_text(
946924
) -> None:
947925
"""
948926
Asserts that the drug dose unit contains the expected text.
949-
950927
Args:
951928
drug_type (str): The drug type to check
952929
drug_number (int): The number of the drug dose cell to check.
953930
expected_text (str): The expected text content of the cell.
954-
955931
Raises:
956932
AssertionError: If the actual text does not match the expected text.
957933
"""

pages/login/select_job_role_page.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ def __init__(self, page: Page):
1414
def select_option_for_job_role(self, job_role: str) -> None:
1515
"""
1616
Selects a job from the job role dropdown
17-
1817
Args:
1918
job_role (str): This is the text of the role you want to select (e.g. Screening Practitioner)
2019
"""

tests/regression/subject/episodes/datasets/investigation/endoscopy/test_endoscopy_investigation_dataset_scenarios.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ def test_check_different_hub_roles_access_to_edit_endoscopy_investigation_datase
168168
) -> None:
169169
"""
170170
Scenario: Check different hub roles' access to edit an endoscopy investigation dataset
171-
172171
This scenario only checks roles which have permission to at least view a dataset.
173172
"""
174173
nhs_no = get_subject_with_incomplete_endoscopy_investigation_dataset()
@@ -243,7 +242,6 @@ def test_check_different_screening_centre_roles_access_to_edit_endoscopy_investi
243242
) -> None:
244243
"""
245244
Scenario: Check different screening centre roles' access to edit an endoscopy investigation dataset
246-
247245
This scenario only checks roles which have permission to at least view a dataset.
248246
"""
249247
nhs_no = get_subject_with_incomplete_endoscopy_investigation_dataset()
@@ -331,7 +329,6 @@ def test_check_different_national_and_qa_roles_access_to_edit_endoscopy_investig
331329
) -> None:
332330
"""
333331
Scenario: Check different national and QA roles' access to edit an endoscopy investigation dataset
334-
335332
This scenario only checks roles which have permission to at least view a dataset.
336333
"""
337334
nhs_no = get_subject_with_incomplete_endoscopy_investigation_dataset()
@@ -365,8 +362,7 @@ def test_check_correct_sections_displayed_in_colonoscopy_investigation_dataset(
365362
page: Page,
366363
) -> None:
367364
"""
368-
Check the correct sections are displayed in new Colonoscopy investigation dataset
369-
365+
Scenario: Check the correct sections are displayed in new Colonoscopy investigation dataset
370366
This scenario just checks that the dataset contains the expected sections and that they are labelled for an endoscopy dataset rather than a radiology dataset.
371367
"""
372368
nhs_no = get_subject_with_new_colonoscopy_investigation_dataset()
@@ -469,8 +465,7 @@ def test_check_field_visibility_and_default_values_in_colonoscopy_investigation_
469465
page: Page,
470466
) -> None:
471467
"""
472-
Check field visibility and default values in the Investigation Dataset section of a new Colonoscopy investigation dataset
473-
468+
Scenario: Check field visibility and default values in the Investigation Dataset section of a new Colonoscopy investigation dataset
474469
The top section of the investigation dataset, labelled Investigation Dataset but referred to as the Diagnostic Test section in the spec, contains mostly read-only fields. This scenario checks that the expected fields are included, and carries out limited checks of the default values (many of these values can only be sensibly tested in a scenario which creates the test from scratch).
475470
"""
476471
nhs_no = get_subject_with_new_colonoscopy_investigation_dataset()
@@ -644,7 +639,6 @@ def test_check_cross_field_validation_is_mandatory_at_completion(page: Page) ->
644639
def test_check_behaviour_of_aspirant_endoscopist_fields(page: Page) -> None:
645640
"""
646641
Scenario: Check the behaviour of the Aspirant Endoscopist fields
647-
648642
This tests:
649643
> Aspirant Endoscopist Not Present field is enabled until an Aspirant Endoscopist is selected
650644
> If Aspirant Endoscopist Not Present is ticked, it is automatically unticked and disabled when an Aspirant Endoscopist is selected
@@ -843,17 +837,14 @@ def test_check_behaviour_of_drug_information_fields_in_incomplete_dataset(
843837
) -> None:
844838
"""
845839
Scenario: Check the behaviour of the Bowel Preparation Administered fields in the Drug Information section in an incomplete endoscopy investigation dataset
846-
847840
This scenario tests:
848841
> The contents of dropdown lists.
849842
> The default values of fields.
850843
> The visibility of drug type/dose fields.
851844
> The correct dose units are displayed.
852-
853845
Immediate validation:
854846
> A "drug administered" field cannot be set to "No" or null if associated drugs and doses are listed.
855847
> Dose values must be within the valid range for the drug type, and have the valid number of decimal places (although invalid values are not removed).
856-
857848
"On save" validation:
858849
> Bowel Preparation Administered cannot be set to "No" if the Endoscopist Defined Extent is beyond Rectum. (The reverse of this is not tested as this scenario does not save changes).
859850
> The same drug type cannot be selected more than once
@@ -1253,18 +1244,15 @@ def check_role_access_to_edit_investigation_dataset(
12531244
) -> None:
12541245
"""
12551246
Verifies whether a user with a specific role has access to edit the Investigation Dataset.
1256-
12571247
This function logs in as a given user role, navigates to the subject's investigation dataset,
12581248
and asserts the visibility of the "Edit Dataset" button based on expected access.
1259-
12601249
Args:
12611250
page (Page): The Playwright page object for interacting with the UI.
12621251
nhs_no (str): NHS number used to search for the subject.
12631252
role (str): The user role to log in as.
12641253
edit_access (bool): True if the role is expected to have edit access; False otherwise.
12651254
role_logging (str): Descriptive log message for tracking which role is being tested.
12661255
role_type (Optional[str]): Optional job role selection (e.g., if multiple job roles exist).
1267-
12681256
Raises:
12691257
AssertionError: If the visibility of the "Edit Dataset" button does not match the expected access.
12701258
"""
@@ -1311,7 +1299,6 @@ def get_subject_with_incomplete_endoscopy_investigation_dataset() -> str:
13111299
Gets a subject with the following criteria:
13121300
"latest episode status": "open"
13131301
"latest episode latest investigation dataset": "endoscopy_incomplete"
1314-
13151302
Returns:
13161303
str: The nhs number of a subject matching the criteria
13171304
"""
@@ -1342,7 +1329,6 @@ def get_subject_with_new_colonoscopy_investigation_dataset() -> str:
13421329
Gets a subject with the following criteria:
13431330
"latest episode status": "open",
13441331
"latest episode latest investigation dataset": "colonoscopy_new",
1345-
13461332
Returns:
13471333
str: The nhs number of a subject matching the criteria
13481334
"""

0 commit comments

Comments
 (0)