Skip to content

Commit

Permalink
#561 - test: add tests for CoReviewerAssignmentSerializer
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvandescheur committed Dec 20, 2024
1 parent 5893dee commit 9bf0fdb
Showing 1 changed file with 139 additions and 0 deletions.
139 changes: 139 additions & 0 deletions backend/src/openarchiefbeheer/destruction/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@

from openarchiefbeheer.accounts.tests.factories import UserFactory
from openarchiefbeheer.emails.models import EmailConfig
from ..api.constants import MAX_NUMBER_CO_REVIEWERS

from ...zaken.tests.factories import ZaakFactory
from ..api.serializers import (
DestructionListCoReviewSerializer,
DestructionListReviewSerializer,
DestructionListWriteSerializer,
CoReviewerAssignmentSerializer,
)
from ..constants import ListItemStatus, ListRole, ListStatus, ReviewDecisionChoices
from ..models import (
Expand Down Expand Up @@ -1282,3 +1284,140 @@ def test_create_review(self):
},
message,
)


class CoReviewerAssignmentSerializerTests(TestCase):
def test_validate_max_co_reviewers_invalid_full(self):
destruction_list = DestructionListFactory.create(
status=ListStatus.ready_to_review
)

request = factory.put("/foo")
request.user = UserFactory.create()

serializer = CoReviewerAssignmentSerializer(
instance=destruction_list,
data={
"add": [
{"user": user.pk}
for user in UserFactory.create_batch(
10, post__can_co_review_destruction=True
)
],
"comment": "gh-561",
},
context={
"request": request,
"destruction_list": destruction_list,
},
partial=False,
)

self.assertFalse(serializer.is_valid())
self.assertEqual(
serializer.errors["non_field_errors"][0],
_("The maximum number of allowed co-reviewers is %(max_co_reviewers)s.")
% {"max_co_reviewers": MAX_NUMBER_CO_REVIEWERS},
)

def test_validate_max_co_reviewers_valid_full(self):
destruction_list = DestructionListFactory.create(
status=ListStatus.ready_to_review
)

request = factory.put("/foo")
request.user = UserFactory.create()

serializer = CoReviewerAssignmentSerializer(
instance=destruction_list,
data={
"add": [
{"user": user.pk}
for user in UserFactory.create_batch(
5, post__can_co_review_destruction=True
)
],
"comment": "gh-561",
},
context={
"request": request,
"destruction_list": destruction_list,
},
partial=False,
)

self.assertTrue(serializer.is_valid())

def test_validate_max_co_reviewers_invalid_partial(self):
destruction_list = DestructionListFactory.create(
status=ListStatus.ready_to_review
)
DestructionListAssigneeFactory.create_batch(
5, destruction_list=destruction_list, role=ListRole.co_reviewer
)

request = factory.patch("/foo")
request.user = UserFactory.create()

serializer = CoReviewerAssignmentSerializer(
instance=destruction_list,
data={
"add": [
{
"user": UserFactory.create(
post__can_co_review_destruction=True
).pk
}
],
"comment": "gh-561",
},
context={
"request": request,
"destruction_list": destruction_list,
},
partial=True,
)

self.assertFalse(serializer.is_valid())
self.assertEqual(
serializer.errors["non_field_errors"][0],
_("The maximum number of allowed co-reviewers is %(max_co_reviewers)s.")
% {"max_co_reviewers": MAX_NUMBER_CO_REVIEWERS},
)

def test_validate_max_co_reviewers_valid_partial(self):
destruction_list = DestructionListFactory.create(
status=ListStatus.ready_to_review
)
assignees = DestructionListAssigneeFactory.create_batch(
5, destruction_list=destruction_list, role=ListRole.co_reviewer
)

request = factory.patch("/foo")
request.user = UserFactory.create()

serializer = CoReviewerAssignmentSerializer(
instance=destruction_list,
data={
"add": [
{
"user": UserFactory.create(
post__can_co_review_destruction=True
).pk
}
],
"remove": [
{
"user": assignees[0].user.pk,
}
],
"comment": "gh-561",
},
context={
"request": request,
"destruction_list": destruction_list,
},
partial=True,
)

self.assertTrue(serializer.is_valid())

0 comments on commit 9bf0fdb

Please sign in to comment.