Skip to content

Commit

Permalink
✅ [#502] Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm committed Nov 29, 2024
1 parent 10c54da commit 4649d41
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 24 deletions.
65 changes: 54 additions & 11 deletions backend/src/openarchiefbeheer/destruction/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
from django.core.exceptions import ObjectDoesNotExist
from django.test import TestCase
from django.utils import timezone
from django.utils.translation import gettext

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 @@ -344,25 +346,66 @@ def test_generate_destruction_report(self):

destruction_list.refresh_from_db()

destruction_list.destruction_report
lines = [line for line in destruction_list.destruction_report.readlines()]
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(lines), 4)
self.assertEqual(len(rows), 4)
self.assertEqual(
lines[0],
b"url,einddatum,resultaat,startdatum,omschrijving,identificatie,zaaktype url,zaaktype omschrijving,selectielijst procestype nummer\n",
rows[0],
(
"url",
"einddatum",
"resultaat",
"startdatum",
"omschrijving",
"identificatie",
"zaaktype url",
"zaaktype omschrijving",
"selectielijst procestype nummer",
),
)
self.assertEqual(
lines[1],
b"http://zaken.nl/api/v1/zaken/111-111-111,2022-01-01,http://zaken.nl/api/v1/resultaten/111-111-111,2020-01-01,Test description 1,ZAAK-01,http://catalogi.nl/api/v1/zaaktypen/111-111-111,Tralala zaaktype,1\n",
rows[1],
(
"http://zaken.nl/api/v1/zaken/111-111-111",
"2022-01-01",
"http://zaken.nl/api/v1/resultaten/111-111-111",
"2020-01-01",
"Test description 1",
"ZAAK-01",
"http://catalogi.nl/api/v1/zaaktypen/111-111-111",
"Tralala zaaktype",
1,
),
)
self.assertEqual(
lines[2],
b"http://zaken.nl/api/v1/zaken/111-111-222,2022-01-02,http://zaken.nl/api/v1/resultaten/111-111-222,2020-01-02,Test description 2,ZAAK-02,http://catalogi.nl/api/v1/zaaktypen/111-111-111,Tralala zaaktype,1\n",
rows[2],
(
"http://zaken.nl/api/v1/zaken/111-111-222",
"2022-01-02",
"http://zaken.nl/api/v1/resultaten/111-111-222",
"2020-01-02",
"Test description 2",
"ZAAK-02",
"http://catalogi.nl/api/v1/zaaktypen/111-111-111",
"Tralala zaaktype",
1,
),
)
self.assertEqual(
lines[3],
b"http://zaken.nl/api/v1/zaken/111-111-333,2022-01-03,http://zaken.nl/api/v1/resultaten/111-111-333,2020-01-03,Test description 3,ZAAK-03,http://catalogi.nl/api/v1/zaaktypen/111-111-222,Tralala zaaktype,2\n",
rows[3],
(
"http://zaken.nl/api/v1/zaken/111-111-333",
"2022-01-03",
"http://zaken.nl/api/v1/resultaten/111-111-333",
"2020-01-03",
"Test description 3",
"ZAAK-03",
"http://catalogi.nl/api/v1/zaaktypen/111-111-222",
"Tralala zaaktype",
2,
),
)

def test_zaak_creation_skipped_if_internal_status_succeeded(self):
Expand Down
71 changes: 58 additions & 13 deletions backend/src/openarchiefbeheer/destruction/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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 @@ -439,16 +440,38 @@ def test_process_list(self):
).exists()
)

lines = [line for line in destruction_list.destruction_report.readlines()]
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(lines), 3)
self.assertEqual(len(rows), 3)
self.assertEqual(
lines[1],
b"http://zaken.nl/api/v1/zaken/111-111-111,2022-01-01,http://zaken.nl/api/v1/resultaten/111-111-111,2020-01-01,Test description 1,ZAAK-01,http://catalogue-api.nl/zaaktypen/111-111-111,Aangifte behandelen,1\n",
rows[1],
(
"http://zaken.nl/api/v1/zaken/111-111-111",
"2022-01-01",
"http://zaken.nl/api/v1/resultaten/111-111-111",
"2020-01-01",
"Test description 1",
"ZAAK-01",
"http://catalogue-api.nl/zaaktypen/111-111-111",
"Aangifte behandelen",
1,
),
)
self.assertEqual(
lines[2],
b"http://zaken.nl/api/v1/zaken/222-222-222,2022-01-02,http://zaken.nl/api/v1/resultaten/111-111-222,2020-01-02,Test description 2,ZAAK-02,http://catalogue-api.nl/zaaktypen/111-111-111,Aangifte behandelen,1\n",
rows[2],
(
"http://zaken.nl/api/v1/zaken/222-222-222",
"2022-01-02",
"http://zaken.nl/api/v1/resultaten/111-111-222",
"2020-01-02",
"Test description 2",
"ZAAK-02",
"http://catalogue-api.nl/zaaktypen/111-111-111",
"Aangifte behandelen",
1,
),
)

m_zaak.assert_called()
Expand Down Expand Up @@ -583,19 +606,41 @@ def test_complete_and_notify(self):
self.assertEqual(destruction_list.processing_status, InternalStatus.succeeded)
self.assertEqual(
destruction_list.destruction_report.name,
"destruction_reports/2024/10/09/report_some-destruction-list.csv",
"destruction_reports/2024/10/09/report_some-destruction-list.xlsx",
)

lines = [line for line in destruction_list.destruction_report.readlines()]
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(lines), 2)
self.assertEqual(len(rows), 2)
self.assertEqual(
lines[0],
b"url,einddatum,resultaat,startdatum,omschrijving,identificatie,zaaktype url,zaaktype omschrijving,selectielijst procestype nummer\n",
rows[0],
(
"url",
"einddatum",
"resultaat",
"startdatum",
"omschrijving",
"identificatie",
"zaaktype url",
"zaaktype omschrijving",
"selectielijst procestype nummer",
),
)
self.assertEqual(
lines[1],
b"http://zaken.nl/api/v1/zaken/111-111-111,2022-01-01,http://zaken.nl/api/v1/resultaten/111-111-111,2020-01-01,Test description 1,ZAAK-01,http://catalogi.nl/api/v1/zaaktypen/111-111-111,Tralala zaaktype,1\n",
rows[1],
(
"http://zaken.nl/api/v1/zaken/111-111-111",
"2022-01-01",
"http://zaken.nl/api/v1/resultaten/111-111-111",
"2020-01-01",
"Test description 1",
"ZAAK-01",
"http://catalogi.nl/api/v1/zaaktypen/111-111-111",
"Tralala zaaktype",
1,
),
)

@override_settings(CELERY_TASK_ALWAYS_EAGER=True)
Expand Down

0 comments on commit 4649d41

Please sign in to comment.