@@ -301,6 +301,8 @@ def test_flags_conditions_rule_match_multiple_actions_multiple_rules_multiple_co
301
301
302
302
303
303
# check a case where the feature exists but the rule doesn't match so we revert to the default value of the feature
304
+
305
+ # Check IN/NOT_IN/KEY_IN_VALUE/KEY_NOT_IN_VALUE/VALUE_IN_KEY/VALUE_NOT_IN_KEY conditions
304
306
def test_flags_match_rule_with_in_action (mocker , config ):
305
307
expected_value = True
306
308
mocked_app_config_schema = {
@@ -395,8 +397,201 @@ def test_flags_no_match_rule_with_not_in_action(mocker, config):
395
397
feature_flags = init_feature_flags (mocker , mocked_app_config_schema , config )
396
398
toggle = feature_flags .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "a" }, default = False )
397
399
assert toggle == expected_value
400
+
401
+ def test_flags_match_rule_with_key_in_value_action (mocker , config ):
402
+ expected_value = True
403
+ mocked_app_config_schema = {
404
+ "my_feature" : {
405
+ "default" : False ,
406
+ "rules" : {
407
+ "tenant id is contained in [6, 2]" : {
408
+ "when_match" : expected_value ,
409
+ "conditions" : [
410
+ {
411
+ "action" : RuleAction .KEY_IN_VALUE .value ,
412
+ "key" : "tenant_id" ,
413
+ "value" : ["6" , "2" ],
414
+ }
415
+ ],
416
+ }
417
+ },
418
+ }
419
+ }
420
+ feature_flags = init_feature_flags (mocker , mocked_app_config_schema , config )
421
+ toggle = feature_flags .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "a" }, default = False )
422
+ assert toggle == expected_value
423
+
424
+
425
+ def test_flags_no_match_rule_with_key_in_value_action (mocker , config ):
426
+ expected_value = False
427
+ mocked_app_config_schema = {
428
+ "my_feature" : {
429
+ "default" : expected_value ,
430
+ "rules" : {
431
+ "tenant id is contained in [8, 2]" : {
432
+ "when_match" : True ,
433
+ "conditions" : [
434
+ {
435
+ "action" : RuleAction .KEY_IN_VALUE .value ,
436
+ "key" : "tenant_id" ,
437
+ "value" : ["8" , "2" ],
438
+ }
439
+ ],
440
+ }
441
+ },
442
+ }
443
+ }
444
+ feature_flags = init_feature_flags (mocker , mocked_app_config_schema , config )
445
+ toggle = feature_flags .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "a" }, default = False )
446
+ assert toggle == expected_value
447
+
448
+
449
+ def test_flags_match_rule_with_key_not_in_value_action (mocker , config ):
450
+ expected_value = True
451
+ mocked_app_config_schema = {
452
+ "my_feature" : {
453
+ "default" : False ,
454
+ "rules" : {
455
+ "tenant id is contained in [8, 2]" : {
456
+ "when_match" : expected_value ,
457
+ "conditions" : [
458
+ {
459
+ "action" : RuleAction .KEY_NOT_IN_VALUE .value ,
460
+ "key" : "tenant_id" ,
461
+ "value" : ["10" , "4" ],
462
+ }
463
+ ],
464
+ }
465
+ },
466
+ }
467
+ }
468
+ feature_flags = init_feature_flags (mocker , mocked_app_config_schema , config )
469
+ toggle = feature_flags .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "a" }, default = False )
470
+ assert toggle == expected_value
471
+
472
+
473
+ def test_flags_no_match_rule_with_key_not_in_value_action (mocker , config ):
474
+ expected_value = False
475
+ mocked_app_config_schema = {
476
+ "my_feature" : {
477
+ "default" : expected_value ,
478
+ "rules" : {
479
+ "tenant id is contained in [8, 2]" : {
480
+ "when_match" : True ,
481
+ "conditions" : [
482
+ {
483
+ "action" : RuleAction .KEY_NOT_IN_VALUE .value ,
484
+ "key" : "tenant_id" ,
485
+ "value" : ["6" , "4" ],
486
+ }
487
+ ],
488
+ }
489
+ },
490
+ }
491
+ }
492
+ feature_flags = init_feature_flags (mocker , mocked_app_config_schema , config )
493
+ toggle = feature_flags .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "a" }, default = False )
494
+ assert toggle == expected_value
495
+
496
+ def test_flags_match_rule_with_value_in_key_action (mocker , config ):
497
+ expected_value = True
498
+ mocked_app_config_schema = {
499
+ "my_feature" : {
500
+ "default" : False ,
501
+ "rules" : {
502
+ "tenant id is contained in [6, 2]" : {
503
+ "when_match" : expected_value ,
504
+ "conditions" : [
505
+ {
506
+ "action" : RuleAction .VALUE_IN_KEY .value ,
507
+ "key" : "groups" ,
508
+ "value" : "SYSADMIN" ,
509
+ }
510
+ ],
511
+ }
512
+ },
513
+ }
514
+ }
515
+ feature_flags = init_feature_flags (mocker , mocked_app_config_schema , config )
516
+ toggle = feature_flags .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "a" , "groups" : ["SYSADMIN" , "IT" ]}, default = False )
517
+ assert toggle == expected_value
518
+
519
+
520
+ def test_flags_no_match_rule_with_value_in_key_action (mocker , config ):
521
+ expected_value = False
522
+ mocked_app_config_schema = {
523
+ "my_feature" : {
524
+ "default" : expected_value ,
525
+ "rules" : {
526
+ "tenant id is contained in [8, 2]" : {
527
+ "when_match" : True ,
528
+ "conditions" : [
529
+ {
530
+ "action" : RuleAction .VALUE_IN_KEY .value ,
531
+ "key" : "groups" ,
532
+ "value" : "GUEST" ,
533
+ }
534
+ ],
535
+ }
536
+ },
537
+ }
538
+ }
539
+ feature_flags = init_feature_flags (mocker , mocked_app_config_schema , config )
540
+ toggle = feature_flags .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "a" , "groups" : ["SYSADMIN" , "IT" ]}, default = False )
541
+ assert toggle == expected_value
542
+
543
+
544
+ def test_flags_match_rule_with_value_not_in_key_action (mocker , config ):
545
+ expected_value = True
546
+ mocked_app_config_schema = {
547
+ "my_feature" : {
548
+ "default" : False ,
549
+ "rules" : {
550
+ "tenant id is contained in [8, 2]" : {
551
+ "when_match" : expected_value ,
552
+ "conditions" : [
553
+ {
554
+ "action" : RuleAction .VALUE_NOT_IN_KEY .value ,
555
+ "key" : "groups" ,
556
+ "value" : "GUEST" ,
557
+ }
558
+ ],
559
+ }
560
+ },
561
+ }
562
+ }
563
+ feature_flags = init_feature_flags (mocker , mocked_app_config_schema , config )
564
+ toggle = feature_flags .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "a" , "groups" : ["SYSADMIN" , "IT" ]}, default = False )
565
+ assert toggle == expected_value
566
+
567
+
568
+ def test_flags_no_match_rule_with_value_not_in_key_action (mocker , config ):
569
+ expected_value = False
570
+ mocked_app_config_schema = {
571
+ "my_feature" : {
572
+ "default" : expected_value ,
573
+ "rules" : {
574
+ "tenant id is contained in [8, 2]" : {
575
+ "when_match" : True ,
576
+ "conditions" : [
577
+ {
578
+ "action" : RuleAction .VALUE_NOT_IN_KEY .value ,
579
+ "key" : "groups" ,
580
+ "value" : "SYSADMIN" ,
581
+ }
582
+ ],
583
+ }
584
+ },
585
+ }
586
+ }
587
+ feature_flags = init_feature_flags (mocker , mocked_app_config_schema , config )
588
+ toggle = feature_flags .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "a" , "groups" : ["SYSADMIN" , "IT" ]}, default = False )
589
+ assert toggle == expected_value
590
+
591
+
398
592
399
593
594
+ # Check multiple features
400
595
def test_multiple_features_enabled (mocker , config ):
401
596
expected_value = ["my_feature" , "my_feature2" ]
402
597
mocked_app_config_schema = {
0 commit comments