Skip to content

Commit

Permalink
✅ Fix tests after rebase on main
Browse files Browse the repository at this point in the history
  • Loading branch information
damm89 committed Feb 9, 2024
1 parent 2097bd2 commit 83bd1d0
Show file tree
Hide file tree
Showing 18 changed files with 578 additions and 320 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from zgw_consumers.models import Service
from zgw_consumers.test import generate_oas_component, mock_service_oas_get

from zac.contrib.objects.kownsl.tests.utils import REVIEW_REQUEST
from zac.contrib.objects.kownsl.tests.utils import ReviewRequestFactory
from zac.contrib.objects.services import factory_review_request
from zac.core.permissions import zaakproces_usertasks, zaken_inzien
from zac.core.tests.utils import ClearCachesMixin
Expand Down Expand Up @@ -162,7 +162,7 @@ def test_add_permission_for_advisor(self, m):
vertrouwelijkheidaanduiding="zaakvertrouwelijk",
eigenschappen=[],
)
review_request = deepcopy(REVIEW_REQUEST)
review_request = ReviewRequestFactory()
review_request["zaak"] = zaak["url"]
review_request["userDeadlines"] = {f"user:{self.user.username}": "2099-01-01"}

Expand Down
15 changes: 9 additions & 6 deletions backend/src/zac/camunda/tests/test_user_task_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
from zac.camunda.data import Task
from zac.contrib.dowc.data import OpenDowc
from zac.contrib.objects.kownsl.constants import KownslTypes
from zac.contrib.objects.kownsl.tests.utils import REVIEW_REQUEST, REVIEWS_ADVICE
from zac.contrib.objects.kownsl.tests.utils import (
ReviewRequestFactory,
ReviewsAdviceFactory,
)
from zac.contrib.objects.services import factory_review_request, factory_reviews
from zac.core.models import CoreConfig
from zac.core.permissions import zaakproces_usertasks
Expand Down Expand Up @@ -380,7 +383,7 @@ def test_get_reconfigure_advice_review_request_user_task(self, m, gt, ct):
)

