Skip to content

Commit d1770d5

Browse files
rashidspmikeproeng37
authored andcommitted
Removes deprecated revenue value support (#107)
1 parent cb28ea4 commit d1770d5

File tree

3 files changed

+23
-75
lines changed

3 files changed

+23
-75
lines changed

optimizely/optimizely.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,6 @@ def track(self, event_key, user_id, attributes=None, event_tags=None):
297297
self.logger.log(enums.LogLevels.ERROR, enums.Errors.INVALID_DATAFILE.format('track'))
298298
return
299299

300-
if event_tags:
301-
if isinstance(event_tags, numbers.Number):
302-
event_tags = {
303-
'revenue': event_tags
304-
}
305-
self.logger.log(enums.LogLevels.WARNING,
306-
'Event value is deprecated in track call. Use event tags to pass in revenue value instead.')
307-
308300
if not self._validate_user_inputs(attributes, event_tags):
309301
return
310302

tests/helpers_tests/test_audience.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2016-2017, Optimizely
1+
# Copyright 2016-2018, Optimizely
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -49,10 +49,18 @@ def test_is_user_in_experiment__no_audience(self):
4949
'browser_type': 'firefox',
5050
'location': 'San Francisco'
5151
}
52+
experiment = self.project_config.get_experiment_from_key('test_experiment')
53+
experiment.audienceIds = []
54+
self.assertTrue(audience.is_user_in_experiment(self.project_config, experiment, user_attributes))
5255

53-
self.assertTrue(audience.is_user_in_experiment(self.project_config,
54-
self.project_config.get_experiment_from_key('test_experiment'),
55-
user_attributes))
56+
def test_is_user_in_experiment__no_attributes(self):
57+
""" Test that is_user_in_experiment returns True when experiment is using no audience. """
58+
59+
self.assertFalse(audience.is_user_in_experiment(self.project_config,
60+
self.project_config.get_experiment_from_key('test_experiment'), None))
61+
62+
self.assertFalse(audience.is_user_in_experiment(self.project_config,
63+
self.project_config.get_experiment_from_key('test_experiment'), {}))
5664

5765
def test_is_user_in_experiment__audience_conditions_are_met(self):
5866
""" Test that is_user_in_experiment returns True when audience conditions are met. """

tests/test_optimizely.py

Lines changed: 11 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,57 +1022,6 @@ def test_track__with_event_tags__forced_bucketing(self):
10221022
self._validate_event_object(mock_dispatch_event.call_args[0][0], 'https://logx.optimizely.com/v1/events',
10231023
expected_params, 'POST', {'Content-Type': 'application/json'})
10241024

1025-
def test_track__with_deprecated_event_value(self):
1026-
""" Test that track calls dispatch_event with right params when event_value information is provided. """
1027-
1028-
with mock.patch('optimizely.decision_service.DecisionService.get_variation',
1029-
return_value=self.project_config.get_variation_from_id(
1030-
'test_experiment', '111128'
1031-
)) as mock_get_variation, \
1032-
mock.patch('time.time', return_value=42), \
1033-
mock.patch('uuid.uuid4', return_value='a68cf1ad-0393-4e18-af87-efe8f01a7c9c'), \
1034-
mock.patch('optimizely.event_dispatcher.EventDispatcher.dispatch_event') as mock_dispatch_event:
1035-
self.optimizely.track('test_event', 'test_user', attributes={'test_attribute': 'test_value'}, event_tags=4200)
1036-
1037-
expected_params = {
1038-
'account_id': '12001',
1039-
'project_id': '111001',
1040-
'visitors': [{
1041-
'visitor_id': 'test_user',
1042-
'attributes': [{
1043-
'type': 'custom',
1044-
'value': 'test_value',
1045-
'entity_id': '111094',
1046-
'key': 'test_attribute'
1047-
}],
1048-
'snapshots': [{
1049-
'decisions': [{
1050-
'variation_id': '111128',
1051-
'experiment_id': '111127',
1052-
'campaign_id': '111182'
1053-
}],
1054-
'events': [{
1055-
'entity_id': '111095',
1056-
'key': 'test_event',
1057-
'revenue': 4200,
1058-
'tags': {
1059-
'revenue': 4200,
1060-
},
1061-
'timestamp': 42000,
1062-
'uuid': 'a68cf1ad-0393-4e18-af87-efe8f01a7c9c',
1063-
}]
1064-
}],
1065-
}],
1066-
'client_version': version.__version__,
1067-
'client_name': 'python-sdk',
1068-
'anonymize_ip': False
1069-
}
1070-
mock_get_variation.assert_called_once_with(self.project_config.get_experiment_from_key('test_experiment'),
1071-
'test_user', {'test_attribute': 'test_value'})
1072-
self.assertEqual(1, mock_dispatch_event.call_count)
1073-
self._validate_event_object(mock_dispatch_event.call_args[0][0], 'https://logx.optimizely.com/v1/events',
1074-
expected_params, 'POST', {'Content-Type': 'application/json'})
1075-
10761025
def test_track__with_invalid_event_tags(self):
10771026
""" Test that track calls dispatch_event with right params when invalid event tags are provided. """
10781027

