@@ -365,6 +365,7 @@ def test_activate(self):
365365 'enrich_decisions' : True ,
366366 'anonymize_ip' : False ,
367367 'revision' : '42' ,
368+ 'region' : 'US' ,
368369 }
369370
370371 log_event = EventFactory .create_log_event (mock_process .call_args [0 ][0 ], self .optimizely .logger )
@@ -385,6 +386,76 @@ def test_activate(self):
385386 {'Content-Type' : 'application/json' },
386387 )
387388
389+ def test_activate_with_eu_hosting (self ):
390+ """ Test that activate calls process with right params and returns expected variation. """
391+ """ Test EU hosting for activate method. """
392+
393+ with mock .patch (
394+ 'optimizely.decision_service.DecisionService.get_variation' ,
395+ return_value = (self .project_config .get_variation_from_id ('test_experiment' , '111129' ), []),
396+ ) as mock_decision , mock .patch ('time.time' , return_value = 42 ), mock .patch (
397+ 'uuid.uuid4' , return_value = 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c'
398+ ), mock .patch (
399+ 'optimizely.event.event_processor.BatchEventProcessor.process'
400+ ) as mock_process :
401+ self .assertEqual ('variation' , self .optimizely .activate ('test_experiment' , 'test_user' ))
402+
403+ expected_params = {
404+ 'account_id' : '12001' ,
405+ 'project_id' : '111001' ,
406+ 'visitors' : [
407+ {
408+ 'visitor_id' : 'test_user' ,
409+ 'attributes' : [],
410+ 'snapshots' : [
411+ {
412+ 'decisions' : [
413+ {'variation_id' : '111129' , 'experiment_id' : '111127' , 'campaign_id' : '111182' ,
414+ 'metadata' : {'flag_key' : '' ,
415+ 'rule_key' : 'test_experiment' ,
416+ 'rule_type' : 'experiment' ,
417+ 'variation_key' : 'variation' ,
418+ 'enabled' : True },
419+ }
420+ ],
421+ 'events' : [
422+ {
423+ 'timestamp' : 42000 ,
424+ 'entity_id' : '111182' ,
425+ 'uuid' : 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c' ,
426+ 'key' : 'campaign_activated' ,
427+ }
428+ ],
429+ }
430+ ],
431+ }
432+ ],
433+ 'client_version' : version .__version__ ,
434+ 'client_name' : 'python-sdk' ,
435+ 'enrich_decisions' : True ,
436+ 'anonymize_ip' : False ,
437+ 'revision' : '42' ,
438+ 'region' : 'EU' ,
439+ }
440+
441+ log_event = EventFactory .create_log_event (mock_process .call_args [0 ][0 ], self .optimizely .logger )
442+ user_context = mock_decision .call_args [0 ][2 ]
443+ user_profile_tracker = mock_decision .call_args [0 ][3 ]
444+
445+ mock_decision .assert_called_once_with (
446+ self .project_config , self .project_config .get_experiment_from_key ('test_experiment' ),
447+ user_context , user_profile_tracker
448+ )
449+ self .assertEqual (1 , mock_process .call_count )
450+
451+ self ._validate_event_object (
452+ log_event .__dict__ ,
453+ 'https://eu.logx.optimizely.com/v1/events' ,
454+ expected_params ,
455+ 'POST' ,
456+ {'Content-Type' : 'application/json' },
457+ )
458+
388459 def test_add_activate_remove_clear_listener (self ):
389460 callbackhit = [False ]
390461 """ Test adding a listener activate passes correctly and gets called"""
@@ -764,6 +835,7 @@ def test_activate__with_attributes__audience_match(self):
764835 'enrich_decisions' : True ,
765836 'anonymize_ip' : False ,
766837 'revision' : '42' ,
838+ 'region' : 'US' ,
767839 }
768840
769841 log_event = EventFactory .create_log_event (mock_process .call_args [0 ][0 ], self .optimizely .logger )
@@ -848,6 +920,7 @@ def test_activate__with_attributes_of_different_types(self):
848920 'enrich_decisions' : True ,
849921 'anonymize_ip' : False ,
850922 'revision' : '42' ,
923+ 'region' : 'US' ,
851924 }
852925
853926 log_event = EventFactory .create_log_event (mock_process .call_args [0 ][0 ], self .optimizely .logger )
@@ -1044,6 +1117,7 @@ def test_activate__with_attributes__audience_match__forced_bucketing(self):
10441117 'enrich_decisions' : True ,
10451118 'anonymize_ip' : False ,
10461119 'revision' : '42' ,
1120+ 'region' : 'US' ,
10471121 }
10481122
10491123 log_event = EventFactory .create_log_event (mock_process .call_args [0 ][0 ], self .optimizely .logger )
@@ -1120,6 +1194,7 @@ def test_activate__with_attributes__audience_match__bucketing_id_provided(self):
11201194 'enrich_decisions' : True ,
11211195 'anonymize_ip' : False ,
11221196 'revision' : '42' ,
1197+ 'region' : 'US' ,
11231198 }
11241199
11251200 log_event = EventFactory .create_log_event (mock_process .call_args [0 ][0 ], self .optimizely .logger )
@@ -1288,6 +1363,7 @@ def test_track__with_attributes(self):
12881363 'enrich_decisions' : True ,
12891364 'anonymize_ip' : False ,
12901365 'revision' : '42' ,
1366+ 'region' : 'US' ,
12911367 }
12921368
12931369 log_event = EventFactory .create_log_event (mock_process .call_args [0 ][0 ], self .optimizely .logger )
@@ -1424,6 +1500,7 @@ def test_track__with_attributes__bucketing_id_provided(self):
14241500 'enrich_decisions' : True ,
14251501 'anonymize_ip' : False ,
14261502 'revision' : '42' ,
1503+ 'region' : 'US' ,
14271504 }
14281505
14291506 log_event = EventFactory .create_log_event (mock_process .call_args [0 ][0 ], self .optimizely .logger )
@@ -1504,6 +1581,7 @@ def test_track__with_event_tags(self):
15041581 'enrich_decisions' : True ,
15051582 'anonymize_ip' : False ,
15061583 'revision' : '42' ,
1584+ 'region' : 'US' ,
15071585 }
15081586 log_event = EventFactory .create_log_event (mock_process .call_args [0 ][0 ], self .optimizely .logger )
15091587
@@ -1560,6 +1638,7 @@ def test_track__with_event_tags_revenue(self):
15601638 'account_id' : '12001' ,
15611639 'anonymize_ip' : False ,
15621640 'revision' : '42' ,
1641+ 'region' : 'US' ,
15631642 }
15641643
15651644 log_event = EventFactory .create_log_event (mock_process .call_args [0 ][0 ], self .optimizely .logger )
@@ -1648,6 +1727,7 @@ def test_track__with_event_tags__forced_bucketing(self):
16481727 'enrich_decisions' : True ,
16491728 'anonymize_ip' : False ,
16501729 'revision' : '42' ,
1730+ 'region' : 'US' ,
16511731 }
16521732
16531733 log_event = EventFactory .create_log_event (mock_process .call_args [0 ][0 ], self .optimizely .logger )
@@ -1703,6 +1783,7 @@ def test_track__with_invalid_event_tags(self):
17031783 'account_id' : '12001' ,
17041784 'anonymize_ip' : False ,
17051785 'revision' : '42' ,
1786+ 'region' : 'US' ,
17061787 }
17071788
17081789 log_event = EventFactory .create_log_event (mock_process .call_args [0 ][0 ], self .optimizely .logger )
@@ -2103,6 +2184,7 @@ def test_is_feature_enabled__returns_true_for_feature_experiment_if_feature_enab
21032184 'enrich_decisions' : True ,
21042185 'anonymize_ip' : False ,
21052186 'revision' : '1' ,
2187+ 'region' : 'US' ,
21062188 }
21072189
21082190 log_event = EventFactory .create_log_event (mock_process .call_args [0 ][0 ], self .optimizely .logger )
@@ -2204,6 +2286,7 @@ def test_is_feature_enabled__returns_false_for_feature_experiment_if_feature_dis
22042286 'enrich_decisions' : True ,
22052287 'anonymize_ip' : False ,
22062288 'revision' : '1' ,
2289+ 'region' : 'US' ,
22072290 }
22082291 log_event = EventFactory .create_log_event (mock_process .call_args [0 ][0 ], self .optimizely .logger )
22092292
@@ -2356,6 +2439,7 @@ def test_is_feature_enabled__returns_true_for_feature_rollout_if_feature_enabled
23562439 'enrich_decisions' : True ,
23572440 'anonymize_ip' : False ,
23582441 'revision' : '1' ,
2442+ 'region' : 'US' ,
23592443 }
23602444 log_event = EventFactory .create_log_event (mock_process .call_args [0 ][0 ], self .optimizely .logger )
23612445
0 commit comments