8000 feat: add datafile accessor (#275) · optimizely/python-sdk@ddf06ed · GitHub
[go: up one dir, main page]

Skip to content

Commit ddf06ed

Browse files
authored
feat: add datafile accessor (#275)
* 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
1 parent 1bf5a89 commit ddf06ed

File tree

4 files changed

+157
-113
lines changed

4 files changed

+157
-113 8000
lines changed

optimizely/optimizely_config.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,19 @@
1717

1818

1919
class OptimizelyConfig(object):
20-
def __init__(self, revision, experiments_map, features_map):
20+
def __init__(self, revision, experiments_map, features_map, datafile=None):
2121
self.revision = revision
2222
self.experiments_map = experiments_map
2323
self.features_map = features_map
24+
self.datafile = datafile
25+
26+
def get_datafile(self):
27+
""" Get the datafile associated with OptimizelyConfig.
28+
29+
Returns:
30+
A JSON string representation of the environment's datafile.
31+
"""
32+
return self.datafile
2433

2534

2635
class OptimizelyExperiment(object):
@@ -68,6 +77,7 @@ def __init__(self, project_config):
6877
self.is_valid = False
6978
return
7079

80+
self._datafile = project_config.to_datafile()
7181
self.experiments = project_config.experiments
7282
self.feature_flags = project_config.feature_flags
7383
self.groups = project_config.groups
@@ -88,7 +98,7 @@ def get_config(self):
8898
experiments_key_map, experiments_id_map = self._get_experiments_maps()
8999
features_map = self._get_features_map(experiments_id_map)
90100

91-
return OptimizelyConfig(self.revision, experiments_key_map, features_map)
101+
return OptimizelyConfig(self.revision, experiments_key_map, features_map, self._datafile)
92102

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

0 commit comments

Comments
 (0)
0