From ccbeb9725fd3262ea8caa2b120fde11fb57c4459 Mon Sep 17 00:00:00 2001 From: Christian Cueni Date: Mon, 29 Jan 2024 13:14:49 +0100 Subject: [PATCH] Use different verbs for different types of assignments --- server/vbv_lernwelt/notify/services.py | 42 ++++- ...ers.py => test_assigment_notifications.py} | 171 +++++++++++++++++- 2 files changed, 202 insertions(+), 11 deletions(-) rename server/vbv_lernwelt/notify/tests/{test_assigment_reminders.py => test_assigment_notifications.py} (61%) diff --git a/server/vbv_lernwelt/notify/services.py b/server/vbv_lernwelt/notify/services.py index 84102609..aadde5aa 100644 --- a/server/vbv_lernwelt/notify/services.py +++ b/server/vbv_lernwelt/notify/services.py @@ -40,11 +40,22 @@ class NotificationService: def send_assignment_submitted_notification( cls, recipient: User, sender: User, assignment_completion: AssignmentCompletion ): - texts = { - "de": "%(sender)s hat die geleitete Fallarbeit «%(assignment_title)s» abgegeben.", - "fr": "%(sender)s a soumis l'étude de cas dirigée «%(assignment_title)s».", - "it": "%(sender)s ha consegnato il caso di studio guidato «%(assignment_title)s».", - } + if ( + assignment_completion.assignment.assignment_type + == AssignmentType.PRAXIS_ASSIGNMENT.value + ): + texts = { + "de": "%(sender)s hat den Praxisauftrag «%(assignment_title)s» abgegeben.", + "fr": "%(sender)s a soumis la mission pratique «%(assignment_title)s».", + "it": "%(sender)s ha consegnato l'incarico pratico «%(assignment_title)s».", + } + # this was the default case before the praxis assignment was introduced + else: + texts = { + "de": "%(sender)s hat die geleitete Fallarbeit «%(assignment_title)s» abgegeben.", + "fr": "%(sender)s a soumis l'étude de cas dirigée «%(assignment_title)s».", + "it": "%(sender)s ha consegnato il caso di studio guidato «%(assignment_title)s».", + } verb = texts.get(recipient.language, "de") % { "sender": sender.get_full_name(), "assignment_title": assignment_completion.assignment.title, @@ -70,11 +81,22 @@ class NotificationService: assignment_completion: AssignmentCompletion, target_url: str, ): - texts = { - "de": "%(sender)s hat die geleitete Fallarbeit «%(assignment_title)s» bewertet.", - "fr": "%(sender)s a évalué l'étude de cas dirigée «%(assignment_title)s».", - "it": "%(sender)s ha valutato il caso di studio guidato «%(assignment_title)s».", - } + if ( + assignment_completion.assignment.assignment_type + == AssignmentType.PRAXIS_ASSIGNMENT.value + ): + texts = { + "de": "%(sender)s hat den Praxisauftrag «%(assignment_title)s» bewertet.", + "fr": "%(sender)s a évalué la mission pratique «%(assignment_title)s».", + "it": "%(sender)s ha valutato l'incarico pratico «%(assignment_title)s».", + } + # this was the default case before the praxis assignment was introduced + else: + texts = { + "de": "%(sender)s hat die geleitete Fallarbeit «%(assignment_title)s» bewertet.", + "fr": "%(sender)s a évalué l'étude de cas dirigée «%(assignment_title)s».", + "it": "%(sender)s ha valutato il caso di studio guidato «%(assignment_title)s».", + } verb = texts.get(recipient.language, "de") % { "sender": sender.get_full_name(), "assignment_title": assignment_completion.assignment.title, diff --git a/server/vbv_lernwelt/notify/tests/test_assigment_reminders.py b/server/vbv_lernwelt/notify/tests/test_assigment_notifications.py similarity index 61% rename from server/vbv_lernwelt/notify/tests/test_assigment_reminders.py rename to server/vbv_lernwelt/notify/tests/test_assigment_notifications.py index 7c912559..d83fb977 100644 --- a/server/vbv_lernwelt/notify/tests/test_assigment_reminders.py +++ b/server/vbv_lernwelt/notify/tests/test_assigment_notifications.py @@ -6,7 +6,13 @@ from django.test import TestCase from django.utils import timezone from freezegun import freeze_time -from vbv_lernwelt.assignment.models import AssignmentType +from vbv_lernwelt.assignment.models import ( + Assignment, + AssignmentCompletion, + AssignmentCompletionStatus, + AssignmentType, +) +from vbv_lernwelt.core.admin import User from vbv_lernwelt.core.constants import TEST_COURSE_SESSION_BERN_ID from vbv_lernwelt.core.create_default_users import create_default_users from vbv_lernwelt.course.creators.test_course import create_test_course @@ -24,6 +30,7 @@ from vbv_lernwelt.notify.email.reminders.assigment import ( send_assignment_reminder_notifications, ) from vbv_lernwelt.notify.models import Notification +from vbv_lernwelt.notify.services import NotificationService EXPECTED_MEMBER_VERB = "Erinnerung: Bald ist ein Abgabetermin" EXPECTED_EXPERT_VERB = "Erinnerung: Bald ist ein Bewertungstermin" @@ -40,6 +47,7 @@ ASSIGNMENT_TYPE_LEARNING_CONTENT_LOOKUP: Dict[AssignmentType, str] = { AssignmentType.PREP_ASSIGNMENT: "test-lehrgang-lp-circle-fahrzeug-lc-fahrzeug-mein-erstes-auto", AssignmentType.REFLECTION: "test-lehrgang-lp-circle-fahrzeug-lc-reflexion", AssignmentType.CASEWORK: "test-lehrgang-lp-circle-fahrzeug-lc-überprüfen-einer-motorfahrzeug-versicherungspolice", + AssignmentType.PRAXIS_ASSIGNMENT: "test-lehrgang-lp-circle-reisen-lc-mein-kundenstamm", } @@ -284,3 +292,164 @@ class TestAssignmentCourseRemindersTest(TestCase): with self.assertRaises(Notification.DoesNotExist): Notification.objects.get(recipient__username=RECIPIENT_TRAINER) + + +class TestAssignmentCourseUpdateTest(TestCase): + def setUp(self): + create_default_users() + create_test_course(with_sessions=True) + + CourseSessionAssignment.objects.all().delete() + Notification.objects.all().delete() + + self.student = User.objects.get(email=RECIPIENT_STUDENTS[0]) + self.trainer = User.objects.get(email=RECIPIENT_TRAINER) + + @freeze_time("2023-01-01") + def test_notification_title_casework_for_experts(self): + # GIVEN + casework = create_assignment( + assignment_type=AssignmentType.CASEWORK, + submission_deadline=timezone.make_aware(datetime(2022, 12, 12)), + evaluation_deadline=timezone.make_aware(datetime(2023, 1, 2)), + ) + assignment = Assignment.objects.get( + slug="test-lehrgang-assignment-überprüfen-einer-motorfahrzeugs-versicherungspolice" + ) + + ac = AssignmentCompletion.objects.create( + completion_status=AssignmentCompletionStatus.SUBMITTED.value, + assignment_user=self.student, + assignment=assignment, + evaluation_passed=True, + course_session=casework.course_session, + completion_data={}, + evaluation_max_points=10, + evaluation_points=10, + evaluation_user=self.trainer, + ) + + # WHEN + NotificationService.send_assignment_submitted_notification( + recipient=self.trainer, + sender=ac.assignment_user, + assignment_completion=ac, + ) + + # THEN + self.assertEqual(1, len(Notification.objects.all())) + + notification = Notification.objects.get(recipient__username=RECIPIENT_TRAINER) + self.assertEqual("USER_INTERACTION", notification.notification_category) + self.assertIn("hat die geleitete Fallarbeit", notification.verb) + + def test_notification_title_praxis_assignment_for_experts(self): + # GIVEN. + casework = create_assignment( + assignment_type=AssignmentType.PRAXIS_ASSIGNMENT, + ) + assignment = Assignment.objects.get( + slug="test-lehrgang-assignment-mein-kundenstamm" + ) + + ac = AssignmentCompletion.objects.create( + completion_status=AssignmentCompletionStatus.SUBMITTED.value, + assignment_user=self.student, + assignment=assignment, + evaluation_passed=True, + course_session=casework.course_session, + completion_data={}, + evaluation_max_points=10, + evaluation_points=10, + evaluation_user=self.trainer, + ) + + # WHEN + NotificationService.send_assignment_submitted_notification( + recipient=self.trainer, + sender=ac.assignment_user, + assignment_completion=ac, + ) + + # THEN + self.assertEqual(1, len(Notification.objects.all())) + + notification = Notification.objects.get(recipient__username=RECIPIENT_TRAINER) + self.assertEqual("USER_INTERACTION", notification.notification_category) + self.assertIn("hat den Praxisauftrag", notification.verb) + + @freeze_time("2023-01-01") + def test_notification_title_casework_for_student(self): + # GIVEN + casework = create_assignment( + assignment_type=AssignmentType.CASEWORK, + submission_deadline=timezone.make_aware(datetime(2022, 12, 12)), + evaluation_deadline=timezone.make_aware(datetime(2023, 1, 2)), + ) + assignment = Assignment.objects.get( + slug="test-lehrgang-assignment-überprüfen-einer-motorfahrzeugs-versicherungspolice" + ) + + ac = AssignmentCompletion.objects.create( + completion_status=AssignmentCompletionStatus.EVALUATION_SUBMITTED.value, + assignment_user=self.student, + assignment=assignment, + evaluation_passed=True, + course_session=casework.course_session, + completion_data={}, + evaluation_max_points=10, + evaluation_points=10, + evaluation_user=self.trainer, + ) + + # WHEN + NotificationService.send_assignment_evaluated_notification( + recipient=ac.assignment_user, + sender=self.trainer, + assignment_completion=ac, + target_url="/some/url", + ) + + # THEN + self.assertEqual(1, len(Notification.objects.all())) + + notification = Notification.objects.get(recipient__username=self.student.email) + self.assertEqual("USER_INTERACTION", notification.notification_category) + self.assertIn("hat die geleitete Fallarbeit", notification.verb) + + @freeze_time("2023-01-01") + def test_notification_title_praxis_assignment_for_student(self): + # GIVEN + casework = create_assignment( + assignment_type=AssignmentType.PRAXIS_ASSIGNMENT, + ) + assignment = Assignment.objects.get( + slug="test-lehrgang-assignment-mein-kundenstamm" + ) + + ac = AssignmentCompletion.objects.create( + completion_status=AssignmentCompletionStatus.EVALUATION_SUBMITTED.value, + assignment_user=self.student, + assignment=assignment, + evaluation_passed=True, + course_session=casework.course_session, + completion_data={}, + evaluation_max_points=10, + evaluation_points=10, + evaluation_user=self.trainer, + ) + + # WHEN + NotificationService.send_assignment_evaluated_notification( + recipient=ac.assignment_user, + sender=self.trainer, + assignment_completion=ac, + target_url="/some/url", + ) + + # THEN + self.assertEqual(1, len(Notification.objects.all())) + + notification = Notification.objects.get(recipient__username=self.student.email) + self.assertEqual("USER_INTERACTION", notification.notification_category) + self.assertIn("hat den Praxisauftrag", notification.verb)