@@ -172,6 +172,7 @@ def test_init__with_v4_datafile(self):
172
172
'revision' : '42' ,
173
173
'version' : '4' ,
174
174
'anonymizeIP' : False ,
175
+ 'botFiltering' : True ,
175
176
'events' : [{
176
177
'key' : 'test_event' ,
177
178
'experimentIds' : ['111127' ],
@@ -387,6 +388,7 @@ def test_init__with_v4_datafile(self):
387
388
self .assertEqual (config_dict ['revision' ], project_config .revision )
388
389
self .assertEqual (config_dict ['experiments' ], project_config .experiments )
389
390
self .assertEqual (config_dict ['events' ], project_config .events )
391
+ self .assertEqual (config_dict ['botFiltering' ], project_config .bot_filtering )
390
392
391
393
expected_group_id_map = {
392
394
'19228' : entities .Group (
@@ -679,6 +681,21 @@ def test_get_project_id(self):
679
681
680
682
self .assertEqual (self .config_dict ['projectId' ], self .project_config .get_project_id ())
681
683
684
+ def test_get_bot_filtering (self ):
685
+ """ Test that bot filtering is retrieved correctly when using get_bot_filtering_value. """
686
+
687
+ # Assert bot filtering is None when not provided in data file
688
+ self .assertTrue ('botFiltering' not in self .config_dict )
689
+ self .assertIsNone (self .project_config .get_bot_filtering_value ())
690
+
691
+ # Assert bot filtering is retrieved as provided in the data file
692
+ opt_obj = optimizely .Optimizely (json .dumps (self .config_dict_with_features ))
693
+ project_config = opt_obj .config
694
+ self .assertEqual (
695
+ self .config_dict_with_features ['botFiltering' ],
696
+ project_config .get_bot_filtering_value ()
697
+ )
698
+
682
699
def test_get_experiment_from_key__valid_key (self ):
683
700
""" Test that experiment is retrieved correctly for valid experiment key. """
684
701
@@ -787,16 +804,27 @@ def test_get_event__invalid_key(self):
787
804
788
805
self .assertIsNone (self .project_config .get_event ('invalid_key' ))
789
806
790
- def test_get_attribute__valid_key (self ):
791
- """ Test that attribute is retrieved correctly for valid attribute key. """
807
+ def test_get_attribute_id__valid_key (self ):
808
+ """ Test that attribute ID is retrieved correctly for valid attribute key. """
792
809
793
- self .assertEqual (entities . Attribute ( '111094' , 'test_attribute' ) ,
794
- self .project_config .get_attribute ('test_attribute' ))
810
+ self .assertEqual ('111094' ,
811
+ self .project_config .get_attribute_id ('test_attribute' ))
795
812
796
- def test_get_attribute__invalid_key (self ):
813
+ def test_get_attribute_id__invalid_key (self ):
797
814
""" Test that None is returned when provided attribute key is invalid. """
798
815
799
- self .assertIsNone (self .project_config .get_attribute ('invalid_key' ))
816
+ self .assertIsNone (self .project_config .get_attribute_id ('invalid_key' ))
817
+
818
+ def test_get_attribute_id__reserved_key (self ):
819
+ """ Test that Attribute Key is returned as ID when provided attribute key is reserved key. """
820
+ self .assertEqual ('$opt_user_agent' ,
821
+ self .project_config .get_attribute_id ('$opt_user_agent' ))
822
+
823
+ def test_get_attribute_id__unknown_key_with_opt_prefix (self ):
824
+ """ Test that Attribute Key is returned as ID when provided attribute key is not
825
+ present in the datafile but has $opt prefix. """
826
+ self .assertEqual ('$opt_interesting' ,
827
+ self .project_config .get_attribute_id ('$opt_interesting' ))
800
828
801
829
def test_get_group__valid_id (self ):
802
830
""" Test that group is retrieved correctly for valid group ID. """
@@ -1074,6 +1102,7 @@ def test_set_forced_variation_when_called_to_remove_forced_variation(self):
1074
1102
1075
1103
1076
1104
class ConfigLoggingTest (base .BaseTest ):
1105
+
1077
1106
def setUp (self ):
1078
1107
base .BaseTest .setUp (self )
1079
1108
self .optimizely = optimizely .Optimizely (json .dumps (self .config_dict ),
@@ -1136,14 +1165,25 @@ def test_get_event__invalid_key(self):
1136
1165
1137
1166
mock_config_logging .error .assert_called_once_with ('Event "invalid_key" is not in datafile.' )
1138
1167
1139
- def test_get_attribute__invalid_key (self ):
1168
+ def test_get_attribute_id__invalid_key (self ):
1140
1169
""" Test that message is logged when provided attribute key is invalid. """
1141
1170
1142
1171
with mock .patch .object (self .project_config , 'logger' ) as mock_config_logging :
1143
- self .project_config .get_attribute ('invalid_key' )
1172
+ self .project_config .get_attribute_id ('invalid_key' )
1144
1173
1145
1174
mock_config_logging .error .assert_called_once_with ('Attribute "invalid_key" is not in datafile.' )
1146
1175
1176
+ def test_get_attribute_id__key_with_opt_prefix_but_not_a_control_attribute (self ):
1177
+ """ Test that message is logged when provided attribute key has $opt_ in prefix and
1178
+ key is not one of the control attributes. """
1179
+ self .project_config .attribute_key_map ['$opt_abc' ] = entities .Attribute ('007' , '$opt_abc' )
1180
+
1181
+ with mock .patch .object (self .project_config , 'logger' ) as mock_config_logging :
1182
+ self .project_config .get_attribute_id ('$opt_abc' )
1183
+
1184
+ mock_config_logging .warning .assert_called_once_with (("Attribute $opt_abc unexpectedly has reserved prefix $opt_; "
1185
+ "using attribute ID instead of reserved attribute name." ))
1186
+
1147
1187
def test_get_group__invalid_id (self ):
1148
1188
""" Test that message is logged when provided group ID is invalid. """
1149
1189
@@ -1210,12 +1250,12 @@ def test_get_event__invalid_key(self):
1210
1250
enums .Errors .INVALID_EVENT_KEY_ERROR ,
1211
1251
self .project_config .get_event , 'invalid_key' )
1212
1252
1213
- def test_get_attribute__invalid_key (self ):
1253
+ def test_get_attribute_id__invalid_key (self ):
1214
1254
""" Test that exception is raised when provided attribute key is invalid. """
1215
1255
1216
1256
self .assertRaisesRegexp (exceptions .InvalidAttributeException ,
1217
1257
enums .Errors .INVALID_ATTRIBUTE_ERROR ,
1218
- self .project_config .get_attribute , 'invalid_key' )
1258
+ self .project_config .get_attribute_id , 'invalid_key' )
1219
1259
1220
1260
def test_get_group__invalid_id (self ):
1221
1261
""" Test that exception is raised when provided group ID is invalid. """
0 commit comments