Skip to content

Commit fb64621

Browse files
Addressing PR comments
1 parent 761e84f commit fb64621

File tree

2 files changed

+72
-58
lines changed

2 files changed

+72
-58
lines changed

tests/regression/subject/demographic/test_temporary_address.py

Lines changed: 38 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,42 @@
1212
search_subject_demographics_by_nhs_number,
1313
)
1414
from utils.oracle.oracle import OracleDB
15+
from utils.oracle.oracle_specific_functions import (
16+
check_if_subject_has_temporary_address,
17+
)
1518
from utils.oracle.subject_selection_query_builder import SubjectSelectionQueryBuilder
1619
import logging
1720
from faker import Faker
1821
from datetime import datetime, timedelta
1922

2023

24+
@pytest.fixture(scope="function", autouse=True)
25+
def before_each(page: Page) -> str:
26+
"""
27+
Before every test is executed, this fixture:
28+
- Logs into BCSS as a Screening Centre Manager at BCS001
29+
- Navigates to the screening subject search page
30+
"""
31+
nhs_no = obtain_test_data_nhs_no()
32+
logging.info(f"Selected NHS Number: {nhs_no}")
33+
UserTools.user_login(page, "Screening Centre Manager at BCS001")
34+
BasePage(page).go_to_screening_subject_search_page()
35+
search_subject_demographics_by_nhs_number(page, nhs_no)
36+
return nhs_no
37+
38+
39+
@pytest.mark.wip
2140
@pytest.mark.regression
2241
@pytest.mark.subject_tests
23-
def test_not_amending_temporary_address(page: Page) -> None:
42+
def test_not_amending_temporary_address(page: Page, before_each) -> None:
2443
"""
2544
Scenario: If not amending a temporary address, no need to validate it
2645
2746
This test is checking that if a temporary address is not being amended,
2847
and the subject's postcode is updated.
2948
That the subject does not have a temporary address added to them.
3049
"""
31-
nhs_no = obtain_test_data_nhs_no()
32-
logging.info(f"Selected NHS Number: {nhs_no}")
33-
34-
UserTools.user_login(page, "Screening Centre Manager at BCS001")
35-
BasePage(page).go_to_screening_subject_search_page()
36-
search_subject_demographics_by_nhs_number(page, nhs_no)
37-
50+
nhs_no = before_each
3851
fake = Faker("en_GB")
3952
random_postcode = fake.postcode()
4053
SubjectDemographicPage(page).fill_postcode_input(random_postcode)
@@ -45,21 +58,17 @@ def test_not_amending_temporary_address(page: Page) -> None:
4558
LogoutPage(page).log_out()
4659

4760

61+
@pytest.mark.wip
4862
@pytest.mark.regression
4963
@pytest.mark.subject_tests
50-
def test_add_temporary_address_then_delete(page: Page) -> None:
64+
def test_add_temporary_address_then_delete(page: Page, before_each) -> None:
5165
"""
5266
Add a temporary address, then delete it.
5367
5468
This test is checking that a temporary address can be added to a subject,
5569
and then deleted successfully, ensuring the temporary address icon behaves as expected.
5670
"""
57-
nhs_no = obtain_test_data_nhs_no()
58-
logging.info(f"Selected NHS Number: {nhs_no}")
59-
60-
UserTools.user_login(page, "Screening Centre Manager at BCS001")
61-
BasePage(page).go_to_screening_subject_search_page()
62-
search_subject_demographics_by_nhs_number(page, nhs_no)
71+
nhs_no = before_each
6372

