Skip to content

Commit

Permalink
Merge pull request #12 from maykinmedia/feature/345-destruction-list-…
Browse files Browse the repository at this point in the history
…endpoint

[#345] Destruction list endpoint
  • Loading branch information
SilviaAmAm authored May 14, 2024
2 parents d7675fe + b454200 commit 900c291
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
39 changes: 38 additions & 1 deletion backend/src/openarchiefbeheer/destruction/api/viewsets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from django.db import transaction
from django.utils.translation import gettext_lazy as _

from drf_spectacular.utils import OpenApiExample, extend_schema, extend_schema_view
from rest_framework import mixins, viewsets
from rest_framework.permissions import IsAuthenticated

Expand All @@ -8,7 +10,42 @@
from .serializers import DestructionListSerializer


class DestructionListViewSet(mixins.CreateModelMixin, viewsets.GenericViewSet):
@extend_schema_view(
list=extend_schema(
summary=_("List destruction lists"),
description=_("List all destruction lists."),
),
create=extend_schema(
summary=_("Create destruction list"),
description=_("Create a new destruction list."),
examples=[
OpenApiExample(
name="Example list creation",
value={
"name": "An example list",
"containsSensitiveInfo": True,
"assignees": [
{"user": 1, "order": 0},
{"user": 2, "order": 1},
],
"items": [
{
"zaak": "http://some-zaken-api.nl/zaken/api/v1/zaken/111-111-111",
"extraZaakData": {},
},
{
"zaak": "http://some-zaken-api.nl/zaken/api/v1/zaken/222-222-222",
"extraZaakData": {},
},
],
},
)
],
),
)
class DestructionListViewSet(
mixins.CreateModelMixin, mixins.ListModelMixin, viewsets.GenericViewSet
):
serializer_class = DestructionListSerializer
queryset = DestructionList.objects.all()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
from openarchiefbeheer.accounts.tests.factories import UserFactory
from openarchiefbeheer.destruction.constants import ListItemStatus
from openarchiefbeheer.destruction.models import DestructionList
from openarchiefbeheer.destruction.tests.factories import DestructionListItemFactory
from openarchiefbeheer.destruction.tests.factories import (
DestructionListFactory,
DestructionListItemFactory,
)


class DestructionListViewSetTest(APITestCase):
Expand Down Expand Up @@ -85,6 +88,18 @@ def test_create_destruction_list(self):

self.assertEqual(destruction_list.author, record_manager)

def test_list_destruction_lists(self):
user = UserFactory.create()
DestructionListFactory.create_batch(3)

self.client.force_authenticate(user=user)
endpoint = reverse("api:destructionlist-list")

response = self.client.get(endpoint)

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.json()), 3)

def test_zaak_already_in_another_destruction_list(self):
record_manager = UserFactory.create(role__can_start_destruction=True)
user1 = UserFactory.create(
Expand Down

0 comments on commit 900c291

Please sign in to comment.