Skip to content

Commit 01a830c

Browse files
Merge pull request #43 from harness/FFM-4813
FFM-4813
2 parents 52a2a71 + f9c8723 commit 01a830c

File tree

6 files changed

+51
-11
lines changed

6 files changed

+51
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Python SDK For Harness Feature Flags
1616
Use this README to get started with our Feature Flags (FF) SDK for Python. This guide outlines the basics of getting started with the SDK and provides a full code sample for you to try out.
1717
This sample doesn’t include configuration options, for in depth steps and configuring the SDK, for example, disabling streaming or using our Relay Proxy, see the [Python SDK Reference](https://ngdocs.harness.io/article/hwoxb6x2oe-python-sdk-reference).
1818

19-
For a sample FF Python SDK project, see our test [test Golang project](examples/getting_started/getting_started.py).
19+
For a sample FF Python SDK project, see our test [test python project](examples/getting_started/getting_started.py).
2020

2121
![FeatureFlags](https://github.com/harness/ff-python-server-sdk/raw/main/docs/images/ff-gui.png)
2222

featureflags/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
__author__ = """Enver Bisevac"""
44
__email__ = "enver.bisevac@harness.io"
5-
__version__ = '1.1.2'
5+
__version__ = '1.1.3'

featureflags/evaluations/evaluator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@ def _evaluate_clauses(self, clauses: Union[Unset, Clauses],
163163
target: Target) -> bool:
164164
if not isinstance(clauses, Unset):
165165
for clause in clauses:
166-
if not self._evaluate_clause(clause, target):
167-
log.debug("Unsuccessful evaluation of clause %s", clause)
168-
return False
166+
if self._evaluate_clause(clause, target):
167+
log.debug("Successful evaluation of clause %s", clause)
168+
return True
169169
log.debug("All clauses %s evaluated", clauses)
170-
return True
170+
return False
171171

172172
def _evaluate_rule(self, rule: ServingRule, target: Target) -> bool:
173173
return self._evaluate_clauses(rule.clauses, target)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.1.2
2+
current_version = 1.1.3
33
commit = True
44
tag = True
55

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@
5656
test_suite="tests",
5757
tests_require=test_requirements,
5858
url="https://github.com/drone/ff-python-server-sdk",
59-
version='1.1.2',
59+
version='1.1.3',
6060
zip_safe=False,
6161
)

tests/unit/test_evaluator.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from featureflags.evaluations.auth_target import Target
44
from featureflags.evaluations.clause import Clause
5-
from featureflags.evaluations.constants import EQUAL_OPERATOR
5+
from featureflags.evaluations.constants import EQUAL_OPERATOR, STARTS_WITH_OPERATOR
66
from featureflags.evaluations.distribution import Distribution
77
from featureflags.evaluations.enum import FeatureState
88
from featureflags.evaluations.evaluator import Evaluator
@@ -58,7 +58,6 @@ def distribution_by_email():
5858

5959
@pytest.fixture
6060
def feature(variations):
61-
6261
default_serve = Serve(variation=TRUE)
6362

6463
return FeatureConfig(
@@ -75,7 +74,6 @@ def feature(variations):
7574

7675
@pytest.fixture
7776
def segment(target):
78-
7977
return Segment(
8078
identifier="beta",
8179
name="Beta users",
@@ -164,6 +162,48 @@ def test_evaluate_clause(data_provider, target):
164162
assert got is True
165163

166164

165+
def test_evaluate_clauses(data_provider, target):
166+
evaluator = Evaluator(data_provider)
167+
clause1 = Clause(
168+
id="",
169+
attribute="identifier",
170+
op=EQUAL_OPERATOR,
171+
values=[target.identifier]
172+
)
173+
174+
clause2 = Clause(
175+
id="",
176+
attribute="name",
177+
op=EQUAL_OPERATOR,
178+
values=[target.name]
179+
)
180+
181+
clause3 = Clause(
182+
id="",
183+
attribute="name",
184+
op=EQUAL_OPERATOR,
185+
values=["Not John"]
186+
)
187+
188+
clause4 = Clause(
189+
id="",
190+
attribute="name",
191+
op=STARTS_WITH_OPERATOR,
192+
values=["Not John"]
193+
)
194+
195+
testcases = [
196+
{"scenario": "Evaluate clauses with no clauses", "input": [], "expected": False},
197+
{"scenario": "Evaluate clauses with 2 Clauses both will match", "input": [clause1, clause2], "expected": True},
198+
{"scenario": "Evaluate clauses with 2 Clauses only 1 match", "input": [clause1, clause3], "expected": True},
199+
{"scenario": "Evaluate clauses with 2 Clauses but no match", "input": [clause3, clause4], "expected": False}
200+
]
201+
202+
for tc in testcases:
203+
actual = evaluator._evaluate_clauses(tc["input"], target)
204+
assert actual is tc["expected"]
205+
206+
167207
def test_evaluate_rules(data_provider, target):
168208
evaluator = Evaluator(data_provider)
169209

0 commit comments

Comments
 (0)