6473
temp_address = {
6574
"valid_from": datetime.today(),
@@ -90,6 +99,7 @@ def test_add_temporary_address_then_delete(page: Page) -> None:
9099
LogoutPage(page).log_out()
91100

92101

102+
@pytest.mark.wip
93103
@pytest.mark.regression
94104
@pytest.mark.subject_tests
95105
def test_validation_regarding_dates(page: Page) -> None:
@@ -100,12 +110,6 @@ def test_validation_regarding_dates(page: Page) -> None:
100110
works correctly when the user tries to enter a temporary address with invalid dates.
101111
It ensures that the user is prompted with appropriate error messages when the dates are not valid.
102112
"""
103-
nhs_no = obtain_test_data_nhs_no()
104-
logging.info(f"Selected NHS Number: {nhs_no}")
105-
106-
UserTools.user_login(page, "Screening Centre Manager at BCS001")
107-
BasePage(page).go_to_screening_subject_search_page()
108-
search_subject_demographics_by_nhs_number(page, nhs_no)
109113

110114
temp_address = {
111115
"valid_from": None,
@@ -167,22 +171,18 @@ def test_validation_regarding_dates(page: Page) -> None:
167171
LogoutPage(page).log_out()
168172

169173

174+
@pytest.mark.wip
170175
@pytest.mark.regression
171176
@pytest.mark.subject_tests
172-
def test_ammending_temporary_address(page: Page) -> None:
177+
def test_ammending_temporary_address(page: Page, before_each) -> None:
173178
"""
174179
Scenario: If amending a temporary address, it should be validated.
175180
176181
This test checks that if a temporary address is being amended,
177182
and the subject's postcode is updated.
178183
That the subject has a temporary address added to them.
179184
"""
180-
nhs_no = obtain_test_data_nhs_no()
181-
logging.info(f"Selected NHS Number: {nhs_no}")
182-
183-
UserTools.user_login(page, "Screening Centre Manager at BCS001")
184-
BasePage(page).go_to_screening_subject_search_page()
185-
search_subject_demographics_by_nhs_number(page, nhs_no)
185+
nhs_no = before_each
186186

187187
temp_address = {
188188
"valid_from": datetime(2000, 1, 1),
@@ -226,15 +226,17 @@ def test_ammending_temporary_address(page: Page) -> None:
226226
LogoutPage(page).log_out()
227227

228228

229+
@pytest.mark.wip
229230
@pytest.mark.regression
230231
@pytest.mark.subject_tests
231-
def test_validating_minimum_information(page: Page) -> None:
232-
nhs_no = obtain_test_data_nhs_no()
233-
logging.info(f"Selected NHS Number: {nhs_no}")
234-
235-
UserTools.user_login(page, "Screening Centre Manager at BCS001")
236-
BasePage(page).go_to_screening_subject_search_page()
237-
search_subject_demographics_by_nhs_number(page, nhs_no)
232+
def test_validating_minimum_information(page: Page, before_each) -> None:
233+
"""
234+
Scenario: Validation regarding minimum information
235+
This test checks that the validation for the temporary address fields
236+
works correctly when the user tries to enter a temporary address with minimum information.
237+
It ensures that the user is prompted with appropriate error messages when the minimum information is not provided
238+
"""
239+
nhs_no = before_each
238240

239241
temp_address = {
240242
"valid_from": datetime.today(),
@@ -322,32 +324,10 @@ def check_subject_has_temporary_address(nhs_no: str, temporary_address: bool) ->
322324
AssertionError: If the expected address status does not match the actual status in the database.
323325
This function queries the database to determine if the subject has a temporary address
324326
and asserts the result against the expected value.
325-
It uses the OracleDB class to execute the query and retrieve the address status.
326-
The query checks for the existence of a temporary address by looking for a record
327-
in the screening_subject_t, sd_contact_t, and sd_address_t tables where the address
328-
type is 13043 (temporary address) and the effective_from date is not null.
329327
The result is then compared to the expected status, and an assertion is raised if they do not match.
330328
"""
331329

332-
query = """
333-
SELECT
334-
CASE
335-
WHEN EXISTS (
336-
SELECT 1
337-
FROM screening_subject_t ss
338-
INNER JOIN sd_contact_t c ON c.nhs_number = ss.subject_nhs_number
339-
INNER JOIN sd_address_t a ON a.contact_id = c.contact_id
340-
WHERE ss.subject_nhs_number = :nhs_no
341-
AND a.address_type = 13043
342-
AND a.effective_from IS NOT NULL
343-
)
344-
THEN 'Subject has a temporary address'
345-
ELSE 'Subject doesn''t have a temporary address'
346-
END AS address_status
347-
FROM DUAL
348-
"""
349-
bind_vars = {"nhs_no": nhs_no}
350-
df = OracleDB().execute_query(query, bind_vars)
330+
df = check_if_subject_has_temporary_address(nhs_no)
351331

352332
if temporary_address:
353333
logging.info(

utils/oracle/oracle_specific_functions.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,3 +422,37 @@ def get_subjects_for_investigation_dataset_updates(
422422
subjects_df = OracleDB().execute_query(query, params)
423423

424424
return subjects_df
425+
426+
427+
def check_if_subject_has_temporary_address(nhs_no: str) -> pd.DataFrame:
428+
"""
429+
Checks if the subject has a temporary address in the database.
430+
Args:
431+
nhs_no (str): The NHS number of the subject.
432+
This function queries the database to determine if the subject has a temporary address
433+
and asserts the result against the expected value.
434+
The query checks for the existence of a temporary address by looking for a record
435+
in the screening_subject_t, sd_contact_t, and sd_address_t tables where the address
436+
type is 13043 (temporary address) and the effective_from date is not null.
437+
"""
438+
439+
query = """
440+
SELECT
441+
CASE
442+
WHEN EXISTS (
443+
SELECT 1
444+
FROM screening_subject_t ss
445+
INNER JOIN sd_contact_t c ON c.nhs_number = ss.subject_nhs_number
446+
INNER JOIN sd_address_t a ON a.contact_id = c.contact_id
447+
WHERE ss.subject_nhs_number = :nhs_no
448+
AND a.address_type = 13043
449+
AND a.effective_from IS NOT NULL
450+
)
451+
THEN 'Subject has a temporary address'
452+
ELSE 'Subject doesn''t have a temporary address'
453+
END AS address_status
454+
FROM DUAL
455+
"""
456+
bind_vars = {"nhs_no": nhs_no}
457+
df = OracleDB().execute_query(query, bind_vars)
458+
return df

0 commit comments

Comments
 (0)