Skip to content

Commit

Permalink
✅ [#4930] Test the export form implementation
Browse files Browse the repository at this point in the history
Ensures that the filters are correctly implemented.
  • Loading branch information
sergei-maertens committed Dec 27, 2024
1 parent 33554a1 commit d8b516e
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions src/openforms/forms/tests/admin/test_form_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from openforms.submissions.tests.factories import SubmissionFactory

from ...forms import ExportStatisticsForm
from ..factories import FormFactory


@disable_admin_mfa()
Expand Down Expand Up @@ -97,3 +98,92 @@ def test_successful_export_downloads_file(self):
response["Content-Disposition"],
'attachment; filename="submissions_2024-12-01_2025-01-01.xlsx"',
)

def test_export_form_filters(self):
"""
Test that the form filters correctly filter down the matching log records.
"""
plugin = DemoRegistration("demo")
form1, form2, form3 = FormFactory.create_batch(3)
with freeze_time("2024-12-20T16:44:00+01:00"):
registered_submission_1 = SubmissionFactory.create(
form=form1,
registration_success=True,
public_registration_reference="SUB-01",
)
logevent.registration_success(registered_submission_1, plugin=plugin)

failed_submission = SubmissionFactory.create(
form=form1,
registration_failed=True,
public_registration_reference="FAIL-01",
)
logevent.registration_failure(failed_submission, error=Exception("nope"))
with freeze_time("2024-11-20T12:00:00+01:00"):
registered_submission_2 = SubmissionFactory.create(
form=form2,
registration_success=True,
public_registration_reference="SUB-02",
)
logevent.registration_success(registered_submission_2, plugin=plugin)

with freeze_time("2024-12-05T12:00:00+01:00"):
registered_submission_3 = SubmissionFactory.create(
form=form3,
registration_success=True,
public_registration_reference="SUB-03",
)
logevent.registration_success(registered_submission_3, plugin=plugin)

with freeze_time("2024-12-06T10:00:00+01:00"):
registered_submission_4 = SubmissionFactory.create(
form=form3,
registration_success=True,
public_registration_reference="SUB-04",
)
logevent.registration_success(registered_submission_4, plugin=plugin)

with self.subTest("filter on start date"):
export_form1 = ExportStatisticsForm(
data={
"start_date": "2024-12-14",
"end_date": "2024-12-31",
}
)
assert export_form1.is_valid()

dataset1 = export_form1.export()

self.assertEqual(len(dataset1), 1)
self.assertEqual(dataset1[0][0], "SUB-01")

with self.subTest("filter on end date"):
export_form2 = ExportStatisticsForm(
data={
"start_date": "2024-01-01",
"end_date": "2024-12-05",
}
)
assert export_form2.is_valid()

dataset2 = export_form2.export()

self.assertEqual(len(dataset2), 2)
self.assertEqual(dataset2[0][0], "SUB-02")
self.assertEqual(dataset2[1][0], "SUB-03")

with self.subTest("filter on subset of forms"):
export_form3 = ExportStatisticsForm(
data={
"start_date": "2024-01-01",
"end_date": "2024-12-31",
"limit_to_forms": [form2.pk, form3.pk],
}
)
assert export_form3.is_valid()

dataset3 = export_form3.export()
self.assertEqual(len(dataset3), 3)
self.assertEqual(dataset3[0][0], "SUB-02")
self.assertEqual(dataset3[1][0], "SUB-03")
self.assertEqual(dataset3[2][0], "SUB-04")

0 comments on commit d8b516e

Please sign in to comment.