Skip to content

Commit

Permalink
fix(flagd): object resolution for RPC and Object types (#102)
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Schrottner <[email protected]>
  • Loading branch information
aepfli committed Nov 18, 2024
1 parent 481b477 commit d0c5784
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 88 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import typing

import grpc
from google.protobuf.json_format import MessageToDict
from google.protobuf.struct_pb2 import Struct

from openfeature.evaluation_context import EvaluationContext
Expand Down Expand Up @@ -72,7 +73,7 @@ def resolve_object_details(
) -> FlagResolutionDetails[typing.Union[dict, list]]:
return self._resolve(key, FlagType.OBJECT, default_value, evaluation_context)

def _resolve(
def _resolve( # noqa: PLR0915
self,
flag_key: str,
flag_type: FlagType,
Expand All @@ -87,26 +88,33 @@ def _resolve(
flag_key=flag_key, context=context
)
response = self.stub.ResolveBoolean(request, **call_args)
value = response.value
elif flag_type == FlagType.STRING:
request = schema_pb2.ResolveStringRequest( # type:ignore[attr-defined]
flag_key=flag_key, context=context
)
response = self.stub.ResolveString(request, **call_args)
value = response.value
elif flag_type == FlagType.OBJECT:
request = schema_pb2.ResolveObjectRequest( # type:ignore[attr-defined]
flag_key=flag_key, context=context
)
response = self.stub.ResolveObject(request, **call_args)
value = MessageToDict(response, preserving_proto_field_name=True)[
"value"
]
elif flag_type == FlagType.FLOAT:
request = schema_pb2.ResolveFloatRequest( # type:ignore[attr-defined]
flag_key=flag_key, context=context
)
response = self.stub.ResolveFloat(request, **call_args)
value = response.value
elif flag_type == FlagType.INTEGER:
request = schema_pb2.ResolveIntRequest( # type:ignore[attr-defined]
flag_key=flag_key, context=context
)
response = self.stub.ResolveInt(request, **call_args)
value = response.value
else:
raise ValueError(f"Unknown flag type: {flag_type}")

Expand All @@ -124,7 +132,7 @@ def _resolve(

# Got a valid flag and valid type. Return it.
return FlagResolutionDetails(
value=response.value,
value=value,
reason=response.reason,
variant=response.variant,
)
Expand Down
18 changes: 0 additions & 18 deletions providers/openfeature-provider-flagd/tests/e2e/test_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,6 @@ def test_flag_change_event():
"""not implemented"""


@pytest.mark.skip(reason="issue #102")
@scenario(
"../../spec/specification/assets/gherkin/evaluation.feature",
"Resolves object value",
)
def test_resolves_object_value():
"""not implemented"""


@pytest.mark.skip(reason="issue #102")
@scenario(
"../../spec/specification/assets/gherkin/evaluation.feature",
"Resolves object details",
)
def test_resolves_object_details():
"""not implemented"""


scenarios(
"../../test-harness/gherkin/flagd.feature",
"../../test-harness/gherkin/flagd-json-evaluator.feature",
Expand Down

This file was deleted.

This file was deleted.

6 changes: 4 additions & 2 deletions providers/openfeature-provider-flagd/tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ def test_file_load_errors(file_name: str):
],
)
def test_json_logic_parse_errors(file_name: str):
path = os.path.abspath(os.path.join(os.path.dirname(__file__), "./flags/"))
client = create_client(
FlagdProvider(
resolver_type=ResolverType.IN_PROCESS,
offline_flag_source_path=f"tests/flags/{file_name}",
offline_flag_source_path=f"{path}/{file_name}",
)
)

Expand All @@ -71,10 +72,11 @@ def test_json_logic_parse_errors(file_name: str):


def test_flag_disabled():
path = os.path.abspath(os.path.join(os.path.dirname(__file__), "./flags/"))
client = create_client(
FlagdProvider(
resolver_type=ResolverType.IN_PROCESS,
offline_flag_source_path="tests/flags/basic-flag-disabled.json",
offline_flag_source_path=f"{path}/basic-flag-disabled.json",
)
)

Expand Down
2 changes: 1 addition & 1 deletion providers/openfeature-provider-flagd/tests/test_flagd.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_should_get_object_flag_from_flagd(flagd_provider_client):
}

# When
flag = client.get_string_details(flag_key="Key", default_value=return_value)
flag = client.get_object_details(flag_key="Key", default_value=return_value)

# Then
assert flag is not None
Expand Down

0 comments on commit d0c5784

Please sign in to comment.