Skip to content

Commit ddd671f

Browse files
PR Review Fixes
1 parent 4bc62e2 commit ddd671f

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

manage_breast_screening/auth/tests/factories.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from django.contrib.auth import get_user_model
2+
from factory import Trait
23
from factory.declarations import Sequence
34
from factory.django import DjangoModelFactory
45

6+
from manage_breast_screening.auth.models import Role
7+
58

69
class UserFactory(DjangoModelFactory):
710
class Meta:
@@ -12,3 +15,7 @@ class Meta:
1215
nhs_uid = Sequence(lambda n: "alice%d" % n)
1316
first_name = Sequence(lambda n: "Alice%d" % n)
1417
last_name = "Lastname"
18+
19+
class Params:
20+
clinical = Trait(roles=[Role.CLINICAL])
21+
administrative = Trait(roles=[Role.ADMINISTRATIVE])

manage_breast_screening/tests/system/clinical/test_clinic_show_page.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ def then_i_can_see_the_special_appointment_banner(self):
265265

266266
def and_there_are_appointments_in_various_states_with_attributed_users(self):
267267
# Create users for attribution
268-
user_in_progress = UserFactory(first_name="Alice", last_name="User")
269268
user_screened = UserFactory(first_name="Bob", last_name="User")
270269
user_cancelled = UserFactory(first_name="Charlie", last_name="User")
271270

@@ -285,7 +284,7 @@ def and_there_are_appointments_in_various_states_with_attributed_users(self):
285284
)
286285
self.in_progress_appointment.statuses.create(
287286
state=AppointmentStatus.IN_PROGRESS,
288-
created_by=user_in_progress,
287+
created_by=self.user_in_progress,
289288
)
290289

291290
# SCREENED status
@@ -319,7 +318,7 @@ def then_i_can_see_status_attribution_for_relevant_appointments(self):
319318
in_progress_row = self.page.locator("tr").filter(
320319
has_text="Participant InProgress"
321320
)
322-
expect(in_progress_row).to_contain_text("with A. User (you)")
321+
expect(in_progress_row).to_contain_text("with A. InProgress (you)")
323322

324323
screened_row = self.page.locator("tr").filter(has_text="Participant Screened")
325324
expect(screened_row).to_contain_text("by B. User")
@@ -329,8 +328,10 @@ def then_i_can_see_status_attribution_for_relevant_appointments(self):
329328

330329
def given_i_am_logged_in_as_a_user_with_appointment_in_progress(self):
331330
# Create and log in the user who will be attributed with the IN_PROGRESS status
332-
user_in_progress = UserFactory(first_name="Alice", last_name="User")
333-
self.login_as_role(Role.CLINICAL, user_in_progress)
331+
self.user_in_progress = self.create_user_with_role(
332+
first_name="Alice", last_name="InProgress", role=Role.CLINICAL
333+
)
334+
self.login_as_user(self.user_in_progress)
334335

335336
def then_i_can_see_you_in_status_attribution(self):
336337
# Check that the "(you)" indicator is present for the in-progress attribution

manage_breast_screening/tests/system/system_test_setup.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ def login_as_user(self, user: User):
4646
Emulate logging in as a particular user, without needing
4747
to visit a login page.
4848
"""
49+
50+
self.current_user = user
51+
4952
# Fake a login
5053
client = Client()
5154
client.force_login(user)
@@ -69,20 +72,25 @@ def login_as_user(self, user: User):
6972
]
7073
)
7174

72-
def login_as_role(self, role: Role, user: User | None = None):
75+
def login_as_role(self, role: Role):
7376
"""
7477
Emulate logging in as a user having a particular role,
7578
without needing to visit a login page.
7679
"""
77-
if not user:
78-
user = UserFactory.create()
80+
user = UserFactory.create()
7981

8082
UserAssignmentFactory.create(user=user, roles=[role.value])
8183

82-
self.current_user = user
8384
self.current_provider = user.assignments.first().provider
8485
self.login_as_user(user)
8586

87+
def create_user_with_role(
88+
self, first_name: str, last_name: str, role: Role
89+
) -> User:
90+
user = UserFactory.create(first_name=first_name, last_name=last_name)
91+
UserAssignmentFactory.create(user=user, roles=[role.value])
92+
return user
93+
8694
def expect_validation_error(
8795
self,
8896
error_text: str,

0 commit comments

Comments
 (0)