Skip to content

Commit

Permalink
parametrize some provider test
Browse files Browse the repository at this point in the history
  • Loading branch information
nickybondarenko committed Sep 12, 2023
1 parent 2856f8d commit ccef02e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 32 deletions.
Empty file added tests/conftest.py
Empty file.
32 changes: 0 additions & 32 deletions tests/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,38 +76,6 @@ def test_resolve_string_with_dot_notation_request_payload(self):
EXPECTED_REQUEST_PAYLOAD,
)

def test_apply_configurable(self):
ctx = EvaluationContext(targeting_key="meh")
apply_false_provider = ConfidenceOpenFeatureProvider(
client_secret="test", apply_on_resolve=False
)
apply_true_provider = ConfidenceOpenFeatureProvider(
client_secret="test", apply_on_resolve=True
)
with requests_mock.Mocker() as mock:
mock.post(
"https://resolver.eu.confidence.dev/v1/flags:resolve",
json=SUCCESSFUL_STRING_FLAG_RESOLVE,
)

apply_false_provider.resolve_string_details(
flag_key="test-flag.color",
default_value="yellow",
evaluation_context=ctx,
)

last_request = mock.request_history[-1]
self.assertEqual(last_request.json()["apply"], False)

apply_true_provider.resolve_string_details(
flag_key="test-flag.color",
default_value="yellow",
evaluation_context=ctx,
)

last_request = mock.request_history[-1]
self.assertEqual(last_request.json()["apply"], True)

if __name__ == "__main__":
unittest.main()

Expand Down
33 changes: 33 additions & 0 deletions tests/test_provider_parametrized.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pytest
import requests_mock
from open_feature.evaluation_context.evaluation_context import EvaluationContext

from provider.provider import ConfidenceOpenFeatureProvider
from tests.test_provider import SUCCESSFUL_STRING_FLAG_RESOLVE


@pytest.mark.parametrize(
"apply_on_resolve",
(
(True, False)
)
)
def test_apply_configurable(apply_on_resolve):
ctx = EvaluationContext(targeting_key="meh")
apply_provider = ConfidenceOpenFeatureProvider(
client_secret="test", apply_on_resolve=apply_on_resolve
)
with requests_mock.Mocker() as mock:
mock.post(
"https://resolver.eu.confidence.dev/v1/flags:resolve",
json=SUCCESSFUL_STRING_FLAG_RESOLVE,
)

apply_provider.resolve_string_details(
flag_key="test-flag.color",
default_value="yellow",
evaluation_context=ctx,
)

last_request = mock.request_history[-1]
assert last_request.json()["apply"] == apply_on_resolve

0 comments on commit ccef02e

Please sign in to comment.