14
14
from zgw_consumers .test .factories import ServiceFactory
15
15
16
16
from openforms .contrib .brk .models import BRKConfig
17
- from openforms .contrib .brk .tests .base import BRK_SERVICE
17
+ from openforms .contrib .brk .tests .base import BRK_SERVICE , INVALID_BRK_SERVICE
18
18
from openforms .contrib .kadaster .models import KadasterApiConfig
19
19
from openforms .forms .tests .factories import (
20
20
FormFactory ,
@@ -244,12 +244,119 @@ def test_timestamp_constraint_returns_no_results(self):
244
244
@override_settings (LANGUAGE_CODE = "en" )
245
245
class BrokenConfigurationTests (TestCase ):
246
246
247
+ def test_no_addressNL_component_not_collected (self ):
248
+ FormFactory .create (
249
+ generate_minimal_setup = True ,
250
+ formstep__form_definition__configuration = {
251
+ "components" : [
252
+ {
253
+ "key" : "textField" ,
254
+ "type" : "textfield" ,
255
+ "label" : "Text Field" ,
256
+ }
257
+ ],
258
+ },
259
+ )
260
+
261
+ broken_configuration = collect_broken_configurations ()
262
+
263
+ self .assertEqual (broken_configuration , [])
264
+
265
+ @patch (
266
+ "openforms.contrib.brk.client.BRKConfig.get_solo" ,
267
+ return_value = BRKConfig (service = None ),
268
+ )
269
+ def test_no_brk_conf_for_addressnl_and_missing_validator_not_collected (self , m ):
270
+ FormFactory .create (
271
+ generate_minimal_setup = True ,
272
+ formstep__form_definition__configuration = {
273
+ "components" : [
274
+ {
275
+ "key" : "addressNl" ,
276
+ "type" : "addressNL" ,
277
+ "label" : "AddressNL" ,
278
+ "defaultValue" : {
279
+ "postcode" : "" ,
280
+ "houseLetter" : "" ,
281
+ "houseNumber" : "" ,
282
+ "houseNumberAddition" : "" ,
283
+ },
284
+ }
285
+ ],
286
+ },
287
+ )
288
+
289
+ broken_configuration = collect_broken_configurations ()
290
+
291
+ self .assertEqual (broken_configuration , [])
292
+
293
+ @patch (
294
+ "openforms.contrib.brk.client.BRKConfig.get_solo" ,
295
+ return_value = BRKConfig (service = None ),
296
+ )
297
+ def test_no_brk_conf_for_addressnl_and_existing_validator_not_collected (self , m ):
298
+ FormFactory .create (
299
+ generate_minimal_setup = True ,
300
+ formstep__form_definition__configuration = {
301
+ "components" : [
302
+ {
303
+ "key" : "addressNl" ,
304
+ "type" : "addressNL" ,
305
+ "label" : "AddressNL" ,
306
+ "defaultValue" : {
307
+ "postcode" : "" ,
308
+ "houseLetter" : "" ,
309
+ "houseNumber" : "" ,
310
+ "houseNumberAddition" : "" ,
311
+ },
312
+ "validate" : {"plugins" : ["brk-zakelijk-gerechtigd" ]},
313
+ }
314
+ ],
315
+ },
316
+ )
317
+
318
+ broken_configuration = collect_broken_configurations ()
319
+
320
+ self .assertEqual (broken_configuration , [])
321
+
322
+ @patch (
323
+ "openforms.contrib.brk.client.BRKConfig.get_solo" ,
324
+ return_value = BRKConfig (service = BRK_SERVICE ),
325
+ )
326
+ def test_valid_brk_conf_for_addressnl_and_missing_validator_not_collected (
327
+ self , brk_config
328
+ ):
329
+ FormFactory .create (
330
+ generate_minimal_setup = True ,
331
+ formstep__form_definition__configuration = {
332
+ "components" : [
333
+ {
334
+ "key" : "addressNl" ,
335
+ "type" : "addressNL" ,
336
+ "label" : "AddressNL" ,
337
+ "defaultValue" : {
338
+ "postcode" : "" ,
339
+ "houseLetter" : "" ,
340
+ "houseNumber" : "" ,
341
+ "houseNumberAddition" : "" ,
342
+ },
343
+ }
344
+ ],
345
+ },
346
+ )
347
+
348
+ broken_configuration = collect_broken_configurations ()
349
+
350
+ self .assertEqual (broken_configuration , [])
351
+
247
352
@patch (
248
353
"openforms.contrib.brk.client.BRKConfig.get_solo" ,
249
354
return_value = BRKConfig (service = BRK_SERVICE ),
250
355
)
251
356
@requests_mock .Mocker ()
252
- def test_valid_brk_congiguration_for_addressNL_not_collected (self , brk_config , m ):
357
+ def test_valid_brk_conf_for_addressnl_and_existing_validator_not_collected (
358
+ self , brk_config , m
359
+ ):
253
360
FormFactory .create (
254
361
generate_minimal_setup = True ,
255
362
formstep__form_definition__configuration = {
@@ -264,6 +371,7 @@ def test_valid_brk_congiguration_for_addressNL_not_collected(self, brk_config, m
264
371
"houseNumber" : "" ,
265
372
"houseNumberAddition" : "" ,
266
373
},
374
+ "validate" : {"plugins" : ["brk-zakelijk-gerechtigd" ]},
267
375
}
268
376
],
269
377
},
@@ -280,9 +388,11 @@ def test_valid_brk_congiguration_for_addressNL_not_collected(self, brk_config, m
280
388
281
389
@patch (
282
390
"openforms.contrib.brk.client.BRKConfig.get_solo" ,
283
- return_value = BRKConfig (service = None ),
391
+ return_value = BRKConfig (service = INVALID_BRK_SERVICE ),
284
392
)
285
- def test_invalid_brk_configuration_for_addressNL_is_collected (self , brk_config ):
393
+ def test_invalid_brk_conf_for_addressnl_and_missing_validator_not_collected (
394
+ self , brk_config
395
+ ):
286
396
FormFactory .create (
287
397
generate_minimal_setup = True ,
288
398
formstep__form_definition__configuration = {
@@ -304,30 +414,45 @@ def test_invalid_brk_configuration_for_addressNL_is_collected(self, brk_config):
304
414
305
415
broken_configuration = collect_broken_configurations ()
306
416
307
- self .assertEqual (len (broken_configuration ), 1 )
308
- self .assertEqual (broken_configuration [0 ].config_name , "BRK Client" )
417
+ self .assertEqual (broken_configuration , [])
309
418
310
419
@patch (
311
420
"openforms.contrib.brk.client.BRKConfig.get_solo" ,
312
- return_value = BRKConfig (service = None ),
421
+ return_value = BRKConfig (service = INVALID_BRK_SERVICE ),
313
422
)
314
- def test_invalid_brk_congiguration_but_unused_not_collected (self , brk_config ):
423
+ @requests_mock .Mocker ()
424
+ def test_invalid_brk_conf_for_addressnl_and_existing_validator_collected (
425
+ self , brk_config , m
426
+ ):
315
427
FormFactory .create (
316
428
generate_minimal_setup = True ,
317
429
formstep__form_definition__configuration = {
318
430
"components" : [
319
431
{
320
- "key" : "textField" ,
321
- "type" : "textfield" ,
322
- "label" : "Text Field" ,
432
+ "key" : "addressNl" ,
433
+ "type" : "addressNL" ,
434
+ "label" : "AddressNL" ,
435
+ "defaultValue" : {
436
+ "postcode" : "" ,
437
+ "houseLetter" : "" ,
438
+ "houseNumber" : "" ,
439
+ "houseNumberAddition" : "" ,
440
+ },
441
+ "validate" : {"plugins" : ["brk-zakelijk-gerechtigd" ]},
323
442
}
324
443
],
325
444
},
326
445
)
327
446
447
+ m .get (
448
+ "https://api.brk.kadaster.nl/invalid/kadastraalonroerendezaken?postcode=1234AB&huisnummer=1" ,
449
+ status_code = 400 ,
450
+ )
451
+
328
452
broken_configuration = collect_broken_configurations ()
329
453
330
- self .assertEqual (broken_configuration , [])
454
+ self .assertEqual (len (broken_configuration ), 1 )
455
+ self .assertEqual (broken_configuration [0 ].config_name , "BRK Client" )
331
456
332
457
@patch (
333
458
"openforms.contrib.kadaster.models.KadasterApiConfig.get_solo" ,
@@ -464,10 +589,8 @@ def test_invalid_bag_configuration_for_address_nl_component_is_collected(
464
589
465
590
broken_configuration = collect_broken_configurations ()
466
591
467
- self .assertEqual (len (broken_configuration ), 2 )
468
- self .assertIn (
469
- "BAG Client" , [config .config_name for config in broken_configuration ]
470
- )
592
+ self .assertEqual (len (broken_configuration ), 1 )
593
+ self .assertEqual (broken_configuration [0 ].config_name , "BAG Client" )
471
594
472
595
@patch ("openforms.contrib.kadaster.models.KadasterApiConfig.get_solo" )
473
596
def test_invalid_bag_configuration_for_address_nl_component_not_collected_when_disabled (
@@ -491,10 +614,7 @@ def test_invalid_bag_configuration_for_address_nl_component_not_collected_when_d
491
614
492
615
broken_configuration = collect_broken_configurations ()
493
616
494
- self .assertEqual (len (broken_configuration ), 1 )
495
- self .assertNotIn (
496
- "BAG Client" , [config .config_name for config in broken_configuration ]
497
- )
617
+ self .assertEqual (len (broken_configuration ), 0 )
498
618
499
619
500
620
@override_settings (LANGUAGE_CODE = "en" )
0 commit comments