@@ -1727,6 +1676,12 @@ def test_track__with_attributes__invalid_attributes(self):
17271676
self.assertRaisesRegexp(exceptions.InvalidAttributeException, enums.Errors.INVALID_ATTRIBUTE_FORMAT,
17281677
self.optimizely.track, 'test_event', 'test_user', attributes='invalid')
17291678

1679+
def test_track__with_event_tag__invalid_event_tag(self):
1680+
""" Test that track raises exception if event_tag is in invalid format. """
1681+
1682+
self.assertRaisesRegexp(exceptions.InvalidEventTagException, enums.Errors.INVALID_EVENT_TAG_FORMAT,
1683+
self.optimizely.track, 'test_event', 'test_user', event_tags=4200)
1684+
17301685
def test_get_variation__with_attributes__invalid_attributes(self):
17311686
""" Test that get variation raises exception if attributes are in invalid format. """
17321687

@@ -1847,23 +1802,16 @@ def test_track__invalid_attributes(self):
18471802

18481803
mock_logging.assert_called_once_with(enums.LogLevels.ERROR, 'Provided attributes are in an invalid format.')
18491804

1850-
def test_track__deprecated_event_tag(self):
1851-
""" Test that expected log messages are logged during track when attributes are in invalid format. """
1852-
1853-
with mock.patch('optimizely.logger.SimpleLogger.log') as mock_logging:
1854-
self.optimizely.track('test_event', 'test_user', event_tags=4200)
1855-
1856-
mock_logging.assert_any_call(enums.LogLevels.WARNING,
1857-
'Event value is deprecated in track call. '
1858-
'Use event tags to pass in revenue value instead.')
1859-
18601805
def test_track__invalid_event_tag(self):
1861-
""" Test that expected log messages are logged during track when attributes are in invalid format. """
1806+
""" Test that expected log messages are logged during track when event_tag is in invalid format. """
18621807

18631808
with mock.patch('optimizely.logger.SimpleLogger.log') as mock_logging:
18641809
self.optimizely.track('test_event', 'test_user', event_tags='4200')
1810+
mock_logging.assert_called_once_with(enums.LogLevels.ERROR, 'Provided event tags are in an invalid format.')
18651811

1866-
mock_logging.assert_called_once_with(enums.LogLevels.ERROR, 'Provided event tags are in an invalid format.')
1812+
with mock.patch('optimizely.logger.SimpleLogger.log') as mock_logging:
1813+
self.optimizely.track('test_event', 'test_user', event_tags=4200)
1814+
mock_logging.assert_called_once_with(enums.LogLevels.ERROR, 'Provided event tags are in an invalid format.')
18671815

18681816
def test_track__dispatch_raises_exception(self):
18691817
""" Test that track logs dispatch failure gracefully. """

0 commit comments

Comments
 (0)