1
- # Copyright 2016-2017 , Optimizely
1
+ # Copyright 2016-2018 , Optimizely
2
2
# Licensed under the Apache License, Version 2.0 (the "License");
3
3
# you may not use this file except in compliance with the License.
4
4
# You may obtain a copy of the License at
@@ -226,13 +226,15 @@ def test_init__with_v3_datafile(self):
226
226
'variations' : [{
227
227
'key' : 'control' ,
228
228
'id' : '111128' ,
229
+ 'featureEnabled' : False ,
229
230
'variables' : [{
230
231
'id' : '127' ,
231
232
'value' : 'false'
232
233
}]
233
234
}, {
234
235
'key' : 'variation' ,
235
236
'id' : '111129' ,
237
+ 'featureEnabled' : False ,
236
238
'variables' : [{
237
239
'id' : '127' ,
238
240
'value' : 'true'
@@ -251,6 +253,7 @@ def test_init__with_v3_datafile(self):
251
253
'variations' : [{
252
254
'key' : 'group_exp_1_control' ,
253
255
'id' : '28901' ,
256
+ 'featureEnabled' : False ,
254
257
'variables' : [{
255
258
'id' : '128' ,
256
259
'value' : 'prod'
@@ -264,6 +267,7 @@ def test_init__with_v3_datafile(self):
264
267
}, {
265
268
'key' : 'group_exp_1_variation' ,
266
269
'id' : '28902' ,
270
+ 'featureEnabled' : False ,
267
271
'variables' : [{
268
272
'id' : '128' ,
269
273
'value' : 'stage'
@@ -295,10 +299,12 @@ def test_init__with_v3_datafile(self):
295
299
'variations' : [{
296
300
'key' : 'group_exp_2_control' ,
297
301
'id' : '28905' ,
302
+ 'featureEnabled' : False ,
298
303
'variables' : []
299
304
}, {
300
305
'key' : 'group_exp_2_variation' ,
301
306
'id' : '28906' ,
307
+ 'featureEnabled' : False ,
302
308
'variables' : []
303
309
}],
304
310
'forcedVariations' : {
@@ -356,13 +362,15 @@ def test_init__with_v3_datafile(self):
356
362
'111127' , 'test_experiment' , 'Running' , ['11154' ], [{
357
363
'key' : 'control' ,
358
364
'id' : '111128' ,
365
+ 'featureEnabled' : False ,
359
366
'variables' : [{
360
367
'id' : '127' ,
361
368
'value' : 'false'
362
369
}]
363
370
}, {
364
371
'key' : 'variation' ,
365
372
'id' : '111129' ,
373
+ 'featureEnabled' : False ,
366
374
'variables' : [{
367
375
'id' : '127' ,
368
376
'value' : 'true'
@@ -385,6 +393,7 @@ def test_init__with_v3_datafile(self):
385
393
'32222' , 'group_exp_1' , 'Running' , [], [{
386
394
'key' : 'group_exp_1_control' ,
387
395
'id' : '28901' ,
396
+ 'featureEnabled' : False ,
388
397
'variables' : [{
389
398
'id' : '128' ,
390
399
'value' : 'prod'
@@ -398,6 +407,7 @@ def test_init__with_v3_datafile(self):
398
407
}, {
399
408
'key' : 'group_exp_1_variation' ,
400
409
'id' : '28902' ,
410
+ 'featureEnabled' : False ,
401
411
'variables' : [{
402
412
'id' : '128' ,
403
413
'value' : 'stage'
@@ -423,10 +433,12 @@ def test_init__with_v3_datafile(self):
423
433
'32223' , 'group_exp_2' , 'Running' , [], [{
424
434
'key' : 'group_exp_2_control' ,
425
435
'id' : '28905' ,
436
+ 'featureEnabled' : False ,
426
437
'variables' : []
427
438
}, {
428
439
'key' : 'group_exp_2_variation' ,
429
440
'id' : '28906' ,
441
+ 'featureEnabled' : False ,
430
442
'variables' : []
431
443
}], {
432
444
'user_1' : 'group_exp_2_control' ,
@@ -462,15 +474,15 @@ def test_init__with_v3_datafile(self):
462
474
}
463
475
expected_variation_key_map = {
464
476
'test_experiment' : {
465
- 'control' : entities .Variation ('111128' , 'control' , [{'id' : '127' , 'value' : 'false' }]),
466
- 'variation' : entities .Variation ('111129' , 'variation' , [{'id' : '127' , 'value' : 'true' }])
477
+ 'control' : entities .Variation ('111128' , 'control' , False , [{'id' : '127' , 'value' : 'false' }]),
478
+ 'variation' : entities .Variation ('111129' , 'variation' , False , [{'id' : '127' , 'value' : 'true' }])
467
479
},
468
480
'group_exp_1' : {
469
481
'group_exp_1_control' : entities .Variation (
470
- '28901' , 'group_exp_1_control' , [
482
+ '28901' , 'group_exp_1_control' , False , [
471
483
{'id' : '128' , 'value' : 'prod' }, {'id' : '129' , 'value' : '1772' }, {'id' : '130' , 'value' : '1.22992' }]),
472
484
'group_exp_1_variation' : entities .Variation (
473
- '28902' , 'group_exp_1_variation' , [
485
+ '28902' , 'group_exp_1_variation' , False , [
474
486
{'id' : '128' , 'value' : 'stage' }, {'id' : '129' , 'value' : '112' }, {'id' : '130' , 'value' : '1.211' }])
475
487
},
476
488
'group_exp_2' : {
@@ -480,13 +492,13 @@ def test_init__with_v3_datafile(self):
480
492
}
481
493
expected_variation_id_map = {
482
494
'test_experiment' : {
483
- '111128' : entities .Variation ('111128' , 'control' , [{'id' : '127' , 'value' : 'false' }]),
484
- '111129' : entities .Variation ('111129' , 'variation' , [{'id' : '127' , 'value' : 'true' }])
495
+ '111128' : entities .Variation ('111128' , 'control' , False , [{'id' : '127' , 'value' : 'false' }]),
496
+ '111129' : entities .Variation ('111129' , 'variation' , False , [{'id' : '127' , 'value' : 'true' }])
485
497
},
486
498
'group_exp_1' : {
487
- '28901' : entities .Variation ('28901' , 'group_exp_1_control' , [
499
+ '28901' : entities .Variation ('28901' , 'group_exp_1_control' , False , [
488
500
{'id' : '128' , 'value' : 'prod' }, {'id' : '129' , 'value' : '1772' }, {'id' : '130' , 'value' : '1.22992' }]),
489
- '28902' : entities .Variation ('28902' , 'group_exp_1_variation' , [
501
+ '28902' : entities .Variation ('28902' , 'group_exp_1_variation' , False , [
490
502
{'id' : '128' , 'value' : 'stage' }, {'id' : '129' , 'value' : '112' }, {'id' : '130' , 'value' : '1.211' }])
491
503
},
492
504
'group_exp_2' : {
@@ -861,42 +873,42 @@ def test_init__with_v4_datafile(self):
861
873
}
862
874
expected_variation_key_map = {
863
875
'test_experiment' : {
864
- 'control' : entities .Variation ('111128' , 'control' , [{'id' : '127' , 'value' : 'false' }]),
865
- 'variation' : entities .Variation ('111129' , 'variation' , [{'id' : '127' , 'value' : 'true' }])
876
+ 'control' : entities .Variation ('111128' , 'control' , False , [{'id' : '127' , 'value' : 'false' }]),
877
+ 'variation' : entities .Variation ('111129' , 'variation' , False , [{'id' : '127' , 'value' : 'true' }])
866
878
},
867
879
'group_exp_1' : {
868
880
'group_exp_1_control' : entities .Variation (
869
- '28901' , 'group_exp_1_control' , [
881
+ '28901' , 'group_exp_1_control' , False , [
870
882
{'id' : '128' , 'value' : 'prod' }, {'id' : '129' , 'value' : '1772' }, {'id' : '130' , 'value' : '1.22992' }]),
871
883
'group_exp_1_variation' : entities .Variation (
872
- '28902' , 'group_exp_1_variation' , [
884
+ '28902' , 'group_exp_1_variation' , False , [
873
885
{'id' : '128' , 'value' : 'stage' }, {'id' : '129' , 'value' : '112' }, {'id' : '130' , 'value' : '1.211' }])
874
886
},
875
887
'group_exp_2' : {
876
888
'group_exp_2_control' : entities .Variation ('28905' , 'group_exp_2_control' ),
877
889
'group_exp_2_variation' : entities .Variation ('28906' , 'group_exp_2_variation' )
878
890
},
879
891
'211112' : {
880
- '211113' : entities .Variation ('211113' , '211113' , [{'id' : '131' , 'value' : '15' }])
892
+ '211113' : entities .Variation ('211113' , '211113' , False , [{'id' : '131' , 'value' : '15' }])
881
893
}
882
894
}
883
895
expected_variation_id_map = {
884
896
'test_experiment' : {
885
- '111128' : entities .Variation ('111128' , 'control' , [{'id' : '127' , 'value' : 'false' }]),
886
- '111129' : entities .Variation ('111129' , 'variation' , [{'id' : '127' , 'value' : 'true' }])
897
+ '111128' : entities .Variation ('111128' , 'control' , False , [{'id' : '127' , 'value' : 'false' }]),
898
+ '111129' : entities .Variation ('111129' , 'variation' , False , [{'id' : '127' , 'value' : 'true' }])
887
899
},
888
900
'group_exp_1' : {
889
- '28901' : entities .Variation ('28901' , 'group_exp_1_control' , [
901
+ '28901' : entities .Variation ('28901' , 'group_exp_1_control' , False , [
890
902
{'id' : '128' , 'value' : 'prod' }, {'id' : '129' , 'value' : '1772' }, {'id' : '130' , 'value' : '1.22992' }]),
891
- '28902' : entities .Variation ('28902' , 'group_exp_1_variation' , [
903
+ '28902' : entities .Variation ('28902' , 'group_exp_1_variation' , False , [
892
904
{'id' : '128' , 'value' : 'stage' }, {'id' : '129' , 'value' : '112' }, {'id' : '130' , 'value' : '1.211' }])
893
905
},
894
906
'group_exp_2' : {
895
907
'28905' : entities .Variation ('28905' , 'group_exp_2_control' ),
896
908
'28906' : entities .Variation ('28906' , 'group_exp_2_variation' )
897
909
},
898
910
'211112' : {
899
- '211113' : entities .Variation ('211113' , '211113' , [{'id' : '131' , 'value' : '15' }])
911
+ '211113' : entities .Variation ('211113' , '211113' , False , [{'id' : '131' , 'value' : '15' }])
900
912
}
901
913
}
902
914
@@ -973,6 +985,30 @@ def test_init__with_v4_datafile(self):
973
985
self .assertEqual (expected_rollout_id_map , project_config .rollout_id_map )
974
986
self .assertEqual (expected_variation_variable_usage_map , project_config .variation_variable_usage_map )
975
987
988
+ def test_variation_has_featureEnabled_false_if_prop_undefined (self ):
989
+ """ Test that featureEnabled property by default is set to False, when not given in the data file"""
990
+ variation = {
991
+ 'key' : 'group_exp_1_variation' ,
992
+ 'id' : '28902' ,
993
+ 'variables' : [{
994
+ 'id' : '128' ,
995
+ 'value' : 'stage'
996
+ }, {
997
+ 'id' : '129' ,
998
+ 'value' : '112'
999
+ }, {
1000
+ 'id' : '130' ,
1001
+ 'value' : '1.211'
1002
+ }]
1003
+ }
1004
+
1005
+ variation_entity = entities .Variation (** variation )
1006
+
1007
+ self .assertEqual (variation ['id' ], variation_entity .id )
1008
+ self .assertEqual (variation ['key' ], variation_entity .key )
1009
+ self .assertEqual (variation ['variables' ], variation_entity .variables )
1010
+ self .assertFalse (variation_entity .featureEnabled )
1011
+
976
1012
def test_get_version (self ):
977
1013
""" Test that JSON version is retrieved correctly when using get_version. """
978
1014
@@ -1161,7 +1197,8 @@ def test_get_rollout_from_id__valid_rollout_id(self):
1161
1197
}],
1162
1198
'variations' : [{
1163
1199
'key' : '211129' ,
1164
- 'id' : '211129'
1200
+ 'id' : '211129' ,
1201
+ 'featureEnabled' : True
1165
1202
}]
1166
1203
}, {
1167
1204
'id' : '211137' ,
@@ -1176,7 +1213,8 @@ def test_get_rollout_from_id__valid_rollout_id(self):
1176
1213
}],
1177
1214
'variations' : [{
1178
1215
'key' : '211139' ,
1179
- 'id' : '211139'
1216
+ 'id' : '211139' ,
1217
+ 'featureEnabled' : True
1180
1218
}]
1181
1219
}, {
1182
1220
'id' : '211147' ,
@@ -1191,7 +1229,8 @@ def test_get_rollout_from_id__valid_rollout_id(self):
1191
1229
}],
1192
1230
'variations' : [{
1193
1231
'key' : '211149' ,
1194
- 'id' : '211149'
1232
+ 'id' : '211149' ,
1233
+ 'featureEnabled' : True
1195
1234
}]
1196
1235
}])
1197
1236
self .assertEqual (expected_rollout , project_config .get_rollout_from_id ('211111' ))
0 commit comments