Skip to content

Commit

Permalink
✅ [#504] Add tests general info table
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm committed Dec 2, 2024
1 parent 54c9011 commit f0b48d7
Show file tree
Hide file tree
Showing 2 changed files with 235 additions and 14 deletions.
188 changes: 181 additions & 7 deletions backend/src/openarchiefbeheer/destruction/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,20 @@ def test_has_short_review_process(self):
self.assertTrue(has_short_review_process)

def test_generate_destruction_report(self):
destruction_list = DestructionListFactory.create(status=ListStatus.deleted)
record_manager = UserFactory.create(
first_name="John",
last_name="Doe",
username="jdoe1",
post__can_start_destruction=True,
)
destruction_list = DestructionListFactory.create(
status=ListStatus.deleted,
end=datetime(2024, 12, 2, 12, tzinfo=timezone.get_default_timezone()),
)
logevent.destruction_list_deletion_triggered(destruction_list, record_manager)
DestructionListItemFactory.create(
processing_status=InternalStatus.succeeded,
status=ListItemStatus.suggested,
destruction_list=destruction_list,
extra_zaak_data={
"url": "http://zaken.nl/api/v1/zaken/111-111-111",
Expand All @@ -328,6 +339,7 @@ def test_generate_destruction_report(self):
)
DestructionListItemFactory.create(
processing_status=InternalStatus.succeeded,
status=ListItemStatus.suggested,
destruction_list=destruction_list,
extra_zaak_data={
"url": "http://zaken.nl/api/v1/zaken/111-111-222",
Expand Down Expand Up @@ -381,9 +393,27 @@ def test_generate_destruction_report(self):
sheet_deleted_zaken = wb[gettext("Deleted zaken")]
rows = list(sheet_deleted_zaken.iter_rows(values_only=True))

self.assertEqual(len(rows), 4)
self.assertEqual(len(rows), 7)
self.assertEqual(
rows[0][:4],
(
gettext("Date/Time of deletion"),
gettext("User who started the deletion"),
gettext("Groups"),
gettext("Number of deleted cases"),
),
)
self.assertEqual(
rows[1][:4],
(
"2024-12-02 12:00+01:00",
"John Doe (jdoe1)",
None,
3,
),
)
self.assertEqual(
rows[0],
rows[3],
(
"Zaaktype UUID",
"Zaaktype Omschrijving",
Expand All @@ -396,7 +426,7 @@ def test_generate_destruction_report(self):
),
)
self.assertEqual(
rows[1],
rows[4],
(
"111-111-111",
"Tralala zaaktype",
Expand All @@ -409,7 +439,7 @@ def test_generate_destruction_report(self):
),
)
self.assertEqual(
rows[2],
rows[5],
(
"111-111-111",
"Tralala zaaktype",
Expand All @@ -422,7 +452,7 @@ def test_generate_destruction_report(self):
),
)
self.assertEqual(
rows[3],
rows[6],
(
"111-111-222",
"Tralala zaaktype",
Expand All @@ -435,6 +465,148 @@ def test_generate_destruction_report(self):
),
)

def test_generate_destruction_report_with_cases_excluded_from_list(self):
destruction_list = DestructionListFactory.create(
status=ListStatus.deleted,
end=datetime(2024, 12, 2, 12, tzinfo=timezone.get_default_timezone()),
)
DestructionListItemFactory.create(
processing_status=InternalStatus.succeeded,
status=ListItemStatus.suggested,
destruction_list=destruction_list,
extra_zaak_data={
"url": "http://zaken.nl/api/v1/zaken/111-111-111",
"omschrijving": "Test description 3",
"identificatie": "ZAAK-01",
"startdatum": "2020-01-03",
"einddatum": "2022-01-03",
"resultaat": None,
"zaaktype": {
"url": "http://catalogi.nl/api/v1/zaaktypen/111-111-222",
"omschrijving": "Tralala zaaktype",
"selectielijst_procestype": {
"naam": "Instellen en inrichten organisatie",
},
},
},
)
DestructionListItemFactory.create(
processing_status=InternalStatus.new,
status=ListItemStatus.removed, # Case no longer in destruction list
destruction_list=destruction_list,
extra_zaak_data={
"url": "http://zaken.nl/api/v1/zaken/222-222-222",
"omschrijving": "Test description 3",
"identificatie": "ZAAK-02",
"startdatum": "2020-01-03",
"einddatum": "2022-01-03",
"resultaat": None,
"zaaktype": {
"url": "http://catalogi.nl/api/v1/zaaktypen/111-111-222",
"omschrijving": "Tralala zaaktype",
"selectielijst_procestype": {
"naam": "Instellen en inrichten organisatie",
},
},
},
)
DestructionListItemFactory.create(
processing_status=InternalStatus.succeeded,
destruction_list=destruction_list,
status=ListItemStatus.suggested,
extra_zaak_data={
"url": "http://zaken.nl/api/v1/zaken/333-333-333",
"omschrijving": "Test description 3",
"identificatie": "ZAAK-03",
"startdatum": "2020-01-03",
"einddatum": "2022-01-03",
"resultaat": None,
"zaaktype": {
"url": "http://catalogi.nl/api/v1/zaaktypen/111-111-222",
"omschrijving": "Tralala zaaktype",
"selectielijst_procestype": {
"naam": "Instellen en inrichten organisatie",
},
},
},
)

destruction_list.generate_destruction_report()

destruction_list.refresh_from_db()

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

self.assertEqual(len(rows), 6)
self.assertEqual(
rows[3],
(
"Zaaktype UUID",
"Zaaktype Omschrijving",
"Zaaktype Identificatie",
"Zaak Identificatie",
"Zaak Startdatum",
"Zaak Einddatum",
"Selectielijst Procestype",
"Resultaat",
),
)
deleted_zaken_ids = sorted([rows[4][3], rows[5][3]])
self.assertEqual(
deleted_zaken_ids,
["ZAAK-01", "ZAAK-03"],
)

def test_generate_destruction_report_with_multiple_logs(self):
record_manager1 = UserFactory.create(
first_name="John",
last_name="Doe",
username="jdoe1",
post__can_start_destruction=True,
)
record_manager2 = UserFactory.create(
first_name="Jane",
last_name="Doe",
username="jdoe2",
post__can_start_destruction=True,
)
destruction_list = DestructionListFactory.create(
status=ListStatus.deleted,
end=datetime(2024, 12, 2, 12, tzinfo=timezone.get_default_timezone()),
)
logevent.destruction_list_deletion_triggered(destruction_list, record_manager1)
logevent.destruction_list_deletion_triggered(destruction_list, record_manager2)

destruction_list.generate_destruction_report()

destruction_list.refresh_from_db()

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

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

def test_generate_destruction_report_review_process(self):
author = UserFactory.create(post__can_start_destruction=True)
reviewer = UserFactory.create(
Expand All @@ -455,7 +627,9 @@ def test_generate_destruction_report_review_process(self):
archivist.groups.add(archivist_group)

destruction_list = DestructionListFactory.create(
status=ListStatus.deleted, author=author
status=ListStatus.deleted,
author=author,
end=datetime(2024, 12, 2, 12, tzinfo=timezone.get_default_timezone()),
)

review_reviewer_rejected = DestructionListReviewFactory.create(
Expand Down
61 changes: 54 additions & 7 deletions backend/src/openarchiefbeheer/destruction/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from openarchiefbeheer.accounts.tests.factories import UserFactory
from openarchiefbeheer.emails.models import EmailConfig
from openarchiefbeheer.logging import logevent
from openarchiefbeheer.selection.models import SelectionItem
from openarchiefbeheer.zaken.models import Zaak
from openarchiefbeheer.zaken.tests.factories import ZaakFactory
Expand Down Expand Up @@ -358,9 +359,16 @@ def test_aborts_if_not_ready_to_delete(self, logs):

@override_settings(CELERY_TASK_ALWAYS_EAGER=True)
def test_process_list(self):
record_manager = UserFactory.create(
first_name="John",
last_name="Doe",
username="jdoe1",
post__can_start_destruction=True,
)
destruction_list = DestructionListFactory.create(
status=ListStatus.ready_to_delete
status=ListStatus.ready_to_delete, author=record_manager
)
logevent.destruction_list_deletion_triggered(destruction_list, record_manager)

item1 = DestructionListItemFactory.create(
with_zaak=True,
Expand All @@ -371,6 +379,7 @@ def test_process_list(self):
zaak__einddatum=date(2022, 1, 1),
zaak__resultaat="http://zaken.nl/api/v1/resultaten/111-111-111",
destruction_list=destruction_list,
status=ListItemStatus.suggested,
)
item2 = DestructionListItemFactory.create(
with_zaak=True,
Expand All @@ -381,6 +390,7 @@ def test_process_list(self):
zaak__einddatum=date(2022, 1, 2),
zaak__resultaat="http://zaken.nl/api/v1/resultaten/111-111-222",
destruction_list=destruction_list,
status=ListItemStatus.suggested,
)

with (
Expand All @@ -394,6 +404,7 @@ def test_process_list(self):
"openarchiefbeheer.destruction.utils.create_eio_destruction_report"
) as m_eio,
patch("openarchiefbeheer.destruction.utils.attach_report_to_zaak") as m_zio,
freeze_time("2024-12-02T12:00:00+01:00"),
):
delete_destruction_list(destruction_list)

Expand Down Expand Up @@ -445,9 +456,28 @@ def test_process_list(self):
sheet_deleted_zaken = wb[_("Deleted zaken")]
rows = list(sheet_deleted_zaken.iter_rows(values_only=True))

self.assertEqual(len(rows), 3)
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[1],
rows[4],
(
"111-111-111",
"Aangifte behandelen",
Expand All @@ -460,7 +490,7 @@ def test_process_list(self):
),
)
self.assertEqual(
rows[2],
rows[5],
(
"111-111-111",
"Aangifte behandelen",
Expand Down Expand Up @@ -547,10 +577,17 @@ def test_processing_list_with_failed_item(self):
m_zio.assert_called()

def test_complete_and_notify(self):
record_manager = UserFactory.create(
first_name="John",
last_name="Doe",
username="jdoe1",
post__can_start_destruction=True,
)
destruction_list = DestructionListFactory.create(
name="Some destruction list",
processing_status=InternalStatus.processing,
status=ListStatus.ready_to_delete,
author=record_manager,
)
DestructionListItemFactory.create(
processing_status=InternalStatus.succeeded,
Expand Down Expand Up @@ -585,6 +622,7 @@ def test_complete_and_notify(self):
)

self.assertIsNone(destruction_list.destruction_report.name)
logevent.destruction_list_deletion_triggered(destruction_list, record_manager)

with (
patch(
Expand Down Expand Up @@ -627,9 +665,18 @@ def test_complete_and_notify(self):
sheet_deleted_zaken = wb[_("Deleted zaken")]
rows = list(sheet_deleted_zaken.iter_rows(values_only=True))

self.assertEqual(len(rows), 2)
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[0],
rows[3],
(
"Zaaktype UUID",
"Zaaktype Omschrijving",
Expand All @@ -642,7 +689,7 @@ def test_complete_and_notify(self):
),
)
self.assertEqual(
rows[1],
rows[4],
(
"111-111-111",
"Tralala zaaktype",
Expand Down

0 comments on commit f0b48d7

Please sign in to comment.