-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ [#1451] -- add test for expected export data format
- Loading branch information
1 parent
3b023db
commit 9def0ad
Showing
1 changed file
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
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, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
"type": "content", | ||
"key": "content", | ||
"html": "<p>Some wysigyg content</p>", | ||
}, | ||
], | ||
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, | ||
), | ||
) |