Skip to content

Commit

Permalink
✅ [#557] Test deleting local destruction report
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm committed Dec 24, 2024
1 parent 9aa2f52 commit 118f3ef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 97 deletions.
13 changes: 13 additions & 0 deletions backend/src/openarchiefbeheer/destruction/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os
from datetime import date, datetime
from unittest.mock import patch

from django.contrib.auth.models import Group
from django.core.exceptions import ObjectDoesNotExist
from django.core.files.base import ContentFile
from django.test import TestCase
from django.utils import timezone
from django.utils.translation import gettext
Expand Down Expand Up @@ -965,7 +967,15 @@ def test_clean_local_metadata(self):
destruction_list = DestructionListFactory.create(
processing_status=InternalStatus.succeeded,
status=ListStatus.deleted,
destruction_report=ContentFile(
b"Hello I am a report.", name="report_test.txt"
),
)

path = destruction_list.destruction_report.path
self.assertIsNotNone(destruction_list.destruction_report)
self.assertTrue(os.path.isfile(path))

item1 = DestructionListItemFactory.create(
processing_status=InternalStatus.succeeded,
destruction_list=destruction_list,
Expand Down Expand Up @@ -1012,6 +1022,9 @@ def test_clean_local_metadata(self):

self.assertEqual(item1.extra_zaak_data, {})
self.assertEqual(item2.extra_zaak_data, {})
with self.assertRaises(ValueError):
destruction_list.destruction_report.file
self.assertFalse(os.path.isfile(path))


class DestructionListCoReviewTest(TestCase):
Expand Down
101 changes: 4 additions & 97 deletions backend/src/openarchiefbeheer/destruction/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from django.utils.translation import gettext as _, ngettext

from freezegun import freeze_time
from openpyxl import load_workbook
from privates.test import temp_private_root
from requests import HTTPError
from requests_mock import Mocker
Expand Down Expand Up @@ -452,63 +451,14 @@ def test_process_list(self):
).exists()
)

wb = load_workbook(filename=destruction_list.destruction_report.path)
sheet_deleted_zaken = wb[_("Deleted zaken")]
rows = list(sheet_deleted_zaken.iter_rows(values_only=True))

self.assertEqual(len(rows), 6)
self.assertEqual(
rows[0][:4],
(
_("Date/Time of deletion"),
_("User who started the deletion"),
_("Groups"),
_("Number of deleted cases"),
),
)
self.assertEqual(
rows[1][:4],
(
"2024-12-02 12:00+01:00",
"John Doe (jdoe1)",
None,
2,
),
)

self.assertEqual(
rows[4],
(
"111-111-111",
"Aangifte behandelen",
"ZAAKTYPE-01",
"ZAAK-01",
"2020-01-01",
"2022-01-01",
"Evaluatie uitvoeren",
"This is a result type",
),
)
self.assertEqual(
rows[5],
(
"111-111-111",
"Aangifte behandelen",
"ZAAKTYPE-01",
"ZAAK-02",
"2020-01-02",
"2022-01-02",
"Evaluatie uitvoeren",
"This is a result type",
),
)

m_zaak.assert_called()
m_eio.assert_called()
m_zio.assert_called()

self.assertEqual(item1.extra_zaak_data, {})
self.assertEqual(item2.extra_zaak_data, {})
with self.assertRaises(ValueError):
destruction_list.destruction_report.file

@log_capture(level=logging.INFO)
def test_item_skipped_if_already_succeeded(self, logs):
Expand Down Expand Up @@ -651,57 +601,14 @@ def test_complete_and_notify(self):

self.assertEqual(destruction_list.status, ListStatus.deleted)
self.assertEqual(destruction_list.processing_status, InternalStatus.succeeded)
self.assertEqual(
destruction_list.destruction_report.name,
"destruction_reports/2024/10/09/report_some-destruction-list.xlsx",
)
self.assertEqual(
destruction_list.end.astimezone(
tz=timezone.get_default_timezone()
).isoformat(),
"2024-10-09T12:00:00+02:00",
)

wb = load_workbook(filename=destruction_list.destruction_report.path)
sheet_deleted_zaken = wb[_("Deleted zaken")]
rows = list(sheet_deleted_zaken.iter_rows(values_only=True))

self.assertEqual(len(rows), 5)
self.assertEqual(
rows[1][:4],
(
"2024-10-09 12:00+02:00",
"John Doe (jdoe1)",
None,
1,
),
)
self.assertEqual(
rows[3],
(
"Zaaktype UUID",
"Zaaktype Omschrijving",
"Zaaktype Identificatie",
"Zaak Identificatie",
"Zaak Startdatum",
"Zaak Einddatum",
"Selectielijst Procestype",
"Resultaat",
),
)
self.assertEqual(
rows[4],
(
"111-111-111",
"Tralala zaaktype",
None,
"ZAAK-01",
"2020-01-01",
"2022-01-01",
"Evaluatie uitvoeren",
"Resulttype 0",
),
)
with self.assertRaises(ValueError):
destruction_list.destruction_report.file

@override_settings(CELERY_TASK_ALWAYS_EAGER=True)
def test_other_items_processed_if_one_fails(self):
Expand Down

0 comments on commit 118f3ef

Please sign in to comment.