|
1 | | -from flag_engine.context.types import SegmentCondition, SegmentContext, SegmentRule |
| 1 | +from flag_engine.context.types import SegmentContext |
2 | 2 | from flag_engine.segments import constants |
3 | 3 |
|
4 | 4 | trait_key_1 = "email" |
|
10 | 10 | trait_key_3 = "date_joined" |
11 | 11 | trait_value_3 = "2021-01-01" |
12 | 12 |
|
13 | | -empty_segment = SegmentContext(key=str(1), name="empty_segment", rules=[]) |
| 13 | +empty_segment = {"key": "1", "name": "empty_segment", "rules": []} |
14 | 14 |
|
15 | | -segment_single_condition = SegmentContext( |
16 | | - key=str(2), |
17 | | - name="segment_one_condition", |
18 | | - rules=[ |
19 | | - SegmentRule( |
20 | | - type=constants.ALL_RULE, |
21 | | - conditions=[ |
22 | | - SegmentCondition( |
23 | | - operator=constants.EQUAL, |
24 | | - property=trait_key_1, |
25 | | - value=trait_value_1, |
26 | | - ) |
| 15 | +segment_single_condition: SegmentContext = { |
| 16 | + "key": "2", |
| 17 | + "name": "segment_one_condition", |
| 18 | + "rules": [ |
| 19 | + { |
| 20 | + "type": constants.ALL_RULE, |
| 21 | + "conditions": [ |
| 22 | + { |
| 23 | + "operator": constants.EQUAL, |
| 24 | + "property": trait_key_1, |
| 25 | + "value": trait_value_1, |
| 26 | + } |
27 | 27 | ], |
28 | | - ) |
| 28 | + } |
29 | 29 | ], |
30 | | -) |
| 30 | +} |
31 | 31 |
|
32 | | -segment_multiple_conditions_all = SegmentContext( |
33 | | - key=str(3), |
34 | | - name="segment_multiple_conditions_all", |
35 | | - rules=[ |
36 | | - SegmentRule( |
37 | | - type=constants.ALL_RULE, |
38 | | - conditions=[ |
39 | | - SegmentCondition( |
40 | | - operator=constants.EQUAL, |
41 | | - property=trait_key_1, |
42 | | - value=trait_value_1, |
43 | | - ), |
44 | | - SegmentCondition( |
45 | | - operator=constants.EQUAL, |
46 | | - property=trait_key_2, |
47 | | - value=trait_value_2, |
48 | | - ), |
| 32 | +segment_multiple_conditions_all: SegmentContext = { |
| 33 | + "key": "3", |
| 34 | + "name": "segment_multiple_conditions_all", |
| 35 | + "rules": [ |
| 36 | + { |
| 37 | + "type": constants.ALL_RULE, |
| 38 | + "conditions": [ |
| 39 | + { |
| 40 | + "operator": constants.EQUAL, |
| 41 | + "property": trait_key_1, |
| 42 | + "value": trait_value_1, |
| 43 | + }, |
| 44 | + { |
| 45 | + "operator": constants.EQUAL, |
| 46 | + "property": trait_key_2, |
| 47 | + "value": trait_value_2, |
| 48 | + }, |
49 | 49 | ], |
50 | | - ) |
| 50 | + } |
51 | 51 | ], |
52 | | -) |
| 52 | +} |
53 | 53 |
|
54 | | -segment_multiple_conditions_any = SegmentContext( |
55 | | - key=str(4), |
56 | | - name="segment_multiple_conditions_all", |
57 | | - rules=[ |
58 | | - SegmentRule( |
59 | | - type=constants.ANY_RULE, |
60 | | - conditions=[ |
61 | | - SegmentCondition( |
62 | | - operator=constants.EQUAL, |
63 | | - property=trait_key_1, |
64 | | - value=trait_value_1, |
65 | | - ), |
66 | | - SegmentCondition( |
67 | | - operator=constants.EQUAL, |
68 | | - property=trait_key_2, |
69 | | - value=trait_value_2, |
70 | | - ), |
| 54 | +segment_multiple_conditions_any: SegmentContext = { |
| 55 | + "key": "4", |
| 56 | + "name": "segment_multiple_conditions_all", |
| 57 | + "rules": [ |
| 58 | + { |
| 59 | + "type": constants.ANY_RULE, |
| 60 | + "conditions": [ |
| 61 | + { |
| 62 | + "operator": constants.EQUAL, |
| 63 | + "property": trait_key_1, |
| 64 | + "value": trait_value_1, |
| 65 | + }, |
| 66 | + { |
| 67 | + "operator": constants.EQUAL, |
| 68 | + "property": trait_key_2, |
| 69 | + "value": trait_value_2, |
| 70 | + }, |
71 | 71 | ], |
72 | | - ) |
| 72 | + } |
73 | 73 | ], |
74 | | -) |
| 74 | +} |
75 | 75 |
|
76 | | -segment_nested_rules = SegmentContext( |
77 | | - key=str(5), |
78 | | - name="segment_nested_rules_all", |
79 | | - rules=[ |
80 | | - SegmentRule( |
81 | | - type=constants.ALL_RULE, |
82 | | - rules=[ |
83 | | - SegmentRule( |
84 | | - type=constants.ALL_RULE, |
85 | | - conditions=[ |
86 | | - SegmentCondition( |
87 | | - operator=constants.EQUAL, |
88 | | - property=trait_key_1, |
89 | | - value=trait_value_1, |
90 | | - ), |
91 | | - SegmentCondition( |
92 | | - operator=constants.EQUAL, |
93 | | - property=trait_key_2, |
94 | | - value=trait_value_2, |
95 | | - ), |
| 76 | +segment_nested_rules: SegmentContext = { |
| 77 | + "key": "5", |
| 78 | + "name": "segment_nested_rules_all", |
| 79 | + "rules": [ |
| 80 | + { |
| 81 | + "type": constants.ALL_RULE, |
| 82 | + "rules": [ |
| 83 | + { |
| 84 | + "type": constants.ALL_RULE, |
| 85 | + "conditions": [ |
| 86 | + { |
| 87 | + "operator": constants.EQUAL, |
| 88 | + "property": trait_key_1, |
| 89 | + "value": trait_value_1, |
| 90 | + }, |
| 91 | + { |
| 92 | + "operator": constants.EQUAL, |
| 93 | + "property": trait_key_2, |
| 94 | + "value": trait_value_2, |
| 95 | + }, |
96 | 96 | ], |
97 | | - ), |
98 | | - SegmentRule( |
99 | | - type=constants.ALL_RULE, |
100 | | - conditions=[ |
101 | | - SegmentCondition( |
102 | | - operator=constants.EQUAL, |
103 | | - property=trait_key_3, |
104 | | - value=trait_value_3, |
105 | | - ) |
| 97 | + }, |
| 98 | + { |
| 99 | + "type": constants.ALL_RULE, |
| 100 | + "conditions": [ |
| 101 | + { |
| 102 | + "operator": constants.EQUAL, |
| 103 | + "property": trait_key_3, |
| 104 | + "value": trait_value_3, |
| 105 | + } |
106 | 106 | ], |
107 | | - ), |
| 107 | + }, |
108 | 108 | ], |
109 | | - ) |
| 109 | + } |
110 | 110 | ], |
111 | | -) |
| 111 | +} |
112 | 112 |
|
113 | | -segment_conditions_and_nested_rules = SegmentContext( |
114 | | - key=str(6), |
115 | | - name="segment_multiple_conditions_all_and_nested_rules", |
116 | | - rules=[ |
117 | | - SegmentRule( |
118 | | - type=constants.ALL_RULE, |
119 | | - conditions=[ |
120 | | - SegmentCondition( |
121 | | - operator=constants.EQUAL, |
122 | | - property=trait_key_1, |
123 | | - value=trait_value_1, |
124 | | - ) |
| 113 | +segment_conditions_and_nested_rules: SegmentContext = { |
| 114 | + "key": "6", |
| 115 | + "name": "segment_multiple_conditions_all_and_nested_rules", |
| 116 | + "rules": [ |
| 117 | + { |
| 118 | + "type": constants.ALL_RULE, |
| 119 | + "conditions": [ |
| 120 | + { |
| 121 | + "operator": constants.EQUAL, |
| 122 | + "property": trait_key_1, |
| 123 | + "value": trait_value_1, |
| 124 | + } |
125 | 125 | ], |
126 | | - rules=[ |
127 | | - SegmentRule( |
128 | | - type=constants.ALL_RULE, |
129 | | - conditions=[ |
130 | | - SegmentCondition( |
131 | | - operator=constants.EQUAL, |
132 | | - property=trait_key_2, |
133 | | - value=trait_value_2, |
134 | | - ), |
| 126 | + "rules": [ |
| 127 | + { |
| 128 | + "type": constants.ALL_RULE, |
| 129 | + "conditions": [ |
| 130 | + { |
| 131 | + "operator": constants.EQUAL, |
| 132 | + "property": trait_key_2, |
| 133 | + "value": trait_value_2, |
| 134 | + }, |
135 | 135 | ], |
136 | | - ), |
137 | | - SegmentRule( |
138 | | - type=constants.ALL_RULE, |
139 | | - conditions=[ |
140 | | - SegmentCondition( |
141 | | - operator=constants.EQUAL, |
142 | | - property=trait_key_3, |
143 | | - value=trait_value_3, |
144 | | - ) |
| 136 | + }, |
| 137 | + { |
| 138 | + "type": constants.ALL_RULE, |
| 139 | + "conditions": [ |
| 140 | + { |
| 141 | + "operator": constants.EQUAL, |
| 142 | + "property": trait_key_3, |
| 143 | + "value": trait_value_3, |
| 144 | + } |
145 | 145 | ], |
146 | | - ), |
| 146 | + }, |
147 | 147 | ], |
148 | | - ) |
| 148 | + } |
149 | 149 | ], |
150 | | -) |
| 150 | +} |
0 commit comments