From 97d0cc47edc4fba5a02d74b974ef5ee36f7fc3cf Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Mon, 27 Jan 2025 16:00:27 +0100 Subject: [PATCH] :test_tube: [#5035] Add test for unintended mutation side effect Damn you, side effects. --- .../submissions/tests/test_models.py | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/openforms/submissions/tests/test_models.py b/src/openforms/submissions/tests/test_models.py index 282059960f..c6c5550844 100644 --- a/src/openforms/submissions/tests/test_models.py +++ b/src/openforms/submissions/tests/test_models.py @@ -456,3 +456,54 @@ def test_names_do_not_break_pdf_saving_to_disk(self): report.generate_submission_report_pdf() self.assertTrue(report.content.storage.exists(report.content.name)) + + @tag("gh-5035") + def test_total_configuration_wrapper_does_not_mutate_first_step(self): + form = FormFactory.create( + generate_minimal_setup=True, + formstep__form_definition__configuration={ + "components": [ + { + "key": "textfield1", + "type": "textfield", + "label": "textfield", + } + ] + }, + ) + FormStepFactory.create( + form=form, + order=1, + form_definition__configuration={ + "components": [ + { + "key": "textfield2", + "type": "textfield", + "label": "Text field 2", + } + ] + }, + ) + submission = SubmissionFactory.create(form=form) + + configuration_wrapper = submission.total_configuration_wrapper + + with self.subTest("all keys present"): + self.assertIn("textfield1", configuration_wrapper) + self.assertIn("textfield2", configuration_wrapper) + + step1, step2 = submission.steps + + with self.subTest("step 1 keys"): + step1_keys = [ + c["key"] + for c in step1.form_step.form_definition.configuration["components"] + ] + self.assertEqual(step1_keys, ["textfield1"]) + + with self.subTest("step 2 keys"): + step2_keys = [ + c["key"] + for c in step2.form_step.form_definition.configuration["components"] + ] + self.assertEqual(step2_keys, ["textfield2"])