Skip to content

Commit 7a09f1d

Browse files
committed
Fix tests
1 parent 1af68db commit 7a09f1d

File tree

2 files changed

+43
-35
lines changed

2 files changed

+43
-35
lines changed

tests/test_event_builder.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ def test_create_impression_event_when_attribute_is_not_in_datafile(self):
208208
'111129',
209209
'test_user',
210210
{'do_you_know_me': 'test_value'},
211+
'US'
211212
)
212213
self._validate_event_object(
213214
event_obj,
@@ -280,6 +281,7 @@ def side_effect(*args, **kwargs):
280281
'111129',
281282
'test_user',
282283
attributes,
284+
'US',
283285
)
284286

285287
self._validate_event_object(
@@ -346,6 +348,7 @@ def test_create_impression_event__with_user_agent_when_bot_filtering_is_enabled(
346348
'111129',
347349
'test_user',
348350
{'$opt_user_agent': 'Edge'},
351+
'US'
349352
)
350353

351354
self._validate_event_object(
@@ -411,6 +414,7 @@ def test_create_impression_event__with_empty_attributes_when_bot_filtering_is_en
411414
'111129',
412415
'test_user',
413416
None,
417+
'US'
414418
)
415419

416420
self._validate_event_object(
@@ -482,6 +486,7 @@ def test_create_impression_event__with_user_agent_when_bot_filtering_is_disabled
482486
'111129',
483487
'test_user',
484488
{'$opt_user_agent': 'Chrome'},
489+
'US'
485490
)
486491

487492
self._validate_event_object(
@@ -529,7 +534,7 @@ def test_create_conversion_event(self):
529534
'uuid.uuid4', return_value='a68cf1ad-0393-4e18-af87-efe8f01a7c9c'
530535
):
531536
event_obj = self.event_builder.create_conversion_event(
532-
self.project_config, 'test_event', 'test_user', None, None
537+
self.project_config, 'test_event', 'test_user', None, None, 'US'
533538
)
534539
self._validate_event_object(
535540
event_obj,
@@ -578,7 +583,7 @@ def test_create_conversion_event__with_attributes(self):
578583
'uuid.uuid4', return_value='a68cf1ad-0393-4e18-af87-efe8f01a7c9c'
579584
):
580585
event_obj = self.event_builder.create_conversion_event(
581-
self.project_config, 'test_event', 'test_user', {'test_attribute': 'test_value'}, None,
586+
self.project_config, 'test_event', 'test_user', {'test_attribute': 'test_value'}, None, 'US'
582587
)
583588
self._validate_event_object(
584589
event_obj,
@@ -636,7 +641,7 @@ def test_create_conversion_event__with_user_agent_when_bot_filtering_is_enabled(
636641
'optimizely.project_config.ProjectConfig.get_bot_filtering_value', return_value=True,
637642
):
638643
event_obj = self.event_builder.create_conversion_event(
639-
self.project_config, 'test_event', 'test_user', {'$opt_user_agent': 'Edge'}, None,
644+
self.project_config, 'test_event', 'test_user', {'$opt_user_agent': 'Edge'}, None, 'US'
640645
)
641646

642647
self._validate_event_object(
@@ -700,7 +705,7 @@ def test_create_conversion_event__with_user_agent_when_bot_filtering_is_disabled
700705
'optimizely.project_config.ProjectConfig.get_bot_filtering_value', return_value=False,
701706
):
702707
event_obj = self.event_builder.create_conversion_event(
703-
self.project_config, 'test_event', 'test_user', {'$opt_user_agent': 'Chrome'}, None,
708+
self.project_config, 'test_event', 'test_user', {'$opt_user_agent': 'Chrome'}, None, 'US'
704709
)
705710

706711
self._validate_event_object(
@@ -758,6 +763,7 @@ def test_create_conversion_event__with_event_tags(self):
758763
'test_user',
759764
{'test_attribute': 'test_value'},
760765
{'revenue': 4200, 'value': 1.234, 'non-revenue': 'abc'},
766+
'US'
761767
)
762768
self._validate_event_object(
763769
event_obj,
@@ -812,6 +818,7 @@ def test_create_conversion_event__with_invalid_event_tags(self):
812818
'test_user',
813819
{'test_attribute': 'test_value'},
814820
{'revenue': '4200', 'value': True, 'non-revenue': 'abc'},
821+
'US'
815822
)
816823
self._validate_event_object(
817824
event_obj,
@@ -868,6 +875,7 @@ def test_create_conversion_event__when_event_is_used_in_multiple_experiments(sel
868875
'test_user',
869876
{'test_attribute': 'test_value'},
870877
{'revenue': 4200, 'value': 1.234, 'non-revenue': 'abc'},
878+
'US'
871879
)
872880
self._validate_event_object(
873881
event_obj,

tests/test_event_factory.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -312,39 +312,39 @@ def side_effect(*args, **kwargs):
312312

313313
return False
314314

315-
attributes = {
316-
'test_attribute': 'test_value',
317-
'boolean_key': True,
318-
'integer_key': 0,
319-
'double_key': 5.5,
320-
}
321-
322-
with mock.patch('time.time', return_value=42.123), mock.patch(
323-
'uuid.uuid4', return_value='a68cf1ad-0393-4e18-af87-efe8f01a7c9c'
324-
), mock.patch(
325-
'optimizely.helpers.validator.is_attribute_valid', side_effect=side_effect,
326-
):
327-
328-
event_obj = UserEventFactory.create_impression_event(
329-
self.project_config,
330-
self.project_config.get_experiment_from_key('test_experiment'),
331-
'111129',
332-
'',
333-
'experiment',
334-
'test_user',
335-
attributes,
336-
)
337-
338-
log_event = EventFactory.create_log_event(event_obj, self.logger)
339-
340-
self._validate_event_object(
341-
log_event,
342-
EventFactory.EVENT_ENDPOINTS.get('US'),
343-
expected_params,
344-
EventFactory.HTTP_VERB,
345-
EventFactory.HTTP_HEADERS,
315+
attributes = {
316+
'test_attribute': 'test_value',
317+
'boolean_key': True,
318+
'integer_key': 0,
319+
'double_key': 5.5,
320+
}
321+
322+
with mock.patch('time.time', return_value=42.123), mock.patch(
323+
'uuid.uuid4', return_value='a68cf1ad-0393-4e18-af87-efe8f01a7c9c'
324+
), mock.patch(
325+
'optimizely.helpers.validator.is_attribute_valid', side_effect=side_effect,
326+
):
327+
328+
event_obj = UserEventFactory.create_impression_event(
329+
self.project_config,
330+
self.project_config.get_experiment_from_key('test_experiment'),
331+
'111129',
332+
'',
333+
'experiment',
334+
'test_user',
335+
attributes,
346336
)
347337

338+
log_event = EventFactory.create_log_event(event_obj, self.logger)
339+
340+
self._validate_event_object(
341+
log_event,
342+
EventFactory.EVENT_ENDPOINTS.get('US'),
343+
expected_params,
344+
EventFactory.HTTP_VERB,
345+
EventFactory.HTTP_HEADERS,
346+
)
347+
348348
def test_create_impression_event__with_user_agent_when_bot_filtering_is_enabled(self,):
349349
""" Test that create_impression_event creates Event object
350350
with right params when user agent attribute is provided and

0 commit comments

Comments
 (0)