Skip to content

Commit cb40bdc

Browse files
committed
Adding test
1 parent 8aa002a commit cb40bdc

File tree

4 files changed

+139
-3
lines changed

4 files changed

+139
-3
lines changed

pages/organisations/list_all_organisations.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from playwright.sync_api import Page
2+
from playwright.sync_api import Page, expect
33
from pages.base_page import BasePage
44
from enum import StrEnum
55
from utils.table_util import TableUtils
@@ -54,6 +54,11 @@ def search_organisation_code(self, org_code: str) -> None:
5454
self.search_org_code.fill(org_code)
5555
self.search_org_code.press("Enter")
5656

57+
def verify_no_organisation_record_found(self, text: str) -> None:
58+
"""Verifies that no organisation record is found."""
59+
logging.info("Verifying that no organisation record is found")
60+
expect(self.page.locator('form[name="frm"]')).to_contain_text(text)
61+
5762

5863
class OrganisationType(StrEnum):
5964
BCS_PROGRAMME_HUB = "1002"

pages/organisations/list_all_sites.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ def __init__(self, page: Page):
1414
# Initialize TableUtils for the table with id="displayRS"
1515
self.list_all_org_table = TableUtils(page, "#listAllOrgsTable")
1616

17-
# List All Organisations links
17+
# List All Site links
1818
self.select_site_type = self.page.locator("#siteTypeId")
1919
self.create_new_site = self.page.get_by_role("button", name="Create New Site")
20+
self.site_code = self.page.locator('input[name="SITE_CODE"]')
2021

