Skip to content

Commit

Permalink
fix linters
Browse files Browse the repository at this point in the history
  • Loading branch information
pawels-optimizely committed Apr 21, 2020
1 parent 6bbc7c4 commit f6e48ac
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
4 changes: 2 additions & 2 deletions optimizely/optimizely.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,15 @@ def _get_all_feature_variables_for_type(
)

all_variables = {}
for variable_key in feature_flag.variables:
for variable_key in feature_flag.variables:
variable = project_config.get_variable_for_feature(feature_key, variable_key)
variable_value = variable.defaultValue
if feature_enabled:
variable_value = project_config.get_variable_value_for_variation(variable, decision.variation)
self.logger.info(
'Got variable value "%s" for variable "%s" of feature flag "%s".'
% (variable_value, variable_key, feature_key)
)
)

try:
actual_value = project_config.get_typecast_value(variable_value, variable.type)
Expand Down
6 changes: 4 additions & 2 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ def setUp(self, config_dict='config_dict'):
{'id': '129', 'key': 'cost', 'defaultValue': '10.99', 'type': 'double'},
{'id': '130', 'key': 'count', 'defaultValue': '999', 'type': 'integer'},
{'id': '131', 'key': 'variable_without_usage', 'defaultValue': '45', 'type': 'integer'},
{'id': '132', 'key': 'object', 'defaultValue': '{"test": 12}', 'type': 'string', 'subType': 'json'},
{'id': '132', 'key': 'object', 'defaultValue': '{"test": 12}', 'type': 'string',
'subType': 'json'},
],
},
{
Expand All @@ -341,7 +342,8 @@ def setUp(self, config_dict='config_dict'):
{'id': '133', 'key': 'message', 'defaultValue': 'Hello', 'type': 'string'},
{'id': '134', 'key': 'price', 'defaultValue': '99.99', 'type': 'double'},
{'id': '135', 'key': 'count', 'defaultValue': '999', 'type': 'integer'},
{'id': '136', 'key': 'object', 'defaultValue': '{"field": 1}', 'type': 'string', 'subType': 'json'},
{'id': '136', 'key': 'object', 'defaultValue': '{"field": 1}', 'type': 'string',
'subType': 'json'},
],
},
{
Expand Down
6 changes: 3 additions & 3 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ def test_init__with_v4_datafile(self):
{'id': '128', 'key': 'environment', 'defaultValue': 'devel', 'type': 'string'},
{'id': '129', 'key': 'number_of_days', 'defaultValue': '192', 'type': 'integer'},
{'id': '130', 'key': 'significance_value', 'defaultValue': '0.00098', 'type': 'double'},
{'id': '131', 'key': 'object', 'defaultValue': '{"field": 12.4}', 'type': 'string', 'subType': 'json'},
{'id': '131', 'key': 'object', 'defaultValue': '{"field": 12.4}', 'type': 'string',
'subType': 'json'},
],
},
{
Expand Down Expand Up @@ -898,8 +899,7 @@ def test_get_rollout_from_id__valid_rollout_id(self):
},
],
)

print(json.loads(json.dumps(expected_rollout, default=lambda o: o.__dict__)))

self.assertEqual(expected_rollout, project_config.get_rollout_from_id('211111'))

def test_get_rollout_from_id__invalid_rollout_id(self):
Expand Down
15 changes: 8 additions & 7 deletions tests/test_optimizely.py
Original file line number Diff line number Diff line change
Expand Up @@ -2532,7 +2532,7 @@ def test_get_feature_variable_json(self):
'optimizely.notification_center.NotificationCenter.send_notifications'
) as mock_broadcast_decision:
self.assertEqual(
{"test":123},
{"test": 123},
opt_obj.get_feature_variable_json('test_feature_in_experiment', 'object', 'test_user'),
)

Expand All @@ -2550,7 +2550,7 @@ def test_get_feature_variable_json(self):
'feature_enabled': True,
'source': 'feature-test',
'variable_key': 'object',
'variable_value': {"test":123},
'variable_value': {"test": 123},
'variable_type': 'json',
'source_info': {'experiment_key': 'test_experiment', 'variation_key': 'variation'},
},
Expand Down Expand Up @@ -2587,7 +2587,8 @@ def test_get_all_feature_variables(self):
[
mock.call('Value for variable "count" for variation "variation" is "4243".'),
mock.call('Value for variable "is_working" for variation "variation" is "true".'),
mock.call('Variable "variable_without_usage" is not used in variation "variation". Assigning default value "45".'),
mock.call('Variable "variable_without_usage" is not used in variation "variation". \
Assigning default value "45".'),
mock.call('Value for variable "object" for variation "variation" is "{"test": 123}".'),
mock.call('Value for variable "environment" for variation "variation" is "staging".'),
mock.call('Value for variable "cost" for variation "variation" is "10.02".')
Expand Down Expand Up @@ -2740,7 +2741,7 @@ def test_get_feature_variable(self):
'optimizely.notification_center.NotificationCenter.send_notifications'
) as mock_broadcast_decision:
self.assertEqual(
{"test":123}, opt_obj.get_feature_variable('test_feature_in_experiment', 'object', 'test_user'),
{"test": 123}, opt_obj.get_feature_variable('test_feature_in_experiment', 'object', 'test_user'),
)

mock_config_logging.info.assert_called_once_with(
Expand Down Expand Up @@ -2990,7 +2991,7 @@ def test_get_all_feature_variables_for_feature_in_rollout(self):
self.assertEqual(5, mock_config_logging.info.call_count)

mock_config_logging.info.assert_has_calls(
[
[
mock.call('Value for variable "count" for variation "211129" is "399".'),
mock.call('Value for variable "message" for variation "211129" is "Hello audience".'),
mock.call('Value for variable "object" for variation "211129" is "{"field": 12}".'),
Expand Down Expand Up @@ -3251,7 +3252,7 @@ def test_get_feature_variable__returns_default_value_if_variable_usage_not_in_va
return_value=decision_service.Decision(mock_experiment, mock_variation, enums.DecisionSources.FEATURE_TEST),
), mock.patch.object(opt_obj.config_manager.get_config(), 'logger') as mock_config_logger:
self.assertEqual(
{"test":12}, opt_obj.get_feature_variable_json('test_feature_in_experiment', 'object', 'test_user'),
{"test": 12}, opt_obj.get_feature_variable_json('test_feature_in_experiment', 'object', 'test_user'),
)

mock_config_logger.info.assert_called_once_with(
Expand Down Expand Up @@ -4085,7 +4086,7 @@ def test_get_feature_variable__returns_default_value_if_feature_not_enabled_in_r
return_value=decision_service.Decision(mock_experiment, mock_variation, enums.DecisionSources.ROLLOUT),
), mock.patch.object(opt_obj, 'logger') as mock_client_logger:
self.assertEqual(
{"field": 1}, opt_obj.get_feature_variable_json('test_feature_in_rollout', 'object', 'test_user'),
{"field": 1}, opt_obj.get_feature_variable_json('test_feature_in_rollout', 'object', 'test_user'),
)
mock_client_logger.info.assert_called_once_with(
'Feature "test_feature_in_rollout" for variation "211229" is not enabled. '
Expand Down
18 changes: 9 additions & 9 deletions tests/test_optimizely_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,11 @@ def setUp(self):
'id': '129',
'value': '10.99'
},
'object': {
'id': '132',
'key': 'object',
'type': 'json',
'value': '{"test": 12}'
'object': {
'id': '132',
'key': 'object',
'type': 'json',
'value': '{"test": 12}'
},
'variable_without_usage': {
'key': 'variable_without_usage',
Expand Down Expand Up @@ -299,10 +299,10 @@ def setUp(self):
'value': '10.02'
},
'object': {
'id': '132',
'key': 'object',
'type': 'json',
'value': '{"test": 123}'
'id': '132',
'key': 'object',
'type': 'json',
'value': '{"test": 123}'
},
'variable_without_usage': {
'key': 'variable_without_usage',
Expand Down

0 comments on commit f6e48ac

Please sign in to comment.