Skip to content

Commit

Permalink
feat: implement get_provider_metadata for requirement 1.1.5 (#140)
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Bond <federicobond@gmail.com>
  • Loading branch information
federicobond authored Jul 10, 2023
1 parent 7fe511f commit 695da28
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions open_feature/open_feature_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from open_feature.exception.exceptions import GeneralError
from open_feature.open_feature_client import OpenFeatureClient
from open_feature.provider.metadata import Metadata
from open_feature.provider.no_op_provider import NoOpProvider
from open_feature.provider.provider import AbstractProvider

Expand All @@ -24,3 +25,8 @@ def set_provider(provider: AbstractProvider):
def get_provider() -> typing.Optional[AbstractProvider]:
global _provider
return _provider


def get_provider_metadata() -> typing.Optional[Metadata]:
global _provider
return _provider.get_metadata()
20 changes: 19 additions & 1 deletion tests/test_open_feature_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

from open_feature.exception.error_code import ErrorCode
from open_feature.exception.exceptions import GeneralError
from open_feature.open_feature_api import get_client, get_provider, set_provider
from open_feature.open_feature_api import (
get_client,
get_provider,
set_provider,
get_provider_metadata,
)
from open_feature.provider.metadata import Metadata
from open_feature.provider.no_op_provider import NoOpProvider


Expand Down Expand Up @@ -52,3 +58,15 @@ def test_should_return_a_provider_if_setup_correctly():
# Then
assert provider
assert isinstance(provider, NoOpProvider)


def test_should_retrieve_metadata_for_configured_provider():
# Given
set_provider(NoOpProvider())

# When
metadata = get_provider_metadata()

# Then
assert isinstance(metadata, Metadata)
assert metadata.name == "No-op Provider"

0 comments on commit 695da28

Please sign in to comment.