Skip to content

Commit

Permalink
feat: add datafile accessor (#275)
Browse files Browse the repository at this point in the history
* feat: add datafile accessor

* refactor: fetch datafile from project_config in OptimizelyConfigService constructor

* test: fix existing test to accommodate new config format due to datafile addition

* test: replace deprecated assert functions to eliminate warnings

* test: add tests for datafile accessor methods

* style: fix indent and spacing of test comments

* style: reorder datafile accessor method to more appropriate location

* fix: revert back to Regexp b/c python2.7 and pypy were failing

* docs: modify comment and incorporate changes

* docs: update method comment
  • Loading branch information
pthompson127 committed Jul 1, 2020
1 parent 1bf5a89 commit ddf06ed
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 113 deletions.
14 changes: 12 additions & 2 deletions optimizely/optimizely_config.py
Expand Up @@ -17,10 +17,19 @@


class OptimizelyConfig(object):
def __init__(self, revision, experiments_map, features_map):
def __init__(self, revision, experiments_map, features_map, datafile=None):
self.revision = revision
self.experiments_map = experiments_map
self.features_map = features_map
self.datafile = datafile

def get_datafile(self):
""" Get the datafile associated with OptimizelyConfig.
Returns:
A JSON string representation of the environment's datafile.
"""
return self.datafile


class OptimizelyExperiment(object):
Expand Down Expand Up @@ -68,6 +77,7 @@ def __init__(self, project_config):
self.is_valid = False
return

self._datafile = project_config.to_datafile()
self.experiments = project_config.experiments
self.feature_flags = project_config.feature_flags
self.groups = project_config.groups
Expand All @@ -88,7 +98,7 @@ def get_config(self):
experiments_key_map, experiments_id_map = self._get_experiments_maps()
features_map = self._get_features_map(experiments_id_map)

return OptimizelyConfig(self.revision, experiments_key_map, features_map)
return OptimizelyConfig(self.revision, experiments_key_map, features_map, self._datafile)

def _create_lookup_maps(self):
""" Creates lookup maps to avoid redundant iteration of config objects. """
Expand Down

0 comments on commit ddf06ed

Please sign in to comment.