Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit 42dc863

Browse files
authored
OneOf operator should be case insensitive (#12)
1 parent 566bee2 commit 42dc863

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

eppo_client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from eppo_client.http_client import HttpClient, SdkParams
1111
from eppo_client.read_write_lock import ReadWriteLock
1212

13-
__version__ = "1.0.3"
13+
__version__ = "1.0.4"
1414

1515
__client: Optional[EppoClient] = None
1616
__lock = ReadWriteLock()

eppo_client/rules.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,13 @@ def evaluate_condition(subject_attributes: dict, condition: Condition) -> bool:
4646
if condition.operator == OperatorType.MATCHES:
4747
return bool(re.match(condition.value, str(subject_value)))
4848
elif condition.operator == OperatorType.ONE_OF:
49-
return str(subject_value) in condition.value
49+
return str(subject_value).lower() in [
50+
value.lower() for value in condition.value
51+
]
5052
elif condition.operator == OperatorType.NOT_ONE_OF:
51-
return str(subject_value) not in condition.value
53+
return str(subject_value).lower() not in [
54+
value.lower() for value in condition.value
55+
]
5256
else:
5357
return isinstance(
5458
subject_value, numbers.Number

test/rules_test.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,32 @@ def test_one_of_operator_with_boolean():
6666
assert matches_any_rule({"enabled": False}, [notOneOfRule]) is True
6767

6868

69+
def test_one_of_operator_case_insensitive():
70+
oneOfRule = Rule(
71+
conditions=[
72+
Condition(
73+
operator=OperatorType.ONE_OF, value=["1Ab", "Ron"], attribute="name"
74+
)
75+
]
76+
)
77+
assert matches_any_rule({"name": "ron"}, [oneOfRule]) is True
78+
assert matches_any_rule({"name": "1AB"}, [oneOfRule]) is True
79+
80+
81+
def test_not_one_of_operator_case_insensitive():
82+
notOneOf = Rule(
83+
conditions=[
84+
Condition(
85+
operator=OperatorType.NOT_ONE_OF,
86+
value=["bbB", "1.1.ab"],
87+
attribute="name",
88+
)
89+
]
90+
)
91+
assert matches_any_rule({"name": "BBB"}, [notOneOf]) is False
92+
assert matches_any_rule({"name": "1.1.AB"}, [notOneOf]) is False
93+
94+
6995
def test_one_of_operator_with_string():
7096
oneOfRule = Rule(
7197
conditions=[

0 commit comments

Comments
 (0)