2122
def select_site_type_option(self, option: str) -> None:
2223
"""
@@ -28,6 +29,23 @@ def click_create_new_site(self) -> None:
2829
"""Clicks the 'Create New Org' button."""
2930
self.create_new_site.click()
3031

32+
def search_site_code(self, site_code: str) -> None:
33+
"""
34+
This method is designed to search for an site by its code.
35+
Args:
36+
org_code (str): The site code to search for.
37+
Returns:
38+
None
39+
"""
40+
logging.info(f"Searching for Site with code: {site_code}")
41+
self.site_code.fill(site_code)
42+
self.site_code.press("Enter")
43+
44+
def verify_no_site_record_found(self, text: str) -> None:
45+
"""Verifies that no site record is found."""
46+
logging.info("Verifying that no site record is found")
47+
expect(self.page.locator('form[name="frm"]')).to_contain_text(text)
48+
3149

3250
class SiteType(StrEnum):
3351
CARE_TRUST_SITE = "1020"

tests/regression/organisation/test_organisation_and_site_details.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from ast import List, Or
2+
from re import L
23
import pytest
34
from playwright.sync_api import Page, expect
45
from pages.base_page import BasePage
@@ -18,6 +19,10 @@
1819
from utils.user_tools import UserTools
1920
from utils.table_util import TableUtils
2021
from utils.calendar_picker import CalendarPicker
22+
from utils.oracle.oracle_specific_functions import (
23+
delete_organisations_created_for_test,
24+
delete_sites_created_for_test,
25+
)
2126
from datetime import datetime
2227

2328

@@ -111,7 +116,31 @@ def test_view_and_edit_organisation_values_z9z1s(page) -> None:
111116
@pytest.mark.organisations_and_contacts_develop_level_tests
112117
def test_remove_all_created_organisation(page) -> None:
113118
"""
114-
Verifies that the 'View and Edit Organisation' functionality works correctly for an existing ICB organisation.
119+
Verifies that the 'Remove All Created Organisation' functionality works correctly
115120
"""
116121
OrganisationsPage(page).go_to_organisations_and_site_details_page()
122+
delete_organisations_created_for_test(["Z9Z1S"])
117123
OrganisationsAndSiteDetails(page).go_to_list_all_organisations()
124+
ListAllOrganisations(page).select_organisation_type_option(OrganisationType.CCG)
125+
ListAllOrganisations(page).search_organisation_code("Z9Z1X")
126+
ListAllOrganisations(page).verify_no_organisation_record_found(
127+
"Sorry, no records match your search criteria. Please refine your search and try again."
128+
)
129+
130+
131+
@pytest.mark.regression
132+
@pytest.mark.organisations_users_and_contacts_tests
133+
@pytest.mark.organisations_and_contacts_develop_level_tests
134+
@pytest.mark.wip
135+
def test_remove_all_created_sites(page) -> None:
136+
"""
137+
Verifies that the 'Remove All Created Sites' functionality works correctly
138+
"""
139+
OrganisationsPage(page).go_to_organisations_and_site_details_page()
140+
delete_sites_created_for_test(["Z9Z1X"])
141+
OrganisationsAndSiteDetails(page).go_to_list_all_sites()
142+
ListAllSites(page).select_site_type_option(SiteType.NHS_TRUST_SITE)
143+
ListAllSites(page).search_site_code("Z9Z1X")
144+
ListAllSites(page).verify_no_site_record_found(
145+
"Sorry, no records match your search criteria. Please refine your search and try again."
146+
)

utils/oracle/oracle_specific_functions.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,3 +707,87 @@ def get_investigation_dataset_polyp_algorithm_size(
707707
df = OracleDB().execute_query(query, bind_vars)
708708
polyp_algorithm_size = df["polyp_algorithm_size"].iloc[0] if not df.empty else None
709709
return polyp_algorithm_size
710+
711+
712+
def delete_organisation_relationships_created_for_test(org_codes: list[str]) -> None:
713+
"""
714+
Deletes organisation relationships for the given org codes.
715+
Must be run first due to foreign key constraints.
716+
"""
717+
placeholders = ", ".join([f":org{i}" for i in range(len(org_codes))])
718+
subquery = f"SELECT ORG_ID FROM ORG WHERE ORG_CODE IN ({placeholders})"
719+
720+
query = f"""
721+
DELETE FROM ORG_RELATIONSHIPS
722+
WHERE CHILD_ORG_ID IN ({subquery})
723+
OR PARENT_ORG_ID IN ({subquery})
724+
"""
725+
726+
params = {f"org{i}": code for i, code in enumerate(org_codes)}
727+
OracleDB().update_or_insert_data_to_table(query, params)
728+
729+
730+
def delete_people_in_org_created_for_test(org_codes: list[str]) -> None:
731+
"""
732+
Deletes people in organisations for the given org codes.
733+
Must be run before deleting organisations due to foreign key constraints.
734+
"""
735+
placeholders = ", ".join([f":org{i}" for i in range(len(org_codes))])
736+
subquery = f"SELECT ORG_ID FROM ORG WHERE ORG_CODE IN ({placeholders})"
737+
738+
query = f"""
739+
DELETE FROM PERSON_IN_ORG
740+
WHERE ORG_ID IN ({subquery})
741+
"""
742+
743+
params = {f"org{i}": code for i, code in enumerate(org_codes)}
744+
OracleDB().update_or_insert_data_to_table(query, params)
745+
746+
747+
def delete_orgs_created_for_test(org_codes: list[str]) -> None:
748+
"""
749+
Deletes organisations for the given org codes.
750+
Must be run last due to foreign key constraints.
751+
"""
752+
placeholders = ", ".join([f":org{i}" for i in range(len(org_codes))])
753+
query = f"""
754+
DELETE FROM ORG
755+
WHERE ORG_CODE IN ({placeholders})
756+
"""
757+
758+
params = {f"org{i}": code for i, code in enumerate(org_codes)}
759+
OracleDB().update_or_insert_data_to_table(query, params)
760+
761+
762+
def delete_organisations_created_for_test(org_codes: list[str]) -> None:
763+
"""
764+
Deletes test organisations and related data in correct dependency order.
765+
"""
766+
logging.info("Start: delete_organisations_created_for_test(%s)", org_codes)
767+
768+
delete_organisation_relationships_created_for_test(org_codes)
769+
delete_people_in_org_created_for_test(org_codes)
770+
delete_orgs_created_for_test(org_codes)
771+
772+
logging.info("End: delete_organisations_created_for_test(%s)", org_codes)
773+
774+
775+
def delete_sites_created_for_test(site_codes: list[str]) -> None:
776+
"""
777+
Deletes sites from the SITES table based on the given site codes.
778+
"""
779+
logging.info("Start: delete_sites_created_for_test(%s)", site_codes)
780+
781+
# Dynamically create placeholders like :site0, :site1, ...
782+
placeholders = ", ".join([f":site{i}" for i in range(len(site_codes))])
783+
query = f"""
784+
DELETE FROM SITES
785+
WHERE SITE_CODE IN ({placeholders})
786+
"""
787+
788+
# Bind each site code to its placeholder
789+
params = {f"site{i}": code for i, code in enumerate(site_codes)}
790+
791+
OracleDB().update_or_insert_data_to_table(query, params)
792+
793+
logging.info("End: delete_sites_created_for_test(%s)", site_codes)

0 commit comments

Comments
 (0)