Skip to content

Commit

Permalink
✅ [#1451] -- add test for expected export data format
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-maertens committed May 9, 2022
1 parent 3b023db commit 6440881
Showing 1 changed file with 113 additions and 0 deletions.
113 changes: 113 additions & 0 deletions src/openforms/submissions/tests/test_exports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
from datetime import datetime

from django.test import TestCase
from django.utils import timezone

from freezegun import freeze_time

from ..exports import create_submission_export
from ..models import Submission
from .factories import SubmissionFactory


class ExportTests(TestCase):
@freeze_time("2022-05-09T13:00:00Z")
def test_complex_formio_configuration(self):
"""
Assert that complex formio configurations with logic are exported correctly.
All form keys should always be present, even if they are hidden.
"""
SubmissionFactory.from_components(
[
{
"type": "textfield",
"key": "input1",
"hidden": False,
},
{
"type": "textfield",
"key": "input2",
"hidden": True,
},
{
"type": "fieldset",
"key": "fieldset1",
"components": [
{
"type": "textfield",
"key": "input3",
"hidden": False,
},
{
"type": "textfield",
"key": "input4",
"hidden": True,
},
],
},
{
"type": "columns",
"key": "columns1",
"hidden": True,
"columns": [
{
"size": 6,
"components": [
{
"type": "textfield",
"key": "input5",
"hidden": False,
},
],
},
{
"size": 6,
"components": [
{
"type": "textfield",
"key": "input6",
"hidden": True,
},
],
},
],
},
],
submitted_data={
"input1": "Input 1",
"input3": "Input 3",
},
form__name="Export test",
completed=True,
completed_on=timezone.now(),
)

dataset = create_submission_export(Submission.objects.all())

self.assertEqual(
dataset.headers,
[
"Formuliernaam",
"Inzendingdatum",
"input1",
"input2",
"input3",
"input4",
"input5",
"input6",
],
)
self.assertEqual(
dataset[0],
(
"Export test",
datetime(2022, 5, 9, 15, 0, 0),
"Input 1",
None,
"Input 3",
None,
None,
None,
),
)

0 comments on commit 6440881

Please sign in to comment.