Skip to content

Commit 4145598

Browse files
chore(release): Release 3.4.2 (#270)
1 parent 8562eee commit 4145598

File tree

4 files changed

+29
-28
lines changed

4 files changed

+29
-28
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# Optimizely Python SDK Changelog
22

3+
## 3.4.2
4+
June 11th, 2020
5+
6+
### Bug Fixes:
7+
* Adjusted log level for audience evaluation logs. ([#267](https://github.com/optimizely/python-sdk/pull/267))
8+
39
## 3.4.1
410
March 19th, 2020
511

612
### Bug Fixes:
713
* Updated `jsonschema` to address [installation issue](https://github.com/optimizely/python-sdk/issues/232).
814

9-
1015
## 3.4.0
1116
January 27th, 2020
1217

optimizely/entities.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2016-2018, Optimizely
1+
# Copyright 2016-2020, Optimizely
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -67,7 +67,7 @@ def __init__(
6767
self.groupId = groupId
6868
self.groupPolicy = groupPolicy
6969

70-
def getAudienceConditionsOrIds(self):
70+
def get_audience_conditions_or_ids(self):
7171
""" Returns audienceConditions if present, otherwise audienceIds. """
7272
return self.audienceConditions if self.audienceConditions is not None else self.audienceIds
7373

optimizely/helpers/audience.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2016, 2018-2019, Optimizely
1+
# Copyright 2016, 2018-2020, Optimizely
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -32,8 +32,7 @@ def is_user_in_experiment(config, experiment, attributes, logger):
3232
Boolean representing if user satisfies audience conditions for any of the audiences or not.
3333
"""
3434

35-
audience_conditions = experiment.getAudienceConditionsOrIds()
36-
35+
audience_conditions = experiment.get_audience_conditions_or_ids()
3736
logger.debug(audience_logs.EVALUATING_AUDIENCES_COMBINED.format(experiment.key, json.dumps(audience_conditions)))
3837

3938
# Return True in case there are no audiences
@@ -45,35 +44,32 @@ def is_user_in_experiment(config, experiment, attributes, logger):
4544
if attributes is None:
4645
attributes = {}
4746

48-
def evaluate_custom_attr(audienceId, index):
49-
audience = config.get_audience(audienceId)
47+
def evaluate_custom_attr(audience_id, index):
48+
audience = config.get_audience(audience_id)
5049
custom_attr_condition_evaluator = condition_helper.CustomAttributeConditionEvaluator(
5150
audience.conditionList, attributes, logger
5251
)
5352

5453
return custom_attr_condition_evaluator.evaluate(index)
5554

56-
def evaluate_audience(audienceId):
57-
audience = config.get_audience(audienceId)
55+
def evaluate_audience(audience_id):
56+
audience = config.get_audience(audience_id)
5857

5958
if audience is None:
6059
return None
6160

62-
logger.debug(audience_logs.EVALUATING_AUDIENCE.format(audienceId, audience.conditions))
61+
logger.debug(audience_logs.EVALUATING_AUDIENCE.format(audience_id, audience.conditions))
6362

6463
result = condition_tree_evaluator.evaluate(
65-
audience.conditionStructure, lambda index: evaluate_custom_attr(audienceId, index),
64+
audience.conditionStructure, lambda index: evaluate_custom_attr(audience_id, index),
6665
)
6766

6867
result_str = str(result).upper() if result is not None else 'UNKNOWN'
69-
logger.info(audience_logs.AUDIENCE_EVALUATION_RESULT.format(audienceId, result_str))
68+
logger.debug(audience_logs.AUDIENCE_EVALUATION_RESULT.format(audience_id, result_str))
7069

7170
return result
7271

7372
eval_result = condition_tree_evaluator.evaluate(audience_conditions, evaluate_audience)
74-
7573
eval_result = eval_result or False
76-
7774
logger.info(audience_logs.AUDIENCE_EVALUATION_RESULT_COMBINED.format(experiment.key, str(eval_result).upper()))
78-
7975
return eval_result

tests/helpers_tests/test_audience.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2016-2019, Optimizely
1+
# Copyright 2016-2020, Optimizely
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -140,7 +140,7 @@ def test_is_user_in_experiment__returns_False__when_condition_tree_evaluator_ret
140140
)
141141
)
142142

143-
def test_is_user_in_experiment__evaluates_audienceIds(self):
143+
def test_is_user_in_experiment__evaluates_audience_ids(self):
144144
""" Test that is_user_in_experiment correctly evaluates audience Ids and
145145
calls custom attribute evaluator for leaf nodes. """
146146

@@ -241,7 +241,7 @@ def test_is_user_in_experiment__with_no_audience(self):
241241
]
242242
)
243243

244-
def test_is_user_in_experiment__evaluates_audienceIds(self):
244+
def test_is_user_in_experiment__evaluates_audience_ids(self):
245245
user_attributes = {'test_attribute': 'test_value_1'}
246246
experiment = self.project_config.get_experiment_from_key('test_experiment')
247247
experiment.audienceIds = ['11154', '11159']
@@ -256,20 +256,20 @@ def test_is_user_in_experiment__evaluates_audienceIds(self):
256256
self.project_config, experiment, user_attributes, self.mock_client_logger,
257257
)
258258

259-
self.assertEqual(3, self.mock_client_logger.debug.call_count)
260-
self.assertEqual(3, self.mock_client_logger.info.call_count)
259+
self.assertEqual(5, self.mock_client_logger.debug.call_count)
260+
self.assertEqual(1, self.mock_client_logger.info.call_count)
261261

262262
self.mock_client_logger.assert_has_calls(
263263
[
264264
mock.call.debug('Evaluating audiences for experiment "test_experiment": ["11154", "11159"].'),
265265
mock.call.debug(
266266
'Starting to evaluate audience "11154" with conditions: ' + audience_11154.conditions + '.'
267267
),
268-
mock.call.info('Audience "11154" evaluated to UNKNOWN.'),
268+
mock.call.debug('Audience "11154" evaluated to UNKNOWN.'),
269269
mock.call.debug(
270270
'Starting to evaluate audience "11159" with conditions: ' + audience_11159.conditions + '.'
271271
),
272-
mock.call.info('Audience "11159" evaluated to UNKNOWN.'),
272+
mock.call.debug('Audience "11159" evaluated to UNKNOWN.'),
273273
mock.call.info('Audiences for experiment "test_experiment" collectively evaluated to FALSE.'),
274274
]
275275
)
@@ -292,8 +292,8 @@ def test_is_user_in_experiment__evaluates_audience_conditions(self):
292292
):
293293
audience.is_user_in_experiment(project_config, experiment, {}, self.mock_client_logger)
294294

295-
self.assertEqual(4, self.mock_client_logger.debug.call_count)
296-
self.assertEqual(4, self.mock_client_logger.info.call_count)
295+
self.assertEqual(7, self.mock_client_logger.debug.call_count)
296+
self.assertEqual(1, self.mock_client_logger.info.call_count)
297297

298298
self.mock_client_logger.assert_has_calls(
299299
[
@@ -306,17 +306,17 @@ def test_is_user_in_experiment__evaluates_audience_conditions(self):
306306
'Starting to evaluate audience "3468206642" with '
307307
'conditions: ' + audience_3468206642.conditions + '.'
308308
),
309-
mock.call.info('Audience "3468206642" evaluated to FALSE.'),
309+
mock.call.debug('Audience "3468206642" evaluated to FALSE.'),
310310
mock.call.debug(
311311
'Starting to evaluate audience "3988293898" with '
312312
'conditions: ' + audience_3988293898.conditions + '.'
313313
),
314-
mock.call.info('Audience "3988293898" evaluated to UNKNOWN.'),
314+
mock.call.debug('Audience "3988293898" evaluated to UNKNOWN.'),
315315
mock.call.debug(
316316
'Starting to evaluate audience "3988293899" with '
317317
'conditions: ' + audience_3988293899.conditions + '.'
318318
),
319-
mock.call.info('Audience "3988293899" evaluated to TRUE.'),
319+
mock.call.debug('Audience "3988293899" evaluated to TRUE.'),
320320
mock.call.info(
321321
'Audiences for experiment "audience_combinations_experiment" collectively evaluated to TRUE.'
322322
),

0 commit comments

Comments
 (0)