Skip to content

Commit

Permalink
PEP8 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
oakbani committed Apr 9, 2018
1 parent 8beb5f5 commit 5ecf0b8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
11 changes: 6 additions & 5 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ def test_get_forced_variation_with_none_set_for_user(self):
with mock.patch('optimizely.logger.NoOpLogger.log') as mock_logging:
self.assertIsNone(self.project_config.get_forced_variation('test_experiment', 'test_user'))
mock_logging.assert_called_once_with(
enums.LogLevels.DEBUG,
enums.LogLevels.DEBUG,
'No experiment "test_experiment" mapped to user "test_user" in the forced variation map.')

def test_get_forced_variation_missing_variation_mapped_to_experiment(self):
Expand All @@ -1002,7 +1002,7 @@ def test_get_forced_variation_missing_variation_mapped_to_experiment(self):
with mock.patch('optimizely.logger.NoOpLogger.log') as mock_logging:
self.assertIsNone(self.project_config.get_forced_variation('test_experiment', 'test_user'))
mock_logging.assert_called_once_with(
enums.LogLevels.DEBUG,
enums.LogLevels.DEBUG,
'No variation mapped to experiment "test_experiment" in the forced variation map.')

# set_forced_variation tests
Expand Down Expand Up @@ -1060,19 +1060,20 @@ def test_set_forced_variation_when_called_to_remove_forced_variation(self):
with mock.patch('optimizely.logger.NoOpLogger.log') as mock_logging:
self.assertTrue(self.project_config.set_forced_variation('test_experiment', 'test_user', None))
mock_logging.assert_called_once_with(
enums.LogLevels.DEBUG,
enums.LogLevels.DEBUG,
'Variation mapped to experiment "test_experiment" has been removed for user "test_user".')

# Test case where user is present in the forced variation map, but the given experiment isn't
self.project_config.forced_variation_map = {}
self.project_config.set_forced_variation('test_experiment', 'test_user', 'variation')

with mock.patch('optimizely.logger.NoOpLogger.log') as mock_logging:
self.assertTrue(self.project_config.set_forced_variation('group_exp_1', 'test_user', None))
mock_logging.assert_called_once_with(
enums.LogLevels.DEBUG,
enums.LogLevels.DEBUG,
'Nothing to remove. Variation mapped to experiment "group_exp_1" for user "test_user" does not exist.')


class ConfigLoggingTest(base.BaseTest):
def setUp(self):
base.BaseTest.setUp(self)
Expand Down
15 changes: 8 additions & 7 deletions tests/test_decision_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2017, Optimizely
# Copyright 2017-2018, Optimizely
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down Expand Up @@ -437,13 +437,14 @@ def test_get_variation_for_rollout__skips_to_everyone_else_rule(self, mock_loggi
for the experiment, then it skips to the Everyone Else rule. """

rollout = self.project_config.get_rollout_from_id('211111')
everyone_else_experiment = self.project_config.get_experiment_from_id('211147')
everyone_else_exp = self.project_config.get_experiment_from_id('211147')
variation_to_mock = self.project_config.get_variation_from_id('211147', '211149')

with mock.patch('optimizely.helpers.audience.is_user_in_experiment', return_value=True) as mock_audience_check,\
mock.patch('optimizely.bucketer.Bucketer.bucket', side_effect= [None, variation_to_mock]):
self.assertEqual(decision_service.Decision(everyone_else_experiment, variation_to_mock, decision_service.DECISION_SOURCE_ROLLOUT),
self.decision_service.get_variation_for_rollout(rollout, 'test_user'))
mock.patch('optimizely.bucketer.Bucketer.bucket', side_effect=[None, variation_to_mock]):
self.assertEqual(
decision_service.Decision(everyone_else_exp, variation_to_mock, decision_service.DECISION_SOURCE_ROLLOUT),
self.decision_service.get_variation_for_rollout(rollout, 'test_user'))

# Check that after first experiment, it skips to the last experiment to check
self.assertEqual(
Expand All @@ -457,7 +458,7 @@ def test_get_variation_for_rollout__skips_to_everyone_else_rule(self, mock_loggi
[mock.call(enums.LogLevels.DEBUG, 'User "test_user" meets conditions for targeting rule 1.'),
mock.call(enums.LogLevels.DEBUG, 'User "test_user" is not in the traffic group for the targeting else. '
'Checking "Everyone Else" rule now.'),
mock.call(enums.LogLevels.DEBUG, 'User "test_user" meets conditions for targeting rule "Everyone Else".')],
mock.call(enums.LogLevels.DEBUG, 'User "test_user" meets conditions for targeting rule "Everyone Else".')],
mock_logging.call_args_list)

def test_get_variation_for_rollout__returns_none_for_user_not_in_rollout(self, mock_logging):
Expand Down Expand Up @@ -608,7 +609,7 @@ def test_get_variation_for_feature__returns_none_for_invalid_group_id(self, mock
decision_service.DECISION_SOURCE_EXPERIMENT),
self.decision_service.get_variation_for_feature(feature, 'test_user')
)
mock_logging.assert_called_with(enums.LogLevels.ERROR,
mock_logging.assert_called_with(enums.LogLevels.ERROR,
enums.Errors.INVALID_GROUP_ID_ERROR.format('_get_variation_for_feature'))

def test_get_variation_for_feature__returns_none_for_user_in_group_experiment_not_associated_with_feature(self, _):
Expand Down
1 change: 0 additions & 1 deletion tests/test_optimizely.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,6 @@ def test_track_invalid_event_key(self):
self.optimizely.track('aabbcc_event', 'test_user')

self.assertEqual(0, mock_dispatch_event.call_count)
print mock_logging.call_args_list
mock_logging.assert_called_with(
enums.LogLevels.INFO,
'Not tracking user "test_user" for event "aabbcc_event".'
Expand Down

0 comments on commit 5ecf0b8

Please sign in to comment.