From 7f8fd3ba3ca26cf5abb9cae8e56ca8b11e6634d0 Mon Sep 17 00:00:00 2001 From: Sergei Maertens Date: Fri, 3 Jan 2025 15:02:38 +0100 Subject: [PATCH] :white_check_mark: Clarify test for prefill from options The plugin return value determines which values get assigned to which variables - there is no default mechanism that stores the retrieved object in the variable that holds the prefill configuration. This means that for the objects API, the retrieved object is never persisted to DB, only the mapped variables contained in the configuration. --- .../prefill/tests/test_prefill_variables.py | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/openforms/prefill/tests/test_prefill_variables.py b/src/openforms/prefill/tests/test_prefill_variables.py index b053d609bd..d978d29760 100644 --- a/src/openforms/prefill/tests/test_prefill_variables.py +++ b/src/openforms/prefill/tests/test_prefill_variables.py @@ -26,6 +26,7 @@ SubmissionFactory, SubmissionStepFactory, ) +from openforms.variables.constants import FormVariableDataTypes from ..contrib.demo.plugin import DemoPrefill from ..service import prefill_variables @@ -265,13 +266,23 @@ def get_prefill_values_from_options(cls, submission: Submission, options): class PrefillVariablesFromOptionsTests(TestCase): @patch( "openforms.prefill.service.fetch_prefill_values_from_options", - return_value={"voornamen": "Not so random string"}, + return_value={ + "object_data": { + "voornamen": "Not so random string", + }, + "voornamen": "Not so random string", + }, ) def test_applying_prefill_plugin_from_user_defined_with_options(self, m_prefill): submission = SubmissionFactory.create() FormVariableFactory.create( - key="voornamen", + key="voornamen", form=submission.form, user_defined=True + ) + FormVariableFactory.create( + key="object_data", form=submission.form, + user_defined=True, + data_type=FormVariableDataTypes.object, prefill_plugin="objects_api", prefill_options={ "objects_api_group": 1, @@ -285,16 +296,9 @@ def test_applying_prefill_plugin_from_user_defined_with_options(self, m_prefill) prefill_variables(submission=submission) - submission_value_variables_state = ( - submission.load_submission_value_variables_state() - ) - - self.assertEqual(1, len(submission_value_variables_state.variables)) - - submission_variable = submission_value_variables_state.get_variable( - key="voornamen" - ) - + variables_state = submission.load_submission_value_variables_state(refresh=True) + self.assertEqual(len(variables_state.variables), 2) + submission_variable = variables_state.get_variable(key="voornamen") self.assertEqual("Not so random string", submission_variable.value) self.assertEqual( SubmissionValueVariableSources.prefill, submission_variable.source