1717
1818from optimizely import event_builder
1919from optimizely import version
20+ from optimizely .project_config import Region
2021from . import base
2122
2223
@@ -37,7 +38,6 @@ class EventBuilderTest(base.BaseTest):
3738 def setUp (self , * args , ** kwargs ):
3839 base .BaseTest .setUp (self , 'config_dict_with_multiple_experiments' )
3940 self .event_builder = self .optimizely .event_builder
40- self .maxDiff = None
4141
4242 def _validate_event_object (self , event_obj , expected_url , expected_params , expected_verb , expected_headers ):
4343 """ Helper method to validate properties of the event object. """
@@ -107,6 +107,60 @@ def test_create_impression_event(self):
107107 event_builder .EventBuilder .HTTP_HEADERS ,
108108 )
109109
110+ def test_create_impression_event_with_EU (self ):
111+ """ Test that create_impression_event creates Event object with right params and EU region. """
112+
113+ expected_params = {
114+ 'account_id' : '12001' ,
115+ 'project_id' : '111001' ,
116+ 'visitors' : [
117+ {
118+ 'visitor_id' : 'test_user' ,
119+ 'attributes' : [],
120+ 'snapshots' : [
121+ {
122+ 'decisions' : [
123+ {'variation_id' : '111129' , 'experiment_id' : '111127' , 'campaign_id' : '111182' }
124+ ],
125+ 'events' : [
126+ {
127+ 'timestamp' : 42123 ,
128+ 'entity_id' : '111182' ,
129+ 'uuid' : 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c' ,
130+ 'key' : 'campaign_activated' ,
131+ }
132+ ],
133+ }
134+ ],
135+ }
136+ ],
137+ 'client_name' : 'python-sdk' ,
138+ 'client_version' : version .__version__ ,
139+ 'enrich_decisions' : True ,
140+ 'anonymize_ip' : False ,
141+ 'revision' : '42' ,
142+ }
143+
144+ with mock .patch .object (self .project_config , 'region' , new = Region .EU ), mock .patch (
145+ 'time.time' , return_value = 42.123
146+ ), mock .patch (
147+ 'optimizely.bucketer.Bucketer._generate_bucket_value' , return_value = 5042
148+ ), mock .patch ('uuid.uuid4' , return_value = 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c' ):
149+ event_obj = self .event_builder .create_impression_event (
150+ self .project_config ,
151+ self .project_config .get_experiment_from_key ('test_experiment' ),
152+ '111129' ,
153+ 'test_user' ,
154+ None ,
155+ )
156+ self ._validate_event_object (
157+ event_obj ,
158+ event_builder .EventBuilder .EVENTS_URLS .get ('EU' ),
159+ expected_params ,
160+ event_builder .EventBuilder .HTTP_VERB ,
161+ event_builder .EventBuilder .HTTP_HEADERS ,
162+ )
163+
110164 def test_create_impression_event__with_attributes (self ):
111165 """ Test that create_impression_event creates Event object
112166 with right params when attributes are provided. """
@@ -532,6 +586,54 @@ def test_create_conversion_event(self):
532586 event_builder .EventBuilder .HTTP_HEADERS ,
533587 )
534588
589+ def test_create_conversion_event_with_eu (self ):
590+ """ Test that create_conversion_event creates Event object
591+ with right params when no attributes are provided. """
592+
593+ expected_params = {
594+ 'account_id' : '12001' ,
595+ 'project_id' : '111001' ,
596+ 'visitors' : [
597+ {
598+ 'visitor_id' : 'test_user' ,
599+ 'attributes' : [],
600+ 'snapshots' : [
601+ {
602+ 'events' : [
603+ {
604+ 'timestamp' : 42123 ,
605+ 'entity_id' : '111095' ,
606+ 'uuid' : 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c' ,
607+ 'key' : 'test_event' ,
608+ }
609+ ]
610+ }
611+ ],
612+ }
613+ ],
614+ 'client_name' : 'python-sdk' ,
615+ 'client_version' : version .__version__ ,
616+ 'enrich_decisions' : True ,
617+ 'anonymize_ip' : False ,
618+ 'revision' : '42' ,
619+ }
620+
621+ with mock .patch .object (self .project_config , 'region' , new = Region .EU ), mock .patch (
622+ 'time.time' , return_value = 42.123
623+ ), mock .patch (
624+ 'uuid.uuid4' , return_value = 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c'
625+ ):
626+ event_obj = self .event_builder .create_conversion_event (
627+ self .project_config , 'test_event' , 'test_user' , None , None
628+ )
629+ self ._validate_event_object (
630+ event_obj ,
631+ event_builder .EventBuilder .EVENTS_URLS .get ('EU' ),
632+ expected_params ,
633+ event_builder .EventBuilder .HTTP_VERB ,
634+ event_builder .EventBuilder .HTTP_HEADERS ,
635+ )
636+
535637 def test_create_conversion_event__with_attributes (self ):
536638 """ Test that create_conversion_event creates Event object
537639 with right params when attributes are provided. """
0 commit comments