Skip to content

Commit

Permalink
fix: Account for inversion in NOT_IN operator where context_value is …
Browse files Browse the repository at this point in the history
…None (#235)
  • Loading branch information
brtkwr authored Feb 24, 2023
1 parent 6703bf8 commit 8e2db32
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion UnleashClient/constraints/Constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def apply(self, context: dict = None) -> bool:
else:
# This is a special case in the client spec - so it's getting it's own handler here
if self.operator is ConstraintOperators.NOT_IN:
return True
constraint_check = True

except Exception as excep: # pylint: disable=broad-except
LOGGER.info("Could not evaluate context %s! Error: %s", self.context_name, excep)
Expand Down
11 changes: 10 additions & 1 deletion tests/unit_tests/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def constraint_NOTIN():
yield Constraint(mock_constraints.CONSTRAINT_DICT_NOTIN)



def test_constraint_IN_match(constraint_IN):
constraint = constraint_IN
context = {
Expand All @@ -39,6 +38,16 @@ def test_constraint_IN_missingcontext(constraint_IN):
assert not constraint.apply({})


def test_constraint_NOTIN_missingcontext(constraint_NOTIN):
constraint = constraint_NOTIN
assert constraint.apply({})


def test_constraint_NOTIN_missingcontext_inversion():
constraint = Constraint(mock_constraints.CONSTRAINT_DICT_NOTIN_INVERT)
assert not constraint.apply({})


def test_constraint_NOTIN_match(constraint_NOTIN):
constraint = constraint_NOTIN
context = {
Expand Down
13 changes: 13 additions & 0 deletions tests/utilities/mocks/mock_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@
}


CONSTRAINT_DICT_NOTIN_INVERT = \
{
"contextName": "appName",
"operator": "NOT_IN",
"values": [
"test",
"test2"
],
"inverted": True
}


CONSTRAINT_DICT_STR_INVERT = \
{
"contextName": "customField",
Expand All @@ -29,6 +41,7 @@
"inverted": True
}


CONSTRAINT_DICT_STR_CONTAINS_CI = \
{
"contextName": "customField",
Expand Down

0 comments on commit 8e2db32

Please sign in to comment.