users = UserFactory.create_batch(3)
review_request_data = deepcopy(REVIEW_REQUEST)
review_request_data = ReviewRequestFactory()
review_request_data["assignedUsers"] = [
{
"deadline": "2020-01-01",
Expand Down Expand Up @@ -570,8 +573,8 @@ def test_get_zet_resultaat_context(self, m, *mocks):
json=paginated_response([self.zaaktype]),
)
tasks = [_get_task(**{"formKey": "zac:zetResultaat"})]
review_request = factory_review_request(REVIEW_REQUEST)
reviews = factory_reviews(REVIEWS_ADVICE)
review_request = factory_review_request(ReviewRequestFactory())
reviews = factory_reviews(ReviewsAdviceFactory())
mock_resource_get(m, self.zaaktype)
resultaattype = generate_oas_component(
"ztc",
Expand Down Expand Up @@ -836,7 +839,7 @@ def test_put_configure_advice_review_request_user_task(self, m, gt, ct):
"toelichting": "some-toelichting",
"id": None,
}
rr = deepcopy(REVIEW_REQUEST)
rr = ReviewRequestFactory()
rr["assignedUsers"] = [
{
"deadline": "2020-01-01",
Expand Down Expand Up @@ -900,7 +903,7 @@ def test_put_configure_advice_review_request_user_task(self, m, gt, ct):
def test_put_reconfigure_advice_review_request_user_task(self, m, gt, ct):
self._mock_permissions(m)
users = UserFactory.create_batch(3)
rr = deepcopy(REVIEW_REQUEST)
rr = ReviewRequestFactory()
rr["assignedUsers"] = [
{
"deadline": "2020-01-01",
Expand Down
3 changes: 2 additions & 1 deletion backend/src/zac/contrib/objects/kownsl/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,10 @@ class ZaakRevReqSummarySerializer(APIModelSerializer):
can_lock = serializers.SerializerMethodField(
label=_("can lock request"), help_text=_("User can lock the review request.")
)
completed = serializers.SerializerMethodField(
completed = serializers.IntegerField(
label=_("completed requests"),
help_text=_("The number of completed requests."),
source="get_completed",
)

class Meta:
Expand Down
5 changes: 4 additions & 1 deletion backend/src/zac/contrib/objects/kownsl/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,17 @@ def get_open_reviews(self) -> List[OpenReview]:
if not getattr(self, "open_reviews", []):
user_deadlines = deepcopy(self.user_deadlines)

# remove those who have already reviewed
for review in self.get_reviews():
# if the reviewer is a group remove the group and...
if name := review.group.get("name"):
user_deadlines.pop(f"{AssigneeTypeChoices.group}:{name}", None)

# ... the user if the reviewer is a user
author = f"{AssigneeTypeChoices.user}:{review.author['username']}"
user_deadlines.pop(author, None)

# create dictionary of users for their information
# create dictionary of users for their information as stored on the review request object
assignees = {}
for assignee in self.assigned_users:
for user in assignee.user_assignees:
Expand Down
84 changes: 62 additions & 22 deletions backend/src/zac/contrib/objects/kownsl/tests/test_camunda.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from copy import deepcopy
from datetime import date
from unittest.mock import MagicMock, patch

from django.contrib.sites.models import Site
from django.urls import reverse

import requests_mock
Expand All @@ -11,11 +11,7 @@
from rest_framework.exceptions import ValidationError
from rest_framework.test import APITestCase
from zgw_consumers.api_models.base import factory
from zgw_consumers.api_models.catalogi import (
InformatieObjectType,
ResultaatType,
ZaakType,
)
from zgw_consumers.api_models.catalogi import InformatieObjectType, ZaakType
from zgw_consumers.api_models.constants import VertrouwelijkheidsAanduidingen
from zgw_consumers.api_models.documenten import Document
from zgw_consumers.constants import APITypes
Expand All @@ -38,14 +34,16 @@
ZaakInformatieTaskSerializer,
)
from .utils import (
ADVICE,
CATALOGI_ROOT,
DOCUMENT_URL,
DOCUMENTS_ROOT,
REVIEW_REQUEST,
REVIEWS_ADVICE,
ZAAK_URL,
ZAKEN_ROOT,
AdviceFactory,
AssignedUsersFactory,
ReviewRequestFactory,
ReviewsAdviceFactory,
UserAssigneeFactory,
)

# Taken from https://docs.camunda.org/manual/7.13/reference/rest/task/get/
Expand Down Expand Up @@ -304,27 +302,44 @@ def test_approval_context_serializer_with_user(self, m):

@requests_mock.Mocker()
def test_advice_context_serializer_previously_assigned_users(self, m):
user_assignees = UserAssigneeFactory(
**{
"username": "some-other-author",
"first_name": "Some Other First",
"last_name": "Some Last",
"full_name": "Some Other First Some Last",
}
)
assigned_users2 = AssignedUsersFactory(
**{
"deadline": "2022-04-15",
"user_assignees": [user_assignees],
"group_assignees": [],
"email_notification": False,
}
)
review_request = ReviewRequestFactory()
review_request["assignedUsers"].append(assigned_users2)

task = _get_task(**{"formKey": "zac:configureAdviceRequest"})
m.get(
f"https://camunda.example.com/engine-rest/task/{TASK_DATA['id']}/variables/assignedUsers?deserializeValue=false",
status_code=404,
)
m.get(
f"https://camunda.example.com/engine-rest/task/{TASK_DATA['id']}/variables/kownslReviewRequestId?deserializeValue=false",
json=serialize_variable(REVIEW_REQUEST["id"]),
json=serialize_variable(review_request["id"]),
)

# Let resolve_assignee get the right users and groups
UserFactory.create(
username=REVIEW_REQUEST["assignedUsers"][0]["userAssignees"][0]
username=review_request["assignedUsers"][0]["userAssignees"][0]
)
UserFactory.create(
username=REVIEW_REQUEST["assignedUsers"][1]["userAssignees"][0]
username=review_request["assignedUsers"][1]["userAssignees"][0]
)

UserFactory.create(username="some-other-author")

rr = factory(ReviewRequest, REVIEW_REQUEST)
rr = factory(ReviewRequest, review_request)
rr.documents = [self.document.url]

# Avoid patching fetch_reviews and everything
Expand Down Expand Up @@ -354,7 +369,7 @@ def test_advice_context_serializer_previously_assigned_users(self, m):
"identificatie": self.zaak.identificatie,
},
),
"id": REVIEW_REQUEST["id"],
"id": review_request["id"],
"previously_assigned_users": [
{
"user_assignees": [
Expand Down Expand Up @@ -406,6 +421,10 @@ def setUpTestData(cls):
Service.objects.create(api_type=APITypes.zrc, api_root=ZAKEN_ROOT)
Service.objects.create(api_type=APITypes.ztc, api_root=CATALOGI_ROOT)

site = Site.objects.get_current()
site.domain = "example"
site.save()

cls.catalogus = generate_oas_component(
"ztc",
"schemas/Catalogus",
Expand Down Expand Up @@ -455,8 +474,26 @@ def setUpTestData(cls):
"zac.core.api.validators.search_informatieobjects",
return_value=[cls.document_es],
)
rr = deepcopy(REVIEW_REQUEST)

user_assignees = UserAssigneeFactory(
**{
"username": "some-other-author",
"first_name": "Some Other First",
"last_name": "Some Last",
"full_name": "Some Other First Some Last",
}
)
assigned_users2 = AssignedUsersFactory(
**{
"deadline": "2022-04-15",
"user_assignees": [user_assignees],
"group_assignees": [],
"email_notification": False,
}
)
rr = ReviewRequestFactory()
rr["documents"] = [cls.document.url]
rr["assignedUsers"].append(assigned_users2)

# Let resolve_assignee get the right users and groups
UserFactory.create(username=rr["assignedUsers"][0]["userAssignees"][0])
Expand Down Expand Up @@ -759,7 +796,7 @@ def test_configure_review_request_serializer_get_process_variables(self):
[f"user:{user}" for user in self.users_1] + [f"group:{self.group}"]
],
"kownslReviewRequestId": str(self.review_request.id),
"kownslFrontendUrl": f"http://example.com/ui/kownsl/review-request/advice?uuid={self.review_request.id}",
"kownslFrontendUrl": f"http://example/ui/kownsl/review-request/advice?uuid={self.review_request.id}",
"emailNotificationList": email_notification_list,
},
)
Expand Down Expand Up @@ -799,7 +836,10 @@ def test_configure_review_request_serializer_fail_get_process_variables(self):
@freeze_time("1999-12-31T23:59:59Z")
@requests_mock.Mocker()
def test_reconfigure_review_request_serializer_user_already_reviewed(self, m):
user = UserFactory.create(username=ADVICE["author"]["username"])
advice = AdviceFactory()
review_request = ReviewRequestFactory()
reviews_advice = ReviewsAdviceFactory()
user = UserFactory.create(username=advice["author"]["username"])
assigned_users = [
{
"user_assignees": [user.username for user in self.users_1]
Expand All @@ -819,15 +859,15 @@ def test_reconfigure_review_request_serializer_user_already_reviewed(self, m):
"assigned_users": assigned_users,
"toelichting": "some-toelichting",
"documents": [self.document.url],
"id": REVIEW_REQUEST["id"],
"id": review_request["id"],
}

task = _get_task(**{"formKey": "zac:configureAdviceRequest"})

rr = factory(ReviewRequest, REVIEW_REQUEST)
rr = factory(ReviewRequest, review_request)

# Avoid patching fetch_reviews and everything
rr.reviews = factory(Reviews, REVIEWS_ADVICE).reviews
rr.reviews = factory(Reviews, reviews_advice).reviews
rr.fetched_reviews = True

with patch(
Expand Down
Loading

0 comments on commit 83bd1d0

Please sign in to comment.