Skip to content

Commit 7f8fd3b

Browse files
✅ 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.
1 parent 25fba12 commit 7f8fd3b

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/openforms/prefill/tests/test_prefill_variables.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
SubmissionFactory,
2727
SubmissionStepFactory,
2828
)
29+
from openforms.variables.constants import FormVariableDataTypes
2930

3031
from ..contrib.demo.plugin import DemoPrefill
3132
from ..service import prefill_variables
@@ -265,13 +266,23 @@ def get_prefill_values_from_options(cls, submission: Submission, options):
265266
class PrefillVariablesFromOptionsTests(TestCase):
266267
@patch(
267268
"openforms.prefill.service.fetch_prefill_values_from_options",
268-
return_value={"voornamen": "Not so random string"},
269+
return_value={
270+
"object_data": {
271+
"voornamen": "Not so random string",
272+
},
273+
"voornamen": "Not so random string",
274+
},
269275
)
270276
def test_applying_prefill_plugin_from_user_defined_with_options(self, m_prefill):
271277
submission = SubmissionFactory.create()
272278
FormVariableFactory.create(
273-
key="voornamen",
279+
key="voornamen", form=submission.form, user_defined=True
280+
)
281+
FormVariableFactory.create(
282+
key="object_data",
274283
form=submission.form,
284+
user_defined=True,
285+
data_type=FormVariableDataTypes.object,
275286
prefill_plugin="objects_api",
276287
prefill_options={
277288
"objects_api_group": 1,
@@ -285,16 +296,9 @@ def test_applying_prefill_plugin_from_user_defined_with_options(self, m_prefill)
285296

286297
prefill_variables(submission=submission)
287298

288-
submission_value_variables_state = (
289-
submission.load_submission_value_variables_state()
290-
)
291-
292-
self.assertEqual(1, len(submission_value_variables_state.variables))
293-
294-
submission_variable = submission_value_variables_state.get_variable(
295-
key="voornamen"
296-
)
297-
299+
variables_state = submission.load_submission_value_variables_state(refresh=True)
300+
self.assertEqual(len(variables_state.variables), 2)
301+
submission_variable = variables_state.get_variable(key="voornamen")
298302
self.assertEqual("Not so random string", submission_variable.value)
299303
self.assertEqual(
300304
SubmissionValueVariableSources.prefill, submission_variable.source

0 commit comments

Comments
 (0)