Esempio n. 1
0
    def test_get_stored_variation__no_stored_decision_available(self):
        """ Test that get_stored_variation returns None when no decision is available. """

        experiment = self.project_config.get_experiment_from_key(
            'test_experiment')
        profile = user_profile.UserProfile('test_user')
        self.assertIsNone(
            self.decision_service.get_stored_variation(experiment, profile))
Esempio n. 2
0
  def test_get_stored_variation__stored_decision_available(self):
    """ Test that stored decision is retrieved as expected. """

    experiment = self.project_config.get_experiment_from_key('test_experiment')
    profile = user_profile.UserProfile('test_user', experiment_bucket_map={'111127': {'variation_id': '111128'}})
    with mock.patch.object(self.decision_service, 'logger') as mock_decision_logging:
      self.assertEqual(entities.Variation('111128', 'control'),
                       self.decision_service.get_stored_variation(experiment, profile))

    mock_decision_logging.info.assert_called_once_with(
      'Found a stored decision. User "test_user" is in variation "control" of experiment "test_experiment".'
    )
Esempio n. 3
0
  def test_get_variation__user_does_not_meet_audience_conditions(self):
    """ Test that get_variation returns None if user is not in experiment. """

    experiment = self.project_config.get_experiment_from_key('test_experiment')
    with mock.patch('optimizely.decision_service.DecisionService.get_forced_variation',
                    return_value=None) as mock_get_forced_variation, \
      mock.patch('optimizely.decision_service.DecisionService.get_stored_variation',
                 return_value=None) as mock_get_stored_variation, \
      mock.patch('optimizely.helpers.audience.is_user_in_experiment', return_value=False) as mock_audience_check, \
      mock.patch('optimizely.bucketer.Bucketer.bucket') as mock_bucket, \
      mock.patch('optimizely.user_profile.UserProfileService.lookup',
                 return_value={'user_id': 'test_user', 'experiment_bucket_map': {}}) as mock_lookup, \
      mock.patch('optimizely.user_profile.UserProfileService.save') as mock_save:
      self.assertIsNone(self.decision_service.get_variation(experiment, 'test_user', None))

    # Assert that user is bucketed and new decision is stored
    mock_get_forced_variation.assert_called_once_with(experiment, 'test_user')
    mock_lookup.assert_called_once_with('test_user')
    mock_get_stored_variation.assert_called_once_with(experiment, user_profile.UserProfile('test_user'))
    mock_audience_check.assert_called_once_with(self.project_config, experiment, None)
    self.assertEqual(0, mock_bucket.call_count)
    self.assertEqual(0, mock_save.call_count)
Esempio n. 4
0
    def setUp(self):
        user_id = 'test_user'
        experiment_bucket_map = {'199912': {'variation_id': '14512525'}}

        self.profile = user_profile.UserProfile(
            user_id, experiment_bucket_map=experiment_bucket_map)