Skip to content

Commit

Permalink
Fix a few more nits.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Ng committed Jun 6, 2017
1 parent 484b0f3 commit 7ecf05a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 13 additions & 1 deletion optimizely/decision_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def get_variation(self, experiment, user_id, attributes, ignore_user_profile=Fal
experiment_key: Experiment for which user variation needs to be determined.
user_id: ID for user.
attributes: Dict representing user attributes.
ignore_user_profile: True to ignore the user profile lookup. Defaults to False.
Returns:
Variation user should see. None if user is not in experiment or experiment is not running.
Expand Down Expand Up @@ -150,7 +151,18 @@ def get_variation(self, experiment, user_id, attributes, ignore_user_profile=Fal
return None

def get_variation_for_layer(self, layer, user_id, attributes=None, ignore_user_profile=False):
""" Determine which variation the user is in for a given layer. Returns the variation of the first experiment the user qualifies for. """
""" Determine which variation the user is in for a given layer. Returns the variation of the first experiment the user qualifies for.
Args:
layer: Layer for which we are getting the variation.
user_id: ID for user.
attributes: Dict representing user attributes.
ignore_user_profile: True to ignore the user profile lookup. Defaults to False.
Returns:
Variation the user should see. None if the user is not in any of the layer's experiments.
"""
# Go through each experiment in order and try to get the variation for the user
if layer:
for experiment_dict in layer.experiments:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_decision_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,12 @@ def test_get_variation__ignore_user_profile_when_specified(self):
self.assertEqual(entities.Variation('111129', 'variation'),
self.decision_service.get_variation(experiment, 'test_user', None, ignore_user_profile=True))

# Assert that user is bucketed and new decision is stored
# Assert that user is bucketed and new decision is NOT stored
mock_get_forced_variation.assert_called_once_with(experiment, 'test_user')
mock_audience_check.assert_called_once_with(self.project_config, experiment, None)
mock_bucket.assert_called_once_with(experiment, 'test_user')
self.assertFalse(mock_lookup.called)
self.assertFalse(mock_save.called)
self.assertEqual(0, mock_lookup.call_count)
self.assertEqual(0, mock_save.call_count)

def test_get_variation_for_feature__returns_variation_for_feature_in_experiment(self):
""" Test that get_variation_for_feature returns the variation of the experiment the feature is associated with. """
Expand Down

0 comments on commit 7ecf05a

Please sign in to comment.