Skip to content

Commit

Permalink
✅ Clarify test for prefill from options
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sergei-maertens committed Jan 3, 2025
1 parent 25fba12 commit 7f8fd3b
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/openforms/prefill/tests/test_prefill_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
SubmissionFactory,
SubmissionStepFactory,
)
from openforms.variables.constants import FormVariableDataTypes

from ..contrib.demo.plugin import DemoPrefill
from ..service import prefill_variables
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 7f8fd3b

Please sign in to comment.