@@ -381,6 +381,112 @@ def test_registration_hook_with_failed_and_completed_payments(self):
381
381
failed_payments = submission .payments .filter (status = PaymentStatus .failed )
382
382
self .assertEqual (failed_payments .count (), 1 )
383
383
384
+ def test_register_submission_transform_selectboxes_data (self ):
385
+ register = Registry ()
386
+
387
+ submission = SubmissionFactory .from_components (
388
+ components_list = [
389
+ {
390
+ "key" : "selectboxes" ,
391
+ "label" : "Selectboxes" ,
392
+ "type" : "selectboxes" ,
393
+ "openForms" : {
394
+ "dataSrc" : "manual" ,
395
+ "translations" : {},
396
+ "transformData" : True ,
397
+ },
398
+ "values" : [
399
+ {"value" : "foo" , "label" : "foo" },
400
+ {"value" : "bar" , "label" : "bar" },
401
+ {"value" : "baz" , "label" : "baz" },
402
+ ],
403
+ }
404
+ ],
405
+ submitted_data = {"selectboxes" : {"foo" : True , "bar" : False , "baz" : True }},
406
+ completed = True ,
407
+ form__registration_backend = "callback" ,
408
+ form__registration_backend_options = {
409
+ "string" : "some-option" ,
410
+ "service" : self .service .id ,
411
+ },
412
+ )
413
+
414
+ # register the callback, including the assertions
415
+ test_closure = self
416
+
417
+ @register ("callback" )
418
+ class Plugin (BasePlugin ):
419
+ verbose_name = "Assertion callback"
420
+ configuration_options = OptionsSerializer
421
+
422
+ def register_submission (self , submission , options ):
423
+ state = submission .load_submission_value_variables_state ()
424
+ data_to_submit = state .get_data ()
425
+ test_closure .assertEqual (
426
+ data_to_submit , {"selectboxes" : ["baz" , "foo" ]}
427
+ )
428
+ return {"result" : "ok" }
429
+
430
+ # call the hook for the submission, while patching the model field registry
431
+ model_field = FormRegistrationBackend ._meta .get_field ("backend" )
432
+ with patch_registry (model_field , register ):
433
+ register_submission (submission .id , PostSubmissionEvents .on_completion )
434
+
435
+ submission .refresh_from_db ()
436
+ self .assertEqual (
437
+ submission .registration_result ,
438
+ {"result" : "ok" },
439
+ )
440
+
441
+ def test_register_submission_transform_data_function_undefined (self ):
442
+ register = Registry ()
443
+
444
+ submission = SubmissionFactory .from_components (
445
+ components_list = [
446
+ {
447
+ "key" : "textfield" ,
448
+ "label" : "Field that has no transform function defined" ,
449
+ "type" : "text" ,
450
+ "openForms" : {
451
+ "translations" : {},
452
+ "transformData" : True ,
453
+ },
454
+ }
455
+ ],
456
+ submitted_data = {"textfield" : "foo" },
457
+ completed = True ,
458
+ form__registration_backend = "callback" ,
459
+ form__registration_backend_options = {
460
+ "string" : "some-option" ,
461
+ "service" : self .service .id ,
462
+ },
463
+ )
464
+
465
+ # register the callback, including the assertions
466
+ test_closure = self
467
+
468
+ @register ("callback" )
469
+ class Plugin (BasePlugin ):
470
+ verbose_name = "Assertion callback"
471
+ configuration_options = OptionsSerializer
472
+
473
+ def register_submission (self , submission , options ):
474
+ state = submission .load_submission_value_variables_state ()
475
+ data_to_submit = state .get_data ()
476
+ test_closure .assertEqual (data_to_submit , {"textfield" : "foo" })
477
+ return {"result" : "ok" }
478
+
479
+ # call the hook for the submission, while patching the model field registry
480
+ model_field = FormRegistrationBackend ._meta .get_field ("backend" )
481
+ with patch_registry (model_field , register ):
482
+ register_submission (submission .id , PostSubmissionEvents .on_completion )
483
+
484
+ submission .refresh_from_db ()
485
+ self .assertEqual (
486
+ submission .registration_result ,
487
+ {"result" : "ok" },
488
+ )
489
+
384
490
385
491
class NumRegistrationsTest (TestCase ):
386
492
@patch ("openforms.plugins.plugin.GlobalConfiguration.get_solo" )
0 commit comments