-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Update test harness (add assertions) #1467 (#415)
* Update test harness (add assertions) #1467 Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com> * fixup! Update test harness (add assertions) #1467 Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com> * fixup! Update test harness (add assertions) #1467 Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com> * fixup! Update test harness (add assertions) #1467 Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com> * fixup! Update test harness (add assertions) #1467 Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com> * fixup! Update test harness (add assertions) #1467 Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com> * fixup! Update test harness (add assertions) #1467 Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com> --------- Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com> Co-authored-by: Anton Grübel <anton.gruebel@gmail.com>
- Loading branch information
Showing
4 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "test-harness"] | ||
path = test-harness | ||
url = https://github.com/open-feature/test-harness.git | ||
[submodule "spec"] | ||
path = spec | ||
url = https://github.com/open-feature/spec.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from behave import given, when | ||
|
||
|
||
@given('a {flag_type}-flag with key "{flag_key}" and a default value "{default_value}"') | ||
def step_impl_flag(context, flag_type: str, flag_key, default_value): | ||
context.flag = (flag_type, flag_key, default_value) | ||
|
||
|
||
@when("the flag was evaluated with details") | ||
def step_impl_evaluation(context): | ||
client = context.client | ||
flag_type, key, default_value = context.flag | ||
if flag_type.lower() == "string": | ||
context.evaluation = client.get_string_details(key, default_value) | ||
elif flag_type.lower() == "boolean": | ||
context.evaluation = client.get_boolean_details(key, default_value) | ||
elif flag_type.lower() == "object": | ||
context.evaluation = client.get_object_details(key, default_value) | ||
elif flag_type.lower() == "float": | ||
context.evaluation = client.get_float_details(key, default_value) | ||
elif flag_type.lower() == "integer": | ||
context.evaluation = client.get_integer_details(key, default_value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from behave import given, then | ||
|
||
from openfeature.api import get_client, set_provider | ||
from openfeature.provider.in_memory_provider import InMemoryProvider | ||
from tests.features.data import IN_MEMORY_FLAGS | ||
|
||
|
||
@given("a stable provider") | ||
def step_impl_stable_provider(context): | ||
set_provider(InMemoryProvider(IN_MEMORY_FLAGS)) | ||
context.client = get_client() | ||
|
||
|
||
@then('the resolved metadata value "{key}" should be "{value}"') | ||
def step_impl_check_metadata(context, key, value): | ||
assert context.evaluation.flag_metadata[key] == value | ||
|
||
|
||
@then("the resolved metadata is empty") | ||
def step_impl_empty_metadata(context): | ||
assert not context.evaluation.flag_metadata | ||
|
||
|
||
@then("the resolved metadata should contain") | ||
def step_impl_metadata_contains(context): | ||
for row in context.table: | ||
key, metadata_type, value = row | ||
|
||
assert context.evaluation.flag_metadata[ | ||
key | ||
] == convert_value_from_metadata_type(value, metadata_type) | ||
|
||
|
||
def convert_value_from_metadata_type(value, metadata_type): | ||
if value == "None": | ||
return None | ||
if metadata_type.lower() == "boolean": | ||
return bool(value) | ||
elif metadata_type.lower() == "integer": | ||
return int(value) | ||
elif metadata_type.lower() == "float": | ||
return float(value) | ||
return value |