Skip to content

Commit e9abbac

Browse files
Implement get_feature_variable and create unit tests (#191)
1 parent 968a54e commit e9abbac

File tree

2 files changed

+677
-38
lines changed

2 files changed

+677
-38
lines changed

Diff for: optimizely/optimizely.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ def _get_feature_variable_for_type(self, feature_key, variable_key, variable_typ
203203
if not variable:
204204
return None
205205

206-
# Return None if type differs
206+
# For non-typed method, use type of variable; else, return None if type differs
207+
variable_type = variable_type or variable.type
207208
if variable.type != variable_type:
208209
self.logger.warning(
209210
'Requested variable type "%s", but variable is of type "%s". '
@@ -513,6 +514,23 @@ def get_enabled_features(self, user_id, attributes=None):
513514

514515
return enabled_features
515516

517+
def get_feature_variable(self, feature_key, variable_key, user_id, attributes=None):
518+
""" Returns value for a variable attached to a feature flag.
519+
520+
Args:
521+
feature_key: Key of the feature whose variable's value is being accessed.
522+
variable_key: Key of the variable whose value is to be accessed.
523+
user_id: ID for user.
524+
attributes: Dict representing user attributes.
525+
526+
Returns:
527+
Value of the variable. None if:
528+
- Feature key is invalid.
529+
- Variable key is invalid.
530+
"""
531+
532+
return self._get_feature_variable_for_type(feature_key, variable_key, None, user_id, attributes)
533+
516534
def get_feature_variable_boolean(self, feature_key, variable_key, user_id, attributes=None):
517535
""" Returns value for a certain boolean variable attached to a feature flag.
518536

0 commit comments

Comments
 (0)