Add learning mentor template test, don't allow invitations in courses without mentors
This commit is contained in:
parent
bc909ae1b6
commit
1e5db1f0f7
|
|
@ -401,9 +401,9 @@ def command(
|
||||||
|
|
||||||
if set_only_is_uk_flag:
|
if set_only_is_uk_flag:
|
||||||
course.configuration.is_vv = False
|
course.configuration.is_vv = False
|
||||||
course.configuration.enable_learning_mentors = True
|
course.configuration.enable_learning_mentor = True
|
||||||
else:
|
else:
|
||||||
course.configuration.is_vv = True
|
course.configuration.is_vv = True
|
||||||
course.configuration.enable_learning_mentors = False
|
course.configuration.enable_learning_mentor = False
|
||||||
|
|
||||||
course.configuration.save()
|
course.configuration.save()
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,21 @@ class LearningMentorInvitationTest(APITestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
@patch("vbv_lernwelt.learning_mentor.views.send_email")
|
@patch("vbv_lernwelt.learning_mentor.views.send_email")
|
||||||
def test_create_invitation(self, mock_send_mail) -> None:
|
def test_create_invitation_vv(self, mock_send_mail) -> None:
|
||||||
|
self._test_create_invitation(
|
||||||
|
EmailTemplate.LEARNING_MENTOR_INVITATION, mock_send_mail
|
||||||
|
)
|
||||||
|
|
||||||
|
@patch("vbv_lernwelt.learning_mentor.views.send_email")
|
||||||
|
def test_create_invitation_uk(self, mock_send_mail) -> None:
|
||||||
|
self.course_session.course.configuration.is_uk = True
|
||||||
|
self.course_session.course.configuration.is_vv = False
|
||||||
|
self.course_session.course.configuration.save()
|
||||||
|
self._test_create_invitation(
|
||||||
|
EmailTemplate.PRAXISBILDNER_INVITATION, mock_send_mail
|
||||||
|
)
|
||||||
|
|
||||||
|
def _test_create_invitation(self, email_template, mock_send_mail) -> None:
|
||||||
# GIVEN
|
# GIVEN
|
||||||
self.client.force_login(self.participant)
|
self.client.force_login(self.participant)
|
||||||
add_course_session_user(
|
add_course_session_user(
|
||||||
|
|
@ -92,7 +106,7 @@ class LearningMentorInvitationTest(APITestCase):
|
||||||
|
|
||||||
mock_send_mail.assert_called_once_with(
|
mock_send_mail.assert_called_once_with(
|
||||||
recipient_email=email,
|
recipient_email=email,
|
||||||
template=EmailTemplate.LEARNING_MENTOR_INVITATION,
|
template=email_template,
|
||||||
template_data={
|
template_data={
|
||||||
"inviter_name": f"{self.participant.first_name} {self.participant.last_name}",
|
"inviter_name": f"{self.participant.first_name} {self.participant.last_name}",
|
||||||
"inviter_email": self.participant.email,
|
"inviter_email": self.participant.email,
|
||||||
|
|
@ -102,6 +116,27 @@ class LearningMentorInvitationTest(APITestCase):
|
||||||
fail_silently=True,
|
fail_silently=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_cannot_create_invitation_if_learning_mentor_disabled(self) -> None:
|
||||||
|
# GIVEN
|
||||||
|
self.course_session.course.configuration.enable_learning_mentor = False
|
||||||
|
self.course_session.course.configuration.save()
|
||||||
|
|
||||||
|
self.client.force_login(self.participant)
|
||||||
|
add_course_session_user(
|
||||||
|
self.course_session,
|
||||||
|
self.participant,
|
||||||
|
role=CourseSessionUser.Role.MEMBER,
|
||||||
|
)
|
||||||
|
invite_url = reverse(
|
||||||
|
"create_invitation", kwargs={"course_session_id": self.course_session.id}
|
||||||
|
)
|
||||||
|
email = "test@example.com"
|
||||||
|
# WHEN
|
||||||
|
response = self.client.post(invite_url, data={"email": email})
|
||||||
|
|
||||||
|
# THEN
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
|
||||||
|
|
||||||
def test_list_invitations(self) -> None:
|
def test_list_invitations(self) -> None:
|
||||||
# GIVEN
|
# GIVEN
|
||||||
self.client.force_login(self.participant)
|
self.client.force_login(self.participant)
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,11 @@ def delete_invitation(request, course_session_id: int, invitation_id: UUID):
|
||||||
def create_invitation(request, course_session_id: int):
|
def create_invitation(request, course_session_id: int):
|
||||||
user = request.user
|
user = request.user
|
||||||
|
|
||||||
course_session = get_object_or_404(CourseSession, id=course_session_id)
|
course_session = get_object_or_404(
|
||||||
|
CourseSession,
|
||||||
|
id=course_session_id,
|
||||||
|
course__configuration__enable_learning_mentor=True,
|
||||||
|
)
|
||||||
course_session_user = get_object_or_404(
|
course_session_user = get_object_or_404(
|
||||||
CourseSessionUser, user=user, course_session=course_session
|
CourseSessionUser, user=user, course_session=course_session
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue