Skip to content
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

feat: get_optimizely_config API #226

Merged
merged 17 commits into from
Jan 6, 2020
Merged

feat: get_optimizely_config API #226

merged 17 commits into from
Jan 6, 2020

Conversation

oakbani
Copy link
Contributor

@oakbani oakbani commented Dec 6, 2019

Summary

Adds support for get_optimizely_config public API.

Test plan

  • Tested manually with FSC OptimizelyConfig tests.
  • Added simple Unit tests in test_optimizely.py

Issues

  • OASIS-5464

@coveralls
Copy link

Coverage Status

Coverage decreased (-4.2%) to 93.422% when pulling 4deaf60 on oakbani/optimizely-config into 9fee8ff on master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-4.2%) to 93.422% when pulling 4deaf60 on oakbani/optimizely-config into 9fee8ff on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-4.2%) to 93.422% when pulling 4deaf60 on oakbani/optimizely-config into 9fee8ff on master.

@coveralls
Copy link

coveralls commented Dec 6, 2019

Coverage Status

Coverage increased (+0.1%) to 97.741% when pulling a95c669 on oakbani/optimizely-config into 0a6086c on master.

@oakbani oakbani marked this pull request as ready for review December 9, 2019 14:23
@oakbani oakbani requested a review from a team as a code owner December 9, 2019 14:23
@oakbani oakbani changed the title WIP - feat: get_optimizely_config API feat: get_optimizely_config API Dec 9, 2019
@oakbani oakbani requested a review from jaeopt December 9, 2019 14:27

def __init__(self, project_config):
"""
Arguments:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. Args.



class OptimizelyVariable(object):
def __init__(self, id, key, type, value):
Copy link
Contributor

Choose a reason for hiding this comment

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

type is a keyword and shadows a built in name. Would recommend naming this variable something else. May be variable_type

Returns:
Optimizely Config instance.
"""
self._create_lookup_maps()
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems awkward that a get is calling a create.

def _get_variables_map(self, variation, experiment):
""" Gets variables map for given variation and experiment.

Arguments:
Copy link
Contributor

Choose a reason for hiding this comment

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

Args and not Arguments. Apply this feedback throughout this PR.

self.groups = project_config.groups
self.revision = project_config.revision

def get_optimizely_config(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. Not sure if the naming has to be get_optimizely_config, but OptimizelyConfigService.get_optimizely_config has too much redundant information in it.

Something as simple as get_config may suffice here. cc @jaeopt

opt_obj = optimizely.Optimizely(json.dumps(self.config_dict_with_features))
opt_config = opt_obj.get_optimizely_config()
self.assertIsInstance(opt_config, optimizely_config.OptimizelyConfig)

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add tests for OptConfig contents validation as well?

Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

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

It looks great! I suggest to add more unit tests for OptConfig contents validation.

@oakbani
Copy link
Contributor Author

oakbani commented Dec 10, 2019

@jaeopt Have added unit tests. Please take a look.

@@ -182,14 +182,12 @@ def setUp(self, config_dict='config_dict'):
{
'id': '122239',
'key': 'control',
'featureEnabled': True,
'variables': [{'id': '155551', 'value': '42.42'}],
'variables': [],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed these since this is not a feature experiment so shouldn't have these props.

class OptimizelyConfigService(object):
""" Class encapsulating methods to be used in creating instance of OptimizelyConfig. """

def __init__(self, project_config):
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to check instance of ProjectConfig

Copy link
Contributor Author

@oakbani oakbani Dec 12, 2019

Choose a reason for hiding this comment

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

I don't expect to be used elsewhere. And in the main class, we validate project_config before using OptimizelyService. I can still validate if you so, but will have to keep a validity flag so that get_config returns nil and does not break.

Copy link
Contributor

Choose a reason for hiding this comment

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

my suggestion is to validate but @aliabbasrizvi will you suggest for validation here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with @msohailhussain, we should validate here.


self.exp_id_to_feature_map = {}
for feature in self.feature_flags:
for id in feature['experimentIds']:
Copy link
Contributor

@msohailhussain msohailhussain Dec 10, 2019

Choose a reason for hiding this comment

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

I would instead of id use experimentId


self.feature_key_variable_key_to_variable_map = {}
self.feature_key_variable_id_to_variable_map = {}
for feature in self.feature_flags:
Copy link
Contributor

Choose a reason for hiding this comment

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

am unable to find the difference between this feature_flags loop and at line 86. Can't we use one loop only?

Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

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

LGTM

self._create_lookup_maps()

def get_config(self):
""" Returns instance of OptimizelyConfig
Copy link
Contributor

Choose a reason for hiding this comment

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

gets

Copy link
Contributor

@aliabbasrizvi aliabbasrizvi left a comment

Choose a reason for hiding this comment

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

Mostly looks good. Comments could use some clarity.

self.feature_key_variable_key_to_variable_map[feature['key']] = variables_key_map
self.feature_key_variable_id_to_variable_map[feature['key']] = variables_id_map

def _get_variables_map(self, variation, experiment):
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. I personally prefer arranging this as self, experiment, variation to honor the parent child relationship between experiments and variations.

""" Gets variables map for given variation and experiment.

Args:
variation dict
Copy link
Contributor

Choose a reason for hiding this comment

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

This is very vague. Dict consisting of what?

@zashraf1985
Copy link
Contributor

@mikeng13 This is approved and i dont have rights to merge. Can you help.

@jaeopt jaeopt merged commit 1785902 into master Jan 6, 2020
@oakbani oakbani deleted the oakbani/optimizely-config branch January 13, 2020 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants