Skip to content

Implement get_feature_variable and create unit tests #191

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 12 commits into from
Jul 24, 2019
20 changes: 19 additions & 1 deletion optimizely/optimizely.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ def _get_feature_variable_for_type(self, feature_key, variable_key, variable_typ
if not variable:
return None

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

return enabled_features

def get_feature_variable(self, feature_key, variable_key, user_id, attributes=None):
""" Returns value for a variable attached to a feature flag.

Args:
feature_key: Key of the feature whose variable's value is being accessed.
variable_key: Key of the variable whose value is to be accessed.
user_id: ID for user.
attributes: Dict representing user attributes.

Returns:
Value of the variable. None if:
- Feature key is invalid.
- Variable key is invalid.
"""

return self._get_feature_variable_for_type(feature_key, variable_key, None, user_id, attributes)

def get_feature_variable_boolean(self, feature_key, variable_key, user_id, attributes=None):
""" Returns value for a certain boolean variable attached to a feature flag.

Expand Down
Loading