From 5bc4af1431fecc97122d3c0f34ebdd6bea2c170c Mon Sep 17 00:00:00 2001 From: SilviaAmAm Date: Mon, 25 Nov 2024 16:59:56 +0100 Subject: [PATCH] :white_check_mark: [#499] Test log filtering for event --- .../accounts/tests/factories.py | 1 + .../logging/tests/test_endpoints.py | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 backend/src/openarchiefbeheer/logging/tests/test_endpoints.py diff --git a/backend/src/openarchiefbeheer/accounts/tests/factories.py b/backend/src/openarchiefbeheer/accounts/tests/factories.py index 481c84833..ce4f43ffb 100644 --- a/backend/src/openarchiefbeheer/accounts/tests/factories.py +++ b/backend/src/openarchiefbeheer/accounts/tests/factories.py @@ -17,6 +17,7 @@ class UserFactory(DjangoModelFactory): class Meta: model = User + django_get_or_create = ("username",) class Params: superuser = factory.Trait( diff --git a/backend/src/openarchiefbeheer/logging/tests/test_endpoints.py b/backend/src/openarchiefbeheer/logging/tests/test_endpoints.py new file mode 100644 index 000000000..a16c2559e --- /dev/null +++ b/backend/src/openarchiefbeheer/logging/tests/test_endpoints.py @@ -0,0 +1,51 @@ +from furl import furl +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 +from openarchiefbeheer.destruction.tests.factories import DestructionListFactory + + +class LogsViewsetTest(APITestCase): + def test_not_authenticated(self): + endpoint = reverse("api:logs-list") + + response = self.client.get(endpoint) + + self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) + + def test_filter(self): + record_manager = UserFactory.create(post__can_start_destruction=True) + destruction_list1 = DestructionListFactory.create() + destruction_list2 = DestructionListFactory.create() + + TimelineLog.objects.create( + content_object=destruction_list1, + template="logging/destruction_list_created.txt", + extra_data={}, + user=record_manager, + ) + TimelineLog.objects.create( + content_object=destruction_list1, + template="logging/destruction_list_ready_for_first_review.txt", + extra_data={}, + user=record_manager, + ) + TimelineLog.objects.create( + content_object=destruction_list2, + template="logging/destruction_list_created.txt", + extra_data={}, + user=record_manager, + ) + + endpoint = furl(reverse("api:logs-list")) + endpoint.args["destruction_list"] = destruction_list1.uuid + endpoint.args["event"] = "destruction_list_created" + + self.client.force_login(record_manager) + response = self.client.get(endpoint.url) + + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(len(response.json()), 1)