@@ -365,6 +365,7 @@ def test_activate(self):
365
365
'enrich_decisions' : True ,
366
366
'anonymize_ip' : False ,
367
367
'revision' : '42' ,
368
+ 'region' : 'US' ,
368
369
}
369
370
370
371
log_event = EventFactory .create_log_event (mock_process .call_args [0 ][0 ], self .optimizely .logger )
@@ -385,6 +386,76 @@ def test_activate(self):
385
386
{'Content-Type' : 'application/json' },
386
387
)
387
388
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
+
388
459
def test_add_activate_remove_clear_listener (self ):
389
460
callbackhit = [False ]
390
461
""" Test adding a listener activate passes correctly and gets called"""
@@ -764,6 +835,7 @@ def test_activate__with_attributes__audience_match(self):
764
835
'enrich_decisions' : True ,
765
836
'anonymize_ip' : False ,
766
837
'revision' : '42' ,
838
+ 'region' : 'US' ,
767
839
}
768
840
769
841
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):
848
920
'enrich_decisions' : True ,
849
921
'anonymize_ip' : False ,
850
922
'revision' : '42' ,
923
+ 'region' : 'US' ,
851
924
}
852
925
853
926
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):
1044
1117
'enrich_decisions' : True ,
1045
1118
'anonymize_ip' : False ,
1046
1119
'revision' : '42' ,
1120
+ 'region' : 'US' ,
1047
1121
}
1048
1122
1049
1123
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):
1120
1194
'enrich_decisions' : True ,
1121
1195
'anonymize_ip' : False ,
1122
1196
'revision' : '42' ,
1197
+ 'region' : 'US' ,
1123
1198
}
1124
1199
1125
1200
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):
1288
1363
'enrich_decisions' : True ,
1289
1364
'anonymize_ip' : False ,
1290
1365
'revision' : '42' ,
1366
+ 'region' : 'US' ,
1291
1367
}
1292
1368
1293
1369
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):
1424
1500
'enrich_decisions' : True ,
1425
1501
'anonymize_ip' : False ,
1426
1502
'revision' : '42' ,
1503
+ 'region' : 'US' ,
1427
1504
}
1428
1505
1429
1506
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):
1504
1581
'enrich_decisions' : True ,
1505
1582
'anonymize_ip' : False ,
1506
1583
'revision' : '42' ,
1584
+ 'region' : 'US' ,
1507
1585
}
1508
1586
log_event = EventFactory .create_log_event (mock_process .call_args [0 ][0 ], self .optimizely .logger )
1509
1587
@@ -1560,6 +1638,7 @@ def test_track__with_event_tags_revenue(self):
1560
1638
'account_id' : '12001' ,
1561
1639
'anonymize_ip' : False ,
1562
1640
'revision' : '42' ,
1641
+ 'region' : 'US' ,
1563
1642
}
1564
1643
1565
1644
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):
1648
1727
'enrich_decisions' : True ,
1649
1728
'anonymize_ip' : False ,
1650
1729
'revision' : '42' ,
1730
+ 'region' : 'US' ,
1651
1731
}
1652
1732
1653
1733
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):
1703
1783
'account_id' : '12001' ,
1704
1784
'anonymize_ip' : False ,
1705
1785
'revision' : '42' ,
1786
+ 'region' : 'US' ,
1706
1787
}
1707
1788
1708
1789
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
2103
2184
'enrich_decisions' : True ,
2104
2185
'anonymize_ip' : False ,
2105
2186
'revision' : '1' ,
2187
+ 'region' : 'US' ,
2106
2188
}
2107
2189
2108
2190
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
2204
2286
'enrich_decisions' : True ,
2205
2287
'anonymize_ip' : False ,
2206
2288
'revision' : '1' ,
2289
+ 'region' : 'US' ,
2207
2290
}
2208
2291
log_event = EventFactory .create_log_event (mock_process .call_args [0 ][0 ], self .optimizely .logger )
2209
2292
@@ -2356,6 +2439,7 @@ def test_is_feature_enabled__returns_true_for_feature_rollout_if_feature_enabled
2356
2439
'enrich_decisions' : True ,
2357
2440
'anonymize_ip' : False ,
2358
2441
'revision' : '1' ,
2442
+ 'region' : 'US' ,
2359
2443
}
2360
2444
log_event = EventFactory .create_log_event (mock_process .call_args [0 ][0 ], self .optimizely .logger )
2361
2445
0 commit comments