Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions featureprobe/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class User:
Usually corresponding to a user of your application.
"""

def __init__(self, attrs: Dict[str, str] = None,
def __init__(self, attrs: Dict[str, any] = None,
stable_rollout_key: str = None):
"""Creates a new FeatureProbe User.

Expand All @@ -33,9 +33,9 @@ def __init__(self, attrs: Dict[str, str] = None,
self._key = stable_rollout_key
else:
self._key = str(int(time.time() * 10**6))
self._attrs = attrs or {}
self._attrs = {k: str(v) for k, v in (attrs or {}).items()}

def __setitem__(self, key: str, value: str):
def __setitem__(self, key: str, value: any):
"""Alias for :func:`~featureprobe.User.with_attr`.

Usage::
Expand All @@ -45,7 +45,7 @@ def __setitem__(self, key: str, value: str):
>>> user.with_attr('key1', 'value1')
>>> user['key2'] = 'value2'
"""
self._attrs[key] = value
self._attrs[key] = str(value)

def __getitem__(self, attr: str):
"""Gets the value of specified attribute.
Expand Down Expand Up @@ -92,7 +92,7 @@ def attrs(self, attrs: Dict[str, str]):
"""Sets (replace the original attributes) multiple attributes to a FeatureProbe User"""
self._attrs = attrs

def with_attr(self, key: str, value: str) -> "User":
def with_attr(self, key: str, value: any) -> "User":
"""Adds an attribute to the user.

:param key: Attribute key / name.
Expand All @@ -104,7 +104,7 @@ def with_attr(self, key: str, value: str) -> "User":
>>> import featureprobe as fp
>>> user = fp.User('unique id').with_attr('key1', 'value1').with_attr('key2', 'value2')
"""
self._attrs[key] = value
self._attrs[key] = str(value)
return self

def has_attr(self, attr: str) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion tests/condition_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_string_is_one_of():
condition.objects = ['12345', '987654', '665544', '13797347245']
condition.predicate = fp.model.StringPredicate.IS_ONE_OF

user['userId'] = '12345'
user['userId'] = 12345 # should auto convert to string
assert condition.match_objects(user, segments)

user['userId'] = '999999'
Expand Down