@@ -172,6 +172,7 @@ def test_init__with_v4_datafile(self):
172172 'revision' : '42' ,
173173 'version' : '4' ,
174174 'anonymizeIP' : False ,
175+ 'botFiltering' : True ,
175176 'events' : [{
176177 'key' : 'test_event' ,
177178 'experimentIds' : ['111127' ],
@@ -387,6 +388,7 @@ def test_init__with_v4_datafile(self):
387388 self .assertEqual (config_dict ['revision' ], project_config .revision )
388389 self .assertEqual (config_dict ['experiments' ], project_config .experiments )
389390 self .assertEqual (config_dict ['events' ], project_config .events )
391+ self .assertEqual (config_dict ['botFiltering' ], project_config .bot_filtering )
390392
391393 expected_group_id_map = {
392394 '19228' : entities .Group (
@@ -679,6 +681,21 @@ def test_get_project_id(self):
679681
680682 self .assertEqual (self .config_dict ['projectId' ], self .project_config .get_project_id ())
681683
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+
682699 def test_get_experiment_from_key__valid_key (self ):
683700 """ Test that experiment is retrieved correctly for valid experiment key. """
684701
@@ -787,16 +804,27 @@ def test_get_event__invalid_key(self):
787804
788805 self .assertIsNone (self .project_config .get_event ('invalid_key' ))
789806
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. """
792809
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' ))
795812
796- def test_get_attribute__invalid_key (self ):
813+ def test_get_attribute_id__invalid_key (self ):
797814 """ Test that None is returned when provided attribute key is invalid. """
798815
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' ))
800828
801829 def test_get_group__valid_id (self ):
802830 """ 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):
10741102
10751103
10761104class ConfigLoggingTest (base .BaseTest ):
1105+
10771106 def setUp (self ):
10781107 base .BaseTest .setUp (self )
10791108 self .optimizely = optimizely .Optimizely (json .dumps (self .config_dict ),
@@ -1136,14 +1165,25 @@ def test_get_event__invalid_key(self):
11361165
11371166 mock_config_logging .error .assert_called_once_with ('Event "invalid_key" is not in datafile.' )
11381167
1139- def test_get_attribute__invalid_key (self ):
1168+ def test_get_attribute_id__invalid_key (self ):
11401169 """ Test that message is logged when provided attribute key is invalid. """
11411170
11421171 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' )
11441173
11451174 mock_config_logging .error .assert_called_once_with ('Attribute "invalid_key" is not in datafile.' )
11461175
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+
11471187 def test_get_group__invalid_id (self ):
11481188 """ Test that message is logged when provided group ID is invalid. """
11491189
@@ -1210,12 +1250,12 @@ def test_get_event__invalid_key(self):
12101250 enums .Errors .INVALID_EVENT_KEY_ERROR ,
12111251 self .project_config .get_event , 'invalid_key' )
12121252
1213- def test_get_attribute__invalid_key (self ):
1253+ def test_get_attribute_id__invalid_key (self ):
12141254 """ Test that exception is raised when provided attribute key is invalid. """
12151255
12161256 self .assertRaisesRegexp (exceptions .InvalidAttributeException ,
12171257 enums .Errors .INVALID_ATTRIBUTE_ERROR ,
1218- self .project_config .get_attribute , 'invalid_key' )
1258+ self .project_config .get_attribute_id , 'invalid_key' )
12191259
12201260 def test_get_group__invalid_id (self ):
12211261 """ Test that exception is raised when provided group ID is invalid. """
0 commit comments