@@ -50,9 +50,8 @@ def test_toggles_rule_does_not_match(mocker, config):
50
50
"features" : {
51
51
"my_feature" : {
52
52
"default" : expected_value ,
53
- "rules" : [
54
- {
55
- "rule_name" : "tenant id equals 345345435" ,
53
+ "rules" : {
54
+ "tenant id equals 345345435" : {
56
55
"when_match" : False ,
57
56
"conditions" : [
58
57
{
@@ -61,10 +60,10 @@ def test_toggles_rule_does_not_match(mocker, config):
61
60
"value" : "345345435" ,
62
61
}
63
62
],
64
- },
65
- ] ,
63
+ }
64
+ } ,
66
65
}
67
- },
66
+ }
68
67
}
69
68
70
69
conf_store = init_configuration_store (mocker , mocked_app_config_schema , config )
@@ -100,9 +99,8 @@ def test_toggles_conditions_no_match(mocker, config):
100
99
"features" : {
101
100
"my_feature" : {
102
101
"default" : expected_value ,
103
- "rules" : [
104
- {
105
- "rule_name" : "tenant id equals 345345435" ,
102
+ "rules" : {
103
+ "tenant id equals 345345435" : {
106
104
"when_match" : False ,
107
105
"conditions" : [
108
106
{
@@ -111,10 +109,10 @@ def test_toggles_conditions_no_match(mocker, config):
111
109
"value" : "345345435" ,
112
110
}
113
111
],
114
- },
115
- ] ,
112
+ }
113
+ } ,
116
114
}
117
- },
115
+ }
118
116
}
119
117
conf_store = init_configuration_store (mocker , mocked_app_config_schema , config )
120
118
toggle = conf_store .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "a" }, default = False )
@@ -130,9 +128,8 @@ def test_toggles_conditions_rule_match_equal_multiple_conditions(mocker, config)
130
128
"features" : {
131
129
"my_feature" : {
132
130
"default" : True ,
133
- "rules" : [
134
- {
135
- "rule_name" : "tenant id equals 6 and username is a" ,
131
+ "rules" : {
132
+ "tenant id equals 6 and username is a" : {
136
133
"when_match" : expected_value ,
137
134
"conditions" : [
138
135
{
@@ -146,8 +143,8 @@ def test_toggles_conditions_rule_match_equal_multiple_conditions(mocker, config)
146
143
"value" : username_val ,
147
144
},
148
145
],
149
- },
150
- ] ,
146
+ }
147
+ } ,
151
148
}
152
149
},
153
150
}
@@ -172,9 +169,9 @@ def test_toggles_conditions_no_rule_match_equal_multiple_conditions(mocker, conf
172
169
"features" : {
173
170
"my_feature" : {
174
171
"default" : expected_val ,
175
- "rules" : [
176
- {
177
- "rule_name" : " tenant id equals 645654 and username is a", # rule will not match
172
+ "rules" : {
173
+ # rule will not match
174
+ " tenant id equals 645654 and username is a": {
178
175
"when_match" : False ,
179
176
"conditions" : [
180
177
{
@@ -188,10 +185,10 @@ def test_toggles_conditions_no_rule_match_equal_multiple_conditions(mocker, conf
188
185
"value" : "a" ,
189
186
},
190
187
],
191
- },
192
- ] ,
188
+ }
189
+ } ,
193
190
}
194
- },
191
+ }
195
192
}
196
193
conf_store = init_configuration_store (mocker , mocked_app_config_schema , config )
197
194
toggle = conf_store .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "a" }, default = False )
@@ -208,9 +205,8 @@ def test_toggles_conditions_rule_match_multiple_actions_multiple_rules_multiple_
208
205
"features" : {
209
206
"my_feature" : {
210
207
"default" : expected_value_third_check ,
211
- "rules" : [
212
- {
213
- "rule_name" : "tenant id equals 6 and username startswith a" ,
208
+ "rules" : {
209
+ "tenant id equals 6 and username startswith a" : {
214
210
"when_match" : expected_value_first_check ,
215
211
"conditions" : [
216
212
{
@@ -225,8 +221,7 @@ def test_toggles_conditions_rule_match_multiple_actions_multiple_rules_multiple_
225
221
},
226
222
],
227
223
},
228
- {
229
- "rule_name" : "tenant id equals 4446 and username startswith a and endswith z" ,
224
+ "tenant id equals 4446 and username startswith a and endswith z" : {
230
225
"when_match" : expected_value_second_check ,
231
226
"conditions" : [
232
227
{
@@ -246,9 +241,9 @@ def test_toggles_conditions_rule_match_multiple_actions_multiple_rules_multiple_
246
241
},
247
242
],
248
243
},
249
- ] ,
244
+ } ,
250
245
}
251
- },
246
+ }
252
247
}
253
248
254
249
conf_store = init_configuration_store (mocker , mocked_app_config_schema , config )
@@ -277,9 +272,8 @@ def test_toggles_match_rule_with_contains_action(mocker, config):
277
272
"features" : {
278
273
"my_feature" : {
279
274
"default" : False ,
280
- "rules" : [
281
- {
282
- "rule_name" : "tenant id is contained in [6, 2]" ,
275
+ "rules" : {
276
+ "tenant id is contained in [6, 2]" : {
283
277
"when_match" : expected_value ,
284
278
"conditions" : [
285
279
{
@@ -288,10 +282,10 @@ def test_toggles_match_rule_with_contains_action(mocker, config):
288
282
"value" : ["6" , "2" ],
289
283
}
290
284
],
291
- },
292
- ] ,
285
+ }
286
+ } ,
293
287
}
294
- },
288
+ }
295
289
}
296
290
conf_store = init_configuration_store (mocker , mocked_app_config_schema , config )
297
291
toggle = conf_store .evaluate (name = "my_feature" , context = {"tenant_id" : "6" , "username" : "a" }, default = False )
@@ -331,9 +325,8 @@ def test_multiple_features_enabled(mocker, config):
331
325
"features" : {
332
326
"my_feature" : {
333
327
"default" : False ,
334
- "rules" : [
335
- {
336
- "rule_name" : "tenant id is contained in [6, 2]" ,
328
+ "rules" : {
329
+ "tenant id is contained in [6, 2]" : {
337
330
"when_match" : True ,
338
331
"conditions" : [
339
332
{
@@ -342,16 +335,16 @@ def test_multiple_features_enabled(mocker, config):
342
335
"value" : ["6" , "2" ],
343
336
}
344
337
],
345
- },
346
- ] ,
338
+ }
339
+ } ,
347
340
},
348
341
"my_feature2" : {
349
342
"default" : True ,
350
343
},
351
344
"my_feature3" : {
352
345
"default" : False ,
353
346
},
354
- },
347
+ }
355
348
}
356
349
conf_store = init_configuration_store (mocker , mocked_app_config_schema , config )
357
350
enabled_list : List [str ] = conf_store .get_enabled_features (context = {"tenant_id" : "6" , "username" : "a" })
@@ -364,9 +357,8 @@ def test_multiple_features_only_some_enabled(mocker, config):
364
357
"features" : {
365
358
"my_feature" : { # rule will match here, feature is enabled due to rule match
366
359
"default" : False ,
367
- "rules" : [
368
- {
369
- "rule_name" : "tenant id is contained in [6, 2]" ,
360
+ "rules" : {
361
+ "tenant id is contained in [6, 2]" : {
370
362
"when_match" : True ,
371
363
"conditions" : [
372
364
{
@@ -375,20 +367,20 @@ def test_multiple_features_only_some_enabled(mocker, config):
375
367
"value" : ["6" , "2" ],
376
368
}
377
369
],
378
- },
379
- ] ,
370
+ }
371
+ } ,
380
372
},
381
373
"my_feature2" : {
382
374
"default" : True ,
383
375
},
384
376
"my_feature3" : {
385
377
"default" : False ,
386
378
},
387
- "my_feature4" : { # rule will not match here, feature is enabled by default
379
+ # rule will not match here, feature is enabled by default
380
+ "my_feature4" : {
388
381
"default" : True ,
389
- "rules" : [
390
- {
391
- "rule_name" : "tenant id equals 7" ,
382
+ "rules" : {
383
+ "tenant id equals 7" : {
392
384
"when_match" : False ,
393
385
"conditions" : [
394
386
{
@@ -397,10 +389,10 @@ def test_multiple_features_only_some_enabled(mocker, config):
397
389
"value" : "7" ,
398
390
}
399
391
],
400
- },
401
- ] ,
392
+ }
393
+ } ,
402
394
},
403
- },
395
+ }
404
396
}
405
397
conf_store = init_configuration_store (mocker , mocked_app_config_schema , config )
406
398
enabled_list : List [str ] = conf_store .get_enabled_features (context = {"tenant_id" : "6" , "username" : "a" })
@@ -468,7 +460,7 @@ def test_is_rule_matched_no_matches(mocker, config):
468
460
conf_store = init_configuration_store (mocker , {}, config )
469
461
470
462
# WHEN calling _is_rule_matched
471
- result = conf_store ._is_rule_matched ("name " , rule , rules_context )
463
+ result = conf_store ._is_rule_matched (rule_name = "dummy " , feature_name = "dummy" , rule = rule , context = rules_context )
472
464
473
465
# THEN return False
474
466
assert result is False
0 commit comments