@@ -125,6 +125,72 @@ def test_create_impression_event(self):
125
125
EventFactory .HTTP_HEADERS ,
126
126
)
127
127
128
+ def test_create_impression_event_with_eu (self ):
129
+ """ Test that create_impression_event creates LogEvent object with right params and region is EU. """
130
+
131
+ expected_params = {
132
+ 'account_id' : '12001' ,
133
+ 'project_id' : '111001' ,
134
+ 'visitors' : [
135
+ {
136
+ 'visitor_id' : 'test_user' ,
137
+ 'attributes' : [],
138
+ 'snapshots' : [
139
+ {
140
+ 'decisions' : [
141
+ {'variation_id' : '111129' , 'experiment_id' : '111127' , 'campaign_id' : '111182' ,
142
+ 'metadata' : {'flag_key' : '' ,
143
+ 'rule_key' : 'rule_key' ,
144
+ 'rule_type' : 'experiment' ,
145
+ 'variation_key' : 'variation' ,
146
+ 'enabled' : False }}
147
+ ],
148
+ 'events' : [
149
+ {
150
+ 'timestamp' : 42123 ,
151
+ 'entity_id' : '111182' ,
152
+ 'uuid' : 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c' ,
153
+ 'key' : 'campaign_activated' ,
154
+ }
155
+ ],
156
+ }
157
+ ],
158
+ }
159
+ ],
160
+ 'client_name' : 'python-sdk' ,
161
+ 'client_version' : version .__version__ ,
162
+ 'enrich_decisions' : True ,
163
+ 'anonymize_ip' : False ,
164
+ 'revision' : '42' ,
165
+ }
166
+
167
+ self .project_config .region = 'EU'
168
+
169
+ with mock .patch ('time.time' , return_value = 42.123 ), mock .patch (
170
+ 'uuid.uuid4' , return_value = 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c'
171
+ ):
172
+ event_obj = UserEventFactory .create_impression_event (
173
+ self .project_config ,
174
+ self .project_config .get_experiment_from_key ('test_experiment' ),
175
+ '111129' ,
176
+ '' ,
177
+ 'rule_key' ,
178
+ 'experiment' ,
179
+ False ,
180
+ 'test_user' ,
181
+ None ,
182
+ )
183
+
184
+ log_event = EventFactory .create_log_event (event_obj , self .logger )
185
+
186
+ self ._validate_event_object (
187
+ log_event ,
188
+ EventFactory .EVENT_ENDPOINTS .get ('EU' ),
189
+ expected_params ,
190
+ EventFactory .HTTP_VERB ,
191
+ EventFactory .HTTP_HEADERS ,
192
+ )
193
+
128
194
def test_create_impression_event__with_attributes (self ):
129
195
""" Test that create_impression_event creates Event object
130
196
with right params when attributes are provided. """
@@ -625,6 +691,57 @@ def test_create_conversion_event(self):
625
691
EventFactory .HTTP_HEADERS ,
626
692
)
627
693
694
+ def test_create_conversion_event_with_eu (self ):
695
+ """ Test that create_conversion_event creates Event object
696
+ with right params when no attributes are provided and region is EU. """
697
+
698
+ expected_params = {
699
+ 'account_id' : '12001' ,
700
+ 'project_id' : '111001' ,
701
+ 'visitors' : [
702
+ {
703
+ 'visitor_id' : 'test_user' ,
704
+ 'attributes' : [],
705
+ 'snapshots' : [
706
+ {
707
+ 'events' : [
708
+ {
709
+ 'timestamp' : 42123 ,
710
+ 'entity_id' : '111095' ,
711
+ 'uuid' : 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c' ,
712
+ 'key' : 'test_event' ,
713
+ }
714
+ ]
715
+ }
716
+ ],
717
+ }
718
+ ],
719
+ 'client_name' : 'python-sdk' ,
720
+ 'client_version' : version .__version__ ,
721
+ 'enrich_decisions' : True ,
722
+ 'anonymize_ip' : False ,
723
+ 'revision' : '42' ,
724
+ }
725
+
726
+ self .project_config .region = 'EU'
727
+
728
+ with mock .patch ('time.time' , return_value = 42.123 ), mock .patch (
729
+ 'uuid.uuid4' , return_value = 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c'
730
+ ):
731
+ event_obj = UserEventFactory .create_conversion_event (
732
+ self .project_config , 'test_event' , 'test_user' , None , None
733
+ )
734
+
735
+ log_event = EventFactory .create_log_event (event_obj , self .logger )
736
+
737
+ self ._validate_event_object (
738
+ log_event ,
739
+ EventFactory .EVENT_ENDPOINTS .get ('EU' ),
740
+ expected_params ,
741
+ EventFactory .HTTP_VERB ,
742
+ EventFactory .HTTP_HEADERS ,
743
+ )
744
+
628
745
def test_create_conversion_event__with_attributes (self ):
629
746
""" Test that create_conversion_event creates Event object
630
747
with right params when attributes are provided. """
0 commit comments