Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/examples/openfeature…
Browse files Browse the repository at this point in the history
…_react/react-app/vite-5.4.5
  • Loading branch information
kodiakhq[bot] authored Sep 17, 2024
2 parents 6cdec25 + d3bcf52 commit 59a0210
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def after(
self._event_queue.append(feature_event)

def error(self, hook_context: HookContext, exception: Exception, hints: dict):
if self._options.disable_data_collection or details.reason != Reason.CACHED:
# we don't collect data if the data collection is disabled or if the flag is not cached
if self._options.disable_data_collection:
# we don't collect data if the data collection is disabled
return

feature_event = FeatureEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from openfeature.exception import ErrorCode
from openfeature.flag_evaluation import Reason, FlagEvaluationDetails

from gofeatureflag_python_provider.data_collector_hook import DataCollectorHook
from gofeatureflag_python_provider.options import GoFeatureFlagOptions
from gofeatureflag_python_provider.provider import GoFeatureFlagProvider

Expand Down Expand Up @@ -588,6 +589,27 @@ def test_should_not_call_data_collector_if_not_having_cache(mock_request: Mock):
assert mock_request.call_count == 1


def test_hook_error():
def _create_hook_context():
ctx = Mock()
eval_ctx = Mock()
eval_ctx.attributes = {"anonymous": True}
eval_ctx.targeting_key = "test_user_key"
ctx.evaluation_context = eval_ctx
ctx.flag_key = "test_key"
return ctx

hook = DataCollectorHook(
options=GoFeatureFlagOptions(endpoint="http://test.com"), http_client=Mock()
)
hook.error(
hook_context=_create_hook_context(),
exception=Exception("test exception raised"),
hints={},
)
assert len(hook._event_queue) == 1


def _read_mock_file(flag_key: str) -> str:
# This hacky if is here to make test run inside pycharm and from the root of the project
if os.getcwd().endswith("/tests"):
Expand Down

0 comments on commit 59a0210

Please sign in to comment.