Skip to content

Delivery rules correction for proper rollout key #351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion optimizely/optimizely_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def _get_delivery_rules(self, rollouts, rollout_id):
audiences_map[optly_audience.id] = optly_audience.name

# Get the experiments_map for that rollout
experiments = rollout.get('experiments_map')
experiments = rollout.get('experiments')
if experiments:
for experiment in experiments:
optly_exp = OptimizelyExperiment(
Expand Down
210 changes: 204 additions & 6 deletions tests/test_optimizely_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,53 @@ def setUp(self):
'experiments_map': {

},
'delivery_rules': [],
'delivery_rules': [
{
'id': '211127',
'key': '211127',
'variations_map': {
'211129': {
'id': '211129',
'key': '211129',
'feature_enabled': True,
'variables_map': {}
},
'211229': {
'id': '211229',
'key': '211229',
'feature_enabled': False,
'variables_map': {}
}
},
'audiences': ''
},
{
'id': '211137',
'key': '211137',
'variations_map': {
'211139': {
'id': '211139',
'key': '211139',
'feature_enabled': True,
'variables_map': {}
}
},
'audiences': ''
},
{
'id': '211147',
'key': '211147',
'variations_map': {
'211149': {
'id': '211149',
'key': '211149',
'feature_enabled': True,
'variables_map': {}
}
},
'audiences': ''
}
],
'experiment_rules': [],
'id': '91112',
'key': 'test_feature_in_rollout'
Expand Down Expand Up @@ -704,7 +750,53 @@ def setUp(self):
'audiences': ''
}
},
'delivery_rules': [],
'delivery_rules': [
{
'id': '211127',
'key': '211127',
'variations_map': {
'211129': {
'id': '211129',
'key': '211129',
'feature_enabled': True,
'variables_map': {}
},
'211229': {
'id': '211229',
'key': '211229',
'feature_enabled': False,
'variables_map': {}
}
},
'audiences': ''
},
{
'id': '211137',
'key': '211137',
'variations_map': {
'211139': {
'id': '211139',
'key': '211139',
'feature_enabled': True,
'variables_map': {}
}
},
'audiences': ''
},
{
'id': '211147',
'key': '211147',
'variations_map': {
'211149': {
'id': '211149',
'key': '211149',
'feature_enabled': True,
'variables_map': {}
}
},
'audiences': ''
}
],
'experiment_rules': [
{
'id': '32223',
Expand Down Expand Up @@ -780,7 +872,53 @@ def setUp(self):
'audiences': '"Test attribute users 3"'
}
},
'delivery_rules': [],
'delivery_rules': [
{
'id': '211127',
'key': '211127',
'variations_map': {
'211129': {
'id': '211129',
'key': '211129',
'feature_enabled': True,
'variables_map': {}
},
'211229': {
'id': '211229',
'key': '211229',
'feature_enabled': False,
'variables_map': {}
}
},
'audiences': ''
},
{
'id': '211137',
'key': '211137',
'variations_map': {
'211139': {
'id': '211139',
'key': '211139',
'feature_enabled': True,
'variables_map': {}
}
},
'audiences': ''
},
{
'id': '211147',
'key': '211147',
'variations_map': {
'211149': {
'id': '211149',
'key': '211149',
'feature_enabled': True,
'variables_map': {}
}
},
'audiences': ''
}
],
'experiment_rules': [
{
'id': '42222',
Expand Down Expand Up @@ -876,7 +1014,53 @@ def setUp(self):
'audiences': '"Test attribute users 3"'
}
},
'delivery_rules': [],
'delivery_rules': [
{
'id': '211127',
'key': '211127',
'variations_map': {
'211129': {
'id': '211129',
'key': '211129',
'feature_enabled': True,
'variables_map': {}
},
'211229': {
'id': '211229',
'key': '211229',
'feature_enabled': False,
'variables_map': {}
}
},
'audiences': ''
},
{
'id': '211137',
'key': '211137',
'variations_map': {
'211139': {
'id': '211139',
'key': '211139',
'feature_enabled': True,
'variables_map': {}
}
},
'audiences': ''
},
{
'id': '211147',
'key': '211147',
'variations_map': {
'211149': {
'id': '211149',
'key': '211149',
'feature_enabled': True,
'variables_map': {}
}
},
'audiences': ''
}
],
'experiment_rules': [
{
'id': '111134',
Expand Down Expand Up @@ -1400,7 +1584,8 @@ def test_stringify_audience_conditions_all_cases(self):
["not", ["and", "1", "2"]],
["or", "1", "100000"],
["and", "and"],
["and"]
["and"],
["and", ["or", "1", ["and", "2", "3"]], ["and", "11", ["or", "12", "3"]]]
]

audiences_output = [
Expand All @@ -1417,7 +1602,8 @@ def test_stringify_audience_conditions_all_cases(self):
'NOT ("us" AND "female")',
'"us" OR "100000"',
'',
''
'',
'("us" OR ("female" AND "adult")) AND ("fr" AND ("male" OR "adult"))'
]

config_service = optimizely_config.OptimizelyConfigService(config)
Expand Down Expand Up @@ -1466,3 +1652,15 @@ def test_get_variations_from_experiments_map(self):
self.assertEqual(variation.key, 'all_traffic_variation')
else:
self.assertEqual(variation.key, 'no_traffic_variation')

def test_get_delivery_rules(self):
expected_features_map_dict = self.expected_config.get('features_map')
actual_features_map_dict = self.actual_config_dict.get('features_map')
actual_features_map = self.actual_config.features_map

for optly_feature in actual_features_map.values():
self.assertIsInstance(optly_feature, optimizely_config.OptimizelyFeature)
for delivery_rule in optly_feature.delivery_rules:
self.assertIsInstance(delivery_rule, optimizely_config.OptimizelyExperiment)

self.assertEqual(expected_features_map_dict, actual_features_map_dict)