Skip to content

Commit

Permalink
🐛 Fix bugs and add regression tests (#1258)
Browse files Browse the repository at this point in the history
  • Loading branch information
damm89 committed May 10, 2024
1 parent 204187a commit 4b5b4bd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
4 changes: 2 additions & 2 deletions backend/src/zac/core/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,8 +1046,8 @@ def _fetch_document(url: str) -> Response:
Retrieve document by URL from DRC or cache.
"""
cache_key = f"document:{url}"
if cache_key in cache:
return cache.get(cache_key)
if cache_key in cache and (response := cache.get(cache_key)):
return response
client = client_from_url(url)
headers = client.auth.credentials()
response = requests.get(url, headers=headers)
Expand Down
11 changes: 5 additions & 6 deletions backend/src/zac/notifications/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def _handle_status_create(self, data: Dict):
)
if tasks:
for task in tasks:
complete_task(task.id)
complete_task(task.id, variables=dict())

# index in ES
update_status_in_zaak_document(zaak)
Expand Down Expand Up @@ -288,11 +288,10 @@ def _handle_zaakobject_destroy(self, zaak_url: str, zaakobject_url: str):
# Get zaakobjectdocument
zaakobjectdocument = get_zaakobject_document(zaakobject_url)

# update related_zaken in objecten index
update_related_zaken_in_object_document(zaakobjectdocument.object)

# delete from zaakobject index
zaakobjectdocument.delete()
if zaakobjectdocument: # update related_zaken in objecten index
update_related_zaken_in_object_document(zaakobjectdocument.object)
# delete from zaakobject index
zaakobjectdocument.delete()

def _handle_zaakinformatieobject_create(
self, zaak_url: str, zaakinformatieobject_url: str
Expand Down
2 changes: 1 addition & 1 deletion backend/src/zac/notifications/tests/test_status_created.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def test_zaak_updated_is_closed(self, rm):
"name": settings.CAMUNDA_OPEN_BIJDRAGE_TASK_NAME + zaak["identificatie"]
}
)
mock_complete_task.assert_called_once_with("some-id")
mock_complete_task.assert_called_once_with("some-id", variables=dict())

activity.refresh_from_db()
self.assertEqual(activity.status, ActivityStatuses.finished)
Expand Down
24 changes: 24 additions & 0 deletions backend/src/zac/notifications/tests/test_zaakobject_changed.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,30 @@ def test_zaakobject_created_indexed_in_es(self, rm):
],
)

def test_zaakobject_destroyed_in_es_if_not_found_regression_test(self, rm):
self._setup_mocks(rm)
rm.get(
f"{ZAKEN_ROOT}zaakobjecten?zaak={ZAAK}",
json=paginated_response([]),
)
rm.get(
f"{ZAKEN_ROOT}zaakobjecten?object={OBJECT}",
json=paginated_response([]),
)

path = reverse("notifications:callback")
response = self.client.post(path, NOTIFICATION_DESTROY)

self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
self.refresh_index()

# Assert no zaakobject document is found with the zo uuid
with self.assertRaises(NotFoundError):
ZaakObjectDocument.get(id=_get_uuid_from_url(ZAAKOBJECT))

with self.assertRaises(NotFoundError):
ObjectDocument.get(id=OBJECT_RESPONSE["uuid"])

def test_zaakobject_destroyed_in_es(self, rm):
self._setup_mocks(rm)
rm.get(
Expand Down

0 comments on commit 4b5b4bd

Please sign in to comment.