From 0487746b93ed75f007fa69ac22951f901e36cabb Mon Sep 17 00:00:00 2001 From: SilviaAmAm Date: Tue, 26 Nov 2024 16:23:55 +0100 Subject: [PATCH] :white_check_mark: [#499] Test logging when review processed --- .../tests/endpoints/test_reviewresponse.py | 24 +++++++++++ .../destruction/tests/test_tasks.py | 41 +++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/backend/src/openarchiefbeheer/destruction/tests/endpoints/test_reviewresponse.py b/backend/src/openarchiefbeheer/destruction/tests/endpoints/test_reviewresponse.py index b462bb35..cf0ae12a 100644 --- a/backend/src/openarchiefbeheer/destruction/tests/endpoints/test_reviewresponse.py +++ b/backend/src/openarchiefbeheer/destruction/tests/endpoints/test_reviewresponse.py @@ -8,6 +8,7 @@ from rest_framework import status from rest_framework.reverse import reverse from rest_framework.test import APITestCase +from timeline_logger.models import TimelineLog from openarchiefbeheer.accounts.tests.factories import UserFactory @@ -56,6 +57,10 @@ def test_filter_on_review(self): def test_create_review_response(self): record_manager = UserFactory.create(post__can_start_destruction=True) + record_manager_group, created = Group.objects.get_or_create( + name="Record Manager" + ) + record_manager.groups.add(record_manager_group) review = DestructionListReviewFactory.create( destruction_list__author=record_manager, destruction_list__status=ListStatus.changes_requested, @@ -133,6 +138,25 @@ def test_create_review_response(self): self.assertEqual(item_response3.action_zaak["archiefactiedatum"], "2030-01-01") + logs = TimelineLog.objects.for_object(review.destruction_list) + + self.assertEqual(logs.count(), 1) + + message = logs[0].get_message() + + self.assertIn( + _( + "User %(author)s (member of group %(groups)s) has processed the feedback on " + 'destruction list "%(list_name)s".' + ) + % { + "author": str(record_manager), + "groups": "Record Manager", + "list_name": review.destruction_list.name, + }, + message, + ) + def test_can_create_response_if_not_author(self): record_manager1 = UserFactory.create(post__can_start_destruction=True) record_manager2 = UserFactory.create(post__can_start_destruction=True) diff --git a/backend/src/openarchiefbeheer/destruction/tests/test_tasks.py b/backend/src/openarchiefbeheer/destruction/tests/test_tasks.py index 93e0d2bc..ab142e68 100644 --- a/backend/src/openarchiefbeheer/destruction/tests/test_tasks.py +++ b/backend/src/openarchiefbeheer/destruction/tests/test_tasks.py @@ -4,12 +4,14 @@ from django.core import mail from django.test import TestCase, override_settings, tag +from django.utils.translation import gettext as _, ngettext from freezegun import freeze_time from privates.test import temp_private_root from requests import HTTPError from requests_mock import Mocker from testfixtures import log_capture +from timeline_logger.models import TimelineLog from zgw_consumers.constants import APITypes from zgw_consumers.test.factories import ServiceFactory @@ -163,6 +165,7 @@ def test_reject_suggestion_does_not_change_zaak(self, m): zaak = ZaakFactory.create(archiefactiedatum="2025-01-01") review_item_response = ReviewItemResponseFactory.create( review_item__destruction_list_item__zaak=zaak, + review_item__destruction_list_item__destruction_list=review_response.review.destruction_list, review_item__review=review_response.review, action_item=DestructionListItemAction.keep, action_zaak_type=ZaakActionType.bewaartermijn, @@ -204,6 +207,21 @@ def test_reject_suggestion_does_not_change_zaak(self, m): zaak.archiefactiedatum.isoformat(), "2025-01-01" ) # NOT changed!! + logs = TimelineLog.objects.for_object(review_response.review.destruction_list) + + self.assertEqual(logs.count(), 1) + + message = logs[0].get_message() + + self.assertIn( + _( + 'The review response of destruction list "%(list_name)s" has been processed.' + ) + % {"list_name": review_response.review.destruction_list.name}, + message, + ) + self.assertIn(_("There is now one zaak on the list."), message) + def test_prepopulating_selection(self, m): destruction_list = DestructionListFactory.create( status=ListStatus.changes_requested @@ -275,6 +293,29 @@ def test_prepopulating_selection(self, m): self.assertNotIn("detail", selection_items[0].selection_data) self.assertFalse(selection_items[0].selection_data["selected"]) + logs = TimelineLog.objects.for_object(destruction_list) + + self.assertEqual(logs.count(), 1) + + message = logs[0].get_message() + + self.assertIn( + _( + 'The review response of destruction list "%(list_name)s" has been processed.' + ) + % {"list_name": review_response.review.destruction_list.name}, + message, + ) + self.assertIn( + ngettext( + "There is now one zaak on the list.", + "There are now %(number_of_zaken)s zaken on the list.", + 2, + ) + % {"number_of_zaken": 2}, + message, + ) + @temp_private_root() class ProcessDeletingZakenTests(TestCase):