Skip to content

Commit

Permalink
✅ [#499] Test log filtering for event
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm committed Nov 26, 2024
1 parent d633295 commit f27e90a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/src/openarchiefbeheer/accounts/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class UserFactory(DjangoModelFactory):

class Meta:
model = User
django_get_or_create = ("username",)

class Params:
superuser = factory.Trait(
Expand Down
51 changes: 51 additions & 0 deletions backend/src/openarchiefbeheer/logging/tests/test_endpoints.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit f27e90a

Please sign in to comment.