Skip to content

Commit

Permalink
making test perform more checks
Browse files Browse the repository at this point in the history
  • Loading branch information
aliabbasrizvi committed Sep 23, 2016
1 parent 4abeda6 commit 304ad3f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/test_optimizely.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,17 @@ def test_track__experiment_not_running(self):

with mock.patch('optimizely.helpers.experiment.is_experiment_running',
return_value=False) as mock_is_experiment_running,\
mock.patch('optimizely.helpers.experiment.is_user_in_forced_variation',
return_value=True) as mock_whitelist_check,\
mock.patch('optimizely.helpers.audience.is_user_in_experiment', return_value=True) as mock_audience_check,\
mock.patch('time.time', return_value=42),\
mock.patch('optimizely.event_dispatcher.EventDispatcher.dispatch_event') as mock_dispatch_event:
self.optimizely.track('test_event', 'test_user')

mock_is_experiment_running.assert_called_once_with(self.project_config.get_experiment_from_key('test_experiment'))
self.assertEqual(0, mock_dispatch_event.call_count)
self.assertEqual(0, mock_whitelist_check.call_count)
self.assertEqual(0, mock_audience_check.call_count)

def test_track__whitelisted_user_overrides_audience_check(self):
""" Test that track does not check for user in audience when user is in whitelist. """
Expand Down Expand Up @@ -331,13 +336,18 @@ def test_get_variation__experiment_not_running(self):
return_value=self.project_config.get_variation_from_id(
'test_experiment', '111129'
)) as mock_bucket,\
mock.patch('optimizely.helpers.experiment.is_user_in_forced_variation',
return_value=True) as mock_whitelist_check,\
mock.patch('optimizely.helpers.audience.is_user_in_experiment', return_value=True) as mock_audience_check,\
mock.patch('optimizely.helpers.experiment.is_experiment_running',
return_value=False) as mock_is_experiment_running:
self.assertIsNone(self.optimizely.get_variation('test_experiment', 'test_user',
attributes={'test_attribute': 'test_value'}))

self.assertEqual(0, mock_bucket.call_count)
mock_is_experiment_running.assert_called_once_with(self.project_config.get_experiment_from_key('test_experiment'))
self.assertEqual(0, mock_whitelist_check.call_count)
self.assertEqual(0, mock_audience_check.call_count)

def test_get_variation__whitelisting_overrides_audience_check(self):
""" Test that in get_variation whitelist overrides audience check if user is in the whitelist. """
Expand Down

0 comments on commit 304ad3f

Please sign in to comment.