Skip to content

Commit

Permalink
Sorted the event features results in the test so we don't have to sor…
Browse files Browse the repository at this point in the history
…t it in the event builder.
  • Loading branch information
alda-optimizely committed Sep 12, 2017
1 parent 3a88c8d commit ba86cbe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions optimizely/event_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ def _add_required_params_for_conversion(self, event_key, event_tags, decisions):
})

self.params[self.EventParams.EVENT_METRICS] = event_values

for event_tag_id in sorted(event_tags.keys()):
for event_tag_id in event_tags.keys():
event_tag_value = event_tags.get(event_tag_id)
if event_tag_value is None:
continue
Expand Down
10 changes: 10 additions & 0 deletions tests/test_optimizely.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,12 @@ def test_track__with_deprecated_event_value(self):
}],
'accountId': '12001'
}

# Sort event features based on ID
mock_dispatch_event.call_args[0][0].params['eventFeatures'] = sorted(
mock_dispatch_event.call_args[0][0].params['eventFeatures'], key=lambda x: x.get('name')
)

mock_get_variation.assert_called_once_with(self.project_config.get_experiment_from_key('test_experiment'),
'test_user', {'test_attribute': 'test_value'})
self.assertEqual(1, mock_dispatch_event.call_count)
Expand Down Expand Up @@ -752,6 +758,10 @@ def test_track__with_invalid_event_tags(self):
'accountId': '12001'
}

# Sort event features based on ID
mock_dispatch_event.call_args[0][0].params['eventFeatures'] = sorted(
mock_dispatch_event.call_args[0][0].params['eventFeatures'], key=lambda x: x.get('name')
)
mock_get_variation.assert_called_once_with(self.project_config.get_experiment_from_key('test_experiment'),
'test_user', {'test_attribute': 'test_value'})
self.assertEqual(1, mock_dispatch_event.call_count)
Expand Down

0 comments on commit ba86cbe

Please sign in to comment.