-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathcontext_steps.py
More file actions
85 lines (71 loc) · 2.46 KB
/
Copy pathcontext_steps.py
File metadata and controls
85 lines (71 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import pytest
from pytest_bdd import given, parsers, when
from tests.e2e.parsers import to_bool, to_list
from openfeature.evaluation_context import EvaluationContext
from ._utils import type_cast
@pytest.fixture
def evaluation_context() -> EvaluationContext:
return EvaluationContext()
@given(
parsers.cfparse(
'a context containing a targeting key with value "{targeting_key}"'
),
)
def assign_targeting_context(evaluation_context: EvaluationContext, targeting_key: str):
"""a context containing a targeting key with value <targeting key>."""
evaluation_context.targeting_key = targeting_key
@given(
parsers.cfparse(
'a context containing a key "{key}", with type "{type_info}" and with value "{value}"'
),
)
def update_context(
evaluation_context: EvaluationContext, key: str, type_info: str, value: str
):
"""a context containing a key and value."""
if type_info == "String":
value = value.replace("\\\\", "\\")
evaluation_context.attributes[key] = type_cast[type_info](value)
@given(
parsers.cfparse(
'a context containing a key "{key}", with type "{type_info}" and with value ""'
),
)
def update_context_without_value(
evaluation_context: EvaluationContext, key: str, type_info: str
):
"""a context containing a key and value."""
update_context(evaluation_context, key, type_info, "")
@when(
parsers.cfparse(
'context contains keys {fields:s} with values "{svalue}", "{svalue2}", {ivalue:d}, "{bvalue:bool}"',
extra_types={"bool": to_bool, "s": to_list},
),
)
def assign_targeting_context_2(
evaluation_context: EvaluationContext,
fields: list,
svalue: str,
svalue2: str,
ivalue: int,
bvalue: bool,
):
evaluation_context.attributes[fields[0]] = svalue
evaluation_context.attributes[fields[1]] = svalue2
evaluation_context.attributes[fields[2]] = ivalue
evaluation_context.attributes[fields[3]] = bvalue
@given(
parsers.cfparse(
'a context containing a nested property with outer key "{outer}" and inner key "{inner}", with value "{value}"'
),
)
def update_context_nested(
evaluation_context: EvaluationContext,
outer: str,
inner: str,
value: str | int,
):
"""a context containing a nested property with outer key, and inner key, and value."""
if outer not in evaluation_context.attributes:
evaluation_context.attributes[outer] = {}
evaluation_context.attributes[outer][inner] = value