Skip to content

Commit 1613814

Browse files
authored
Merge pull request #602 from NHSDigital/add-delegation-tests
Add a basic test for delegation
2 parents 0db97fe + f88da7b commit 1613814

File tree

14 files changed

+296
-68
lines changed

14 files changed

+296
-68
lines changed

.env.generic

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ BASIC_AUTH_TOKEN=
1111
SET_FEATURE_FLAGS=false
1212
ADDITIONAL_FEATURE_FLAGS=
1313

14+
SCREENSHOT_ALL_STEPS=false
15+
1416
IMMS_API_PEM=
1517
IMMS_API_KEY=
1618
IMMS_API_KID=

.github/actions/run-functional-tests/action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ inputs:
77
required: true
88
programmes_enabled:
99
required: true
10+
screenshot_all_steps:
11+
required: true
1012
set_feature_flags:
1113
default: "false"
1214
additional_feature_flags:
@@ -36,6 +38,7 @@ runs:
3638
env:
3739
BASE_URL: ${{ inputs.base_url }}
3840
PROGRAMMES_ENABLED: ${{ inputs.programmes_enabled }}
41+
SCREENSHOT_ALL_STEPS: ${{ inputs.screenshot_all_steps }}
3942
SET_FEATURE_FLAGS: ${{ inputs.set_feature_flags }}
4043
ADDITIONAL_FEATURE_FLAGS: ${{ inputs.additional_feature_flags }}
4144
BASIC_AUTH_TOKEN: ${{ env.BASIC_AUTH_TOKEN }}

.github/workflows/functional_selected_device.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ on:
3131
- training
3232
- sandbox-alpha
3333
- sandbox-beta
34+
screenshot_all_steps:
35+
description: 'Take screenshots for all steps (in addition to failures)'
36+
required: true
37+
default: 'false'
38+
type: choice
39+
options:
40+
- true
41+
- false
3442
set_feature_flags:
3543
description: 'Set feature flags in the flipper page before running tests (affects all users of the environment being tested!)'
3644
required: true
@@ -73,6 +81,7 @@ jobs:
7381
echo "set_feature_flags=false" >> $GITHUB_OUTPUT
7482
echo "additional_feature_flags=" >> $GITHUB_OUTPUT
7583
echo "deploy_report=false" >> $GITHUB_OUTPUT
84+
echo "screenshot_all_steps=false" >> $GITHUB_OUTPUT
7685
else
7786
echo "device=${{ github.event.inputs.device }}" >> $GITHUB_OUTPUT
7887
@@ -84,6 +93,7 @@ jobs:
8493
echo "set_feature_flags=${{ github.event.inputs.set_feature_flags }}" >> $GITHUB_OUTPUT
8594
echo "additional_feature_flags=${{ github.event.inputs.additional_feature_flags }}" >> $GITHUB_OUTPUT
8695
echo "deploy_report=true" >> $GITHUB_OUTPUT
96+
echo "screenshot_all_steps=${{ github.event.inputs.screenshot_all_steps }}" >> $GITHUB_OUTPUT
8797
fi
8898
8999
- uses: actions/checkout@v5
@@ -101,6 +111,7 @@ jobs:
101111
device: ${{ steps.set-variables.outputs.device }}
102112
base_url: ${{ steps.set-variables.outputs.environment }}
103113
programmes_enabled: ${{ steps.set-variables.outputs.programmes }}
114+
screenshot_all_steps: ${{ steps.set-variables.outputs.screenshot_all_steps }}
104115
set_feature_flags: ${{ steps.set-variables.outputs.set_feature_flags }}
105116
additional_feature_flags: ${{ steps.set-variables.outputs.additional_feature_flags }}
106117
playwright_cache_hit: ${{ steps.playwright-cache.outputs.cache-hit }}

mavis/test/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,20 @@
2020
edit_batch_page,
2121
flipper_page,
2222
get_online_consent_url,
23+
healthcare_assistant,
2324
imms_base_url,
2425
import_records_page,
2526
log_in_as_medical_secretary,
2627
log_in_as_nurse,
28+
log_in_as_prescriber,
2729
log_in_page,
2830
match_consent_response_page,
2931
medical_secretary,
3032
nurse,
3133
onboarding,
3234
online_consent_page,
3335
organisation,
36+
prescriber,
3437
programmes_enabled,
3538
programmes_page,
3639
reset_before_each_module,
@@ -73,17 +76,20 @@
7376
"edit_batch_page",
7477
"flipper_page",
7578
"get_online_consent_url",
79+
"healthcare_assistant",
7680
"imms_base_url",
7781
"import_records_page",
7882
"log_in_as_medical_secretary",
7983
"log_in_as_nurse",
84+
"log_in_as_prescriber",
8085
"log_in_page",
8186
"match_consent_response_page",
8287
"medical_secretary",
8388
"nurse",
8489
"onboarding",
8590
"online_consent_page",
8691
"organisation",
92+
"prescriber",
8793
"programmes_enabled",
8894
"programmes_page",
8995
"pytest_runtest_logreport",

mavis/test/annotations.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@ def _reduce_colors(image_bytes: bytes) -> bytes:
1616
return output_io.getvalue()
1717

1818

19-
def step(title: str, *, attach_screenshot: bool = True):
19+
def _add_screenshot(page, name: str) -> None:
20+
screenshot_bytes = page.screenshot(full_page=True, scale="css")
21+
reduced_bytes = _reduce_colors(screenshot_bytes)
22+
allure.attach(
23+
reduced_bytes,
24+
name=name,
25+
attachment_type=allure.attachment_type.PNG,
26+
)
27+
28+
29+
def step(title: str):
2030
def decorator(func):
2131
@wraps(func)
2232
def wrapper(self, *args, **kwargs):
2333
with allure.step(title):
2434
try:
2535
return_value = func(self, *args, **kwargs)
2636
except Exception:
27-
if attach_screenshot:
28-
screenshot_bytes = self.page.screenshot(
29-
full_page=True,
30-
scale="css",
31-
)
32-
reduced_bytes = _reduce_colors(screenshot_bytes)
33-
allure.attach(
34-
reduced_bytes,
35-
name="Screenshot on failure",
36-
attachment_type=allure.attachment_type.PNG,
37-
)
37+
_add_screenshot(self.page, name="Screenshot on failure")
3838
raise
3939

4040
coverage = kwargs.get("coverage")
@@ -45,14 +45,8 @@ def wrapper(self, *args, **kwargs):
4545
attachment_type=allure.attachment_type.TEXT,
4646
)
4747

48-
if attach_screenshot:
49-
screenshot_bytes = self.page.screenshot(full_page=True, scale="css")
50-
reduced_bytes = _reduce_colors(screenshot_bytes)
51-
allure.attach(
52-
reduced_bytes,
53-
name="Screenshot",
54-
attachment_type=allure.attachment_type.PNG,
55-
)
48+
if os.getenv("SCREENSHOT_ALL_STEPS", "false").lower() == "true":
49+
_add_screenshot(self.page, name="Screenshot")
5650

5751
return return_value
5852

mavis/test/data/pds.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import csv
2+
import random
23
from datetime import date, datetime
34
from pathlib import Path
45
from typing import NamedTuple
56
from zoneinfo import ZoneInfo
67

78
from dateutil.relativedelta import relativedelta
89

10+
from mavis.test.models import Child, Parent, Relationship
911
from mavis.test.utils import get_todays_date
1012

1113

@@ -65,14 +67,28 @@ def address(self) -> tuple[str, str, str, str]:
6567
reader = csv.DictReader(file)
6668
patients = [Patient.from_csv_row(row) for row in reader]
6769

68-
patients_without_date_of_death = [
69-
patient for patient in patients if not patient.date_of_death
70-
]
7170

72-
cutoff_date = get_todays_date() - relativedelta(years=22)
71+
def get_random_child_patient_without_date_of_death() -> Child:
72+
patients_without_date_of_death = [
73+
patient for patient in patients if not patient.date_of_death
74+
]
7375

74-
child_patients_without_date_of_death = [
75-
patient
76-
for patient in patients_without_date_of_death
77-
if patient.date_of_birth >= cutoff_date
78-
]
76+
cutoff_date = get_todays_date() - relativedelta(years=22)
77+
78+
child_patients_without_date_of_death = [
79+
patient
80+
for patient in patients_without_date_of_death
81+
if patient.date_of_birth >= cutoff_date
82+
]
83+
84+
child = random.choice(child_patients_without_date_of_death)
85+
86+
return Child(
87+
child.given_name,
88+
child.family_name,
89+
child.nhs_number,
90+
child.address,
91+
child.date_of_birth,
92+
9,
93+
(Parent.get(Relationship.DAD), Parent.get(Relationship.MUM)),
94+
)

mavis/test/fixtures/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
get_online_consent_url,
44
log_in_as_medical_secretary,
55
log_in_as_nurse,
6+
log_in_as_prescriber,
67
set_feature_flags,
78
test_data,
89
)
@@ -11,11 +12,13 @@
1112
children,
1213
clinics,
1314
delete_team_after_tests,
15+
healthcare_assistant,
1416
imms_base_url,
1517
medical_secretary,
1618
nurse,
1719
onboarding,
1820
organisation,
21+
prescriber,
1922
programmes_enabled,
2023
reset_before_each_module,
2124
schools,
@@ -78,17 +81,20 @@
7881
"edit_batch_page",
7982
"flipper_page",
8083
"get_online_consent_url",
84+
"healthcare_assistant",
8185
"imms_base_url",
8286
"import_records_page",
8387
"log_in_as_medical_secretary",
8488
"log_in_as_nurse",
89+
"log_in_as_prescriber",
8590
"log_in_page",
8691
"match_consent_response_page",
8792
"medical_secretary",
8893
"nurse",
8994
"onboarding",
9095
"online_consent_page",
9196
"organisation",
97+
"prescriber",
9298
"programmes_enabled",
9399
"programmes_page",
94100
"reset_before_each_module",

mavis/test/fixtures/helpers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ def log_in_as_nurse(set_feature_flags, nurse, team, log_in_page):
8585
log_in_page.log_out()
8686

8787

88+
@pytest.fixture
89+
def log_in_as_prescriber(set_feature_flags, prescriber, team, log_in_page):
90+
log_in_page.navigate()
91+
log_in_page.log_in_and_choose_team_if_necessary(prescriber, team)
92+
yield
93+
log_in_page.log_out()
94+
95+
8896
@pytest.fixture
8997
def test_data(organisation, schools, nurse, children, clinics, year_groups):
9098
return TestData(organisation, schools, nurse, children, clinics, year_groups)

mavis/test/fixtures/models.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,21 @@ def reset_before_each_module(base_url, team) -> None:
104104
_check_response_status(response)
105105

106106

107+
@pytest.fixture(scope="session")
108+
def healthcare_assistant(onboarding) -> User:
109+
return onboarding.users["healthcare_assistant"]
110+
111+
107112
@pytest.fixture(scope="session")
108113
def medical_secretary(onboarding) -> User:
109114
return onboarding.users["medical_secretary"]
110115

111116

117+
@pytest.fixture(scope="session")
118+
def prescriber(onboarding) -> User:
119+
return onboarding.users["prescriber"]
120+
121+
112122
@pytest.fixture(scope="session")
113123
def clinics(onboarding) -> list[Clinic]:
114124
return onboarding.clinics

mavis/test/models.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,13 @@ def get_onboarding_data_for_tests(
554554
team = Team.generate(subteam, organisation)
555555
users = {
556556
role: User.generate(role)
557-
for role in ("nurse", "medical_secretary", "superuser")
557+
for role in (
558+
"nurse",
559+
"medical_secretary",
560+
"superuser",
561+
"prescriber",
562+
"healthcare_assistant",
563+
)
558564
}
559565
clinics = [Clinic.generate()]
560566
schools = School.get_from_testing_api(base_url, year_groups)

0 commit comments

Comments
 (0)