Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
e80fdfb
added sdk and environment key
ozayr-zaviar Jun 10, 2021
d58b71a
[MAINTENANCE] Remove Deprecated warnings during build
The-inside-man Jun 3, 2021
a583ea5
[OASIS-7757] Fix spelling of environment to fix testcases from failing
The-inside-man Jun 15, 2021
5b2196c
[OASIS-7757] - Added additional test cases to test_optimizely and tes…
The-inside-man Jun 17, 2021
f964f94
[OASIS-7800] Updated optimizely_config with attributes and events
The-inside-man Jun 22, 2021
f60ab0a
[OASIS-7757] - update copyright years and add more testcases for sdk_…
The-inside-man Jun 23, 2021
df1b081
[OASIS-7800] Updated optimizely_config with attributes and events
The-inside-man Jun 23, 2021
9c9bcea
Run autopep8 to fix formatting issues after rebase
The-inside-man Jun 24, 2021
61d5c24
[OASIS-7800] - Added test cases for attribute map and events map
The-inside-man Jun 24, 2021
13703ca
Remove unused import from optimizely config
The-inside-man Jun 24, 2021
ef95cd8
Corrected comment wording in get functions for events.
The-inside-man Jun 25, 2021
b8828b9
[OASIS-7812] - Add Audiences to OpotimizelyConfig to expose to users
The-inside-man Jul 2, 2021
c3bc816
Remove unused import for Experiment in OptimizelyConfig
The-inside-man Jul 2, 2021
f1bd533
Update Formatting issues for lint
The-inside-man Jul 2, 2021
0ad43d0
Update Import for conditions in optimizely_config.py
The-inside-man Jul 2, 2021
942bfe9
Additional changes for audiences and added functions to create attrib…
The-inside-man Jul 6, 2021
528b8f2
Add delivery_rules to OptimizelyConfig and testcases to support
The-inside-man Jul 6, 2021
c3c3d2c
Formatting issues
The-inside-man Jul 6, 2021
2fef52a
Fix line length in comments and statement
The-inside-man Jul 6, 2021
d3b2a46
Shortened return statement
The-inside-man Jul 6, 2021
dda6e76
Updated list copy to use slice for backwards compatibility
The-inside-man Jul 6, 2021
4f2d7fb
Add in test datafile for typed audiences
The-inside-man Jul 7, 2021
f90e3e3
remove unused import
The-inside-man Jul 7, 2021
4471555
Merge branch 'master' into jbrown/oasis-7812
The-inside-man Jul 7, 2021
bb98741
Modify test_update_experiment to pass audiences as OptimizelyExperiment
The-inside-man Jul 7, 2021
48f604b
Fix linting issues
The-inside-man Jul 7, 2021
8179f2b
Style changes as requested to comments and variable naming.
The-inside-man Jul 7, 2021
d694c7f
Lint Update
The-inside-man Jul 7, 2021
ec39096
Fix line length
The-inside-man Jul 7, 2021
a687a9b
Move upper() to central location to only call once
The-inside-man Jul 7, 2021
11be430
Indent fix
The-inside-man Jul 7, 2021
ecf2e45
Broke statement into two for Lint issues
The-inside-man Jul 7, 2021
f568aad
Added test case for variation
The-inside-man Jul 9, 2021
3b8706f
Add changes to decision service to us experiment ID instead of KEY.
The-inside-man Jul 9, 2021
2504f98
Missing newline added
The-inside-man Jul 9, 2021
1cd6aab
Remove redundant update function. Ad
The-inside-man Jul 9, 2021
bc98adc
Rename testcase to remove replace_ids_with_names.
The-inside-man Jul 9, 2021
98ff2b6
Duplicate experiment Key issue with multi feature flag (#347)
The-inside-man Jul 9, 2021
d6fa32d
Update delivery rules test.
The-inside-man Jul 9, 2021
16059d7
Explenation added to flake8 for ignoring W504.
The-inside-man Jul 12, 2021
0320627
Changes made to move delivery rules and experiment rules into Optimiz…
The-inside-man Jul 12, 2021
8187f6f
Formatter on new changes
The-inside-man Jul 12, 2021
0804bb8
Merge branch 'master' into jbrown/oasis-7812
The-inside-man Jul 12, 2021
ba3bbef
Remove TODO and other dev comments
The-inside-man Jul 12, 2021
2567bac
Remove TODO and other dev comments
The-inside-man Jul 12, 2021
d401c72
Remove unused imoprt
The-inside-man Jul 12, 2021
6b4a00d
Added nl after imports to follow Flake8
The-inside-man Jul 12, 2021
a1ed815
Add except for if incorrect type used in lookup_name_from_id() to pre…
The-inside-man Jul 12, 2021
ec4218a
Correct except to assign audience_id instead of blank string
The-inside-man Jul 12, 2021
508f82f
Casting name to string in case non string type for testing
The-inside-man Jul 12, 2021
26ad430
Added test and modification to account for scenario when NOT is follo…
The-inside-man Jul 12, 2021
1f35dda
Update from isinstance to type and change List to list for python 3.4
The-inside-man Jul 12, 2021
a4e497f
Simplified stringifyConditions algorithm to be more readable and less…
The-inside-man Jul 13, 2021
bf92fd7
Updated changes - reuse test logic, modify stringify to proper handle…
The-inside-man Jul 13, 2021
2d6def3
Change to single test to run all cases for stringify.
The-inside-man Jul 14, 2021
bec791a
Move config_service out of loop.
The-inside-man Jul 14, 2021
286f178
Added missed step in delivery rules.
The-inside-man Jul 14, 2021
c3faba3
Update to properly refect datafile examples.
The-inside-man Jul 14, 2021
199a35f
Remove unused import
The-inside-man Jul 14, 2021
4fa5d05
Cleaned up get functions till overall cleanup of code.
The-inside-man Jul 14, 2021
4356a4d
Merge branch 'master' into jbrown/oasis-7812
The-inside-man Jul 15, 2021
a273d11
Merge branch 'master' into jbrown/oasis-7812
The-inside-man Jul 15, 2021
c8d68f7
Added comments to stringify_conditions, added testcase to test string…
The-inside-man Jul 19, 2021
a9ac50c
Correct spelling of precedence
The-inside-man Jul 19, 2021
6ce98e3
Update comment to be more readable.
The-inside-man Jul 20, 2021
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update Formatting issues for lint
  • Loading branch information
The-inside-man committed Jul 2, 2021
commit f1bd5337cfd8bbe42b4abc9472e27e2704d9683a
59 changes: 37 additions & 22 deletions optimizely/optimizely_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,6 @@ def get_events(self):
"""
return self.events

def get_attributes(self):
""" Get the attributes associated with OptimizelyConfig

returns:
A list of attributes.
"""
return self.attributes

def get_events(self):
""" Get the events associated with OptimizelyConfig

returns:
A list of events.
"""
return self.events

def get_audiences(self):
""" Get the audiences associated with OptimizelyConfig

Expand Down Expand Up @@ -182,7 +166,8 @@ def __init__(self, project_config):

for old_audience in project_config.audiences:
# check if old_audience.id exists in new_audiences.id from typed_audiences
if len([new_audience for new_audience in typed_audiences if new_audience.get('id') == old_audience.get('id')]) == 0:
if len([new_audience for new_audience in typed_audiences
if new_audience.get('id') == old_audience.get('id')]) == 0:
if old_audience.get('id') == "$opt_dummy_audience":
continue
else:
Expand All @@ -195,7 +180,7 @@ def __init__(self, project_config):
for audience in self.audiences:
audiences_map[audience.get('id')] = audience.get('name')

# Updating each entities.Experiment found in the experiment_key_map
# Updating each OptimizelyExperiment based on the ID from entities.Experiment found in the experiment_key_map
for ent_exp in project_config.experiment_key_map.values():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This covers "experiment" rules. We also need to do the same to experiments in rollout ("delivery" rules) as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delivery Rules added to OptimizelyConfig and test cases to cover

experiments_by_key, experiments_by_id = self._get_experiments_maps()
try:
Expand All @@ -206,18 +191,39 @@ def __init__(self, project_config):
continue

def update_experiment(self, experiment, conditions, audiences_map):
'''
Gets an OptimizelyExperiment to update, conditions from
the corresponding entities.Experiment and an audiences_map
in the form of [id:name]

Updates the OptimizelyExperiment.audiences with a string
of conditions and audience names.
'''
audiences = self.replace_ids_with_names(conditions, audiences_map)
experiment.audiences = audiences

def replace_ids_with_names(self, conditions, audiences_map):
# Confirm where conditions are coming from...
if conditions != None:
'''
Gets conditions and audiences_map [id:name]

Returns:
a string of conditions with id's swapped with names
or None if no conditions found.

'''
if conditions is not None:
return self.stringify_conditions(conditions, audiences_map)
else:
return None

def lookup_name_from_id(self, audience_id, audiences_map):
'''
Gets and audience ID and audiences map

Returns:
The name corresponding to the ID
or None if not found
'''
name = ""
try:
name = audiences_map[audience_id]
Expand All @@ -227,6 +233,14 @@ def lookup_name_from_id(self, audience_id, audiences_map):
return name

def stringify_conditions(self, conditions, audiences_map):
'''
Gets a list of conditions from an entities.Experiment
and an audiences_map [id:name]

Returns:
A string of conditions and names for the provided
list of conditions.
'''
ARGS = ConditionOperatorTypes.operators
condition = ""
ret = "("
Expand All @@ -248,15 +262,16 @@ def stringify_conditions(self, conditions, audiences_map):
condition = conditions[i]
else:
if type(conditions[i]) == list:
# If the next item is a list, recursively call function on list
if i + 1 < length:
ret += self.stringify_conditions(conditions[i],
audiences_map) + ' ' + condition.upper() + ' '
else:
ret += self.stringify_conditions(conditions[i], audiences_map)
else:
# Handle ID's here - Lookup required
# Handle ID's here - Lookup name based on ID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no apostrophe

audience_name = self.lookup_name_from_id(conditions[i], audiences_map)
if audience_name != None:
if audience_name is not None:
if i + 1 < length:
ret += '"' + audience_name + '" ' + condition.upper() + ' '
else:
Expand Down
64 changes: 52 additions & 12 deletions tests/test_optimizely_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,26 @@ def setUp(self):
'environment_key': None,
'attributes': [{'key': 'test_attribute', 'id': '111094'}],
'events': [{'key': 'test_event', 'experimentIds': ['111127'], 'id': '111095'}],
'audiences': [{'name': 'Test attribute users 1', 'conditions': '["and", ["or", ["or", {"name": "test_attribute", "type": "custom_attribute", "value": "test_value_1"}]]]', 'id': '11154'}, {'name': 'Test attribute users 2', 'conditions': '["and", ["or", ["or", {"name": "test_attribute", "type": "custom_attribute", "value": "test_value_2"}]]]', 'id': '11159'}, {'name': 'Test attribute users 3', 'conditions': '["and", ["or", ["or", {"match": "exact", "name": "experiment_attr", "type": "custom_attribute", "value": "group_experiment"}]]]', 'id': '11160'}],
'audiences': [
{
'name': 'Test attribute users 1',
'conditions': '["and", ["or", ["or", '
'{"name": "test_attribute", "type": "custom_attribute", "value": "test_value_1"}]]]',
'id': '11154'
},
{
'name': 'Test attribute users 2',
'conditions': '["and", ["or", ["or", '
'{"name": "test_attribute", "type": "custom_attribute", "value": "test_value_2"}]]]',
'id': '11159'
},
{
'name': 'Test attribute users 3',
'conditions': "[\"and\", [\"or\", [\"or\", {\"match\": \"exact\", \"name\": \
\"experiment_attr\", \"type\": \"custom_attribute\", \"value\": \"group_experiment\"}]]]",
'id': '11160',
}
],
'experiments_map': {
'test_experiment2': {
'variations_map': {
Expand Down Expand Up @@ -899,7 +918,17 @@ def test_get_audiences(self):
'name': 'Test_Audience',
'id': '1234',
'conditions': [
'["and", ["or", ["or", {"name": "test_attribute", "type": "custom_attribute", "value": "test_value_1"}]]]'
["and",
["or",
["or",
{
"name": "test_attribute",
"type": "custom_attribute",
"value": "test_value_1"
}
]
]
]
]
}
]
Expand All @@ -909,30 +938,41 @@ def test_get_audiences(self):
'name': 'Test_Audience',
'id': '1234',
'conditions': [
'["and", ["or", ["or", {"name": "test_attribute", "type": "custom_attribute", "value": "test_value_1"}]]]'
["and",
["or",
["or",
{
"name": "test_attribute",
"type": "custom_attribute",
"value": "test_value_1"
}
]
]
]
]
}
]

self.assertEqual(expected_value, config.get_audiences())

def test_stringify_conditions(self):
'''
'''
Test to confirm converting from audienceConditions list to String represented conditions
Note* this also test lookup_name_from_id in OptimizelyConfig
Note* this also test lookup_name_from_id in OptimizelyConfig
'''

experiment = {'audienceConditions': ['and', ['or', '3468206642', '3988293898'], [
'or', '3988293899', '3468206646', '3468206647', '3468206644', '3468206643']], 'audienceIds': ['0'], 'forcedVariations': {}, 'id': '1323241598'}
'or', '3988293899', '3468206646', '3468206647', '3468206644', '3468206643']],
'audienceIds': ['0'], 'forcedVariations': {}, 'id': '1323241598'}

audience_conditions = experiment.get('audienceConditions')

audiences_map = {
'3468206642': 'US',
'3988293898': 'FEMALE',
'3988293899': 'MALE',
'3468206646': 'THEM',
'3468206647': 'ANYONE'
'3468206642': 'us',
'3988293898': 'female',
'3988293899': 'male',
'3468206646': 'them',
'3468206647': 'anyone'
}

config = optimizely_config.OptimizelyConfig(
Expand All @@ -949,7 +989,7 @@ def test_stringify_conditions(self):

result = config_service.stringify_conditions(audience_conditions, audiences_map)

expected_result = '(("US" OR "FEMALE") AND ("MALE" OR "THEM" OR "ANYONE" OR "3468206644" OR "3468206643"))'
expected_result = '(("us" OR "female") AND ("male" OR "them" OR "anyone" OR "3468206644" OR "3468206643"))'

self.assertEqual(result, expected_result)

Expand Down