wingify-fme-python-sdk 1.70.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tests/data/__init__.py +13 -0
- tests/data/dummy_test_data_reader.py +63 -0
- tests/data/user_storage.py +48 -0
- tests/e2e/__init__.py +13 -0
- tests/e2e/custom_bucketing_test.py +514 -0
- tests/e2e/force_users_test.py +368 -0
- tests/e2e/get_flag_test.py +195 -0
- tests/unit/__init__.py +13 -0
- tests/unit/packages/__init__.py +13 -0
- tests/unit/packages/decision_maker/__init__.py +13 -0
- tests/unit/packages/decision_maker/decision_maker_test.py +83 -0
- tests/unit/packages/segmentation_evaluator/__init__.py +13 -0
- tests/unit/packages/segmentation_evaluator/segmentation_evaluator_test.py +284 -0
- tests/unit/packages/segmentation_evaluator/segmentation_manager_test.py +215 -0
- tests/unit/packages/segmentation_evaluator/web_testing_segment_test.py +216 -0
- tests/unit/services/__init__.py +0 -0
- tests/unit/services/hooks_manager_test.py +80 -0
- tests/unit/services/internal_events_sampling_service_test.py +160 -0
- tests/unit/settings/__init__.py +13 -0
- tests/unit/settings/settings_schema_validation_test.py +67 -0
- tests/unit/utils/__init__.py +0 -0
- tests/unit/utils/campaign_util_test.py +248 -0
- tests/unit/utils/decision_util_force_users_test.py +790 -0
- tests/unit/utils/log_message_test.py +65 -0
- tests/unit/vwo_wingify_test.py +175 -0
- tests/unit/wingify_client_validation_test.py +72 -0
- vwo/__init__.py +35 -0
- vwo/models/__init__.py +13 -0
- vwo/models/batch_event_data.py +19 -0
- vwo/models/user/__init__.py +13 -0
- vwo/models/user/context_vwo_model.py +21 -0
- vwo/models/user/get_flag.py +19 -0
- vwo/models/vwo_options_model.py +21 -0
- vwo/packages/__init__.py +13 -0
- vwo/packages/logger/__init__.py +13 -0
- vwo/packages/logger/enums/__init__.py +13 -0
- vwo/packages/logger/enums/log_level_enum.py +19 -0
- vwo/packages/storage/__init__.py +13 -0
- vwo/packages/storage/connector.py +19 -0
- vwo/vwo.py +58 -0
- vwo/vwo_builder.py +21 -0
- vwo/vwo_client.py +22 -0
- wingify/__init__.py +36 -0
- wingify/api/__init__.py +13 -0
- wingify/api/get_flag_api.py +727 -0
- wingify/api/set_attribute_api.py +60 -0
- wingify/api/track_api.py +99 -0
- wingify/constants/Constants.py +94 -0
- wingify/constants/__init__.py +13 -0
- wingify/constants/sampled_debug_error_template_keys.py +34 -0
- wingify/decorators/__init__.py +13 -0
- wingify/decorators/storage_decorator.py +92 -0
- wingify/enums/__init__.py +13 -0
- wingify/enums/api_enum.py +26 -0
- wingify/enums/campaign_type_enum.py +22 -0
- wingify/enums/debug_category_enum.py +24 -0
- wingify/enums/event_enum.py +26 -0
- wingify/enums/headers_enum.py +21 -0
- wingify/enums/hooks_enum.py +24 -0
- wingify/enums/status_enum.py +21 -0
- wingify/enums/storage_enum.py +25 -0
- wingify/enums/url_enum.py +29 -0
- wingify/models/Alias.py +60 -0
- wingify/models/AliasSetResponse.py +43 -0
- wingify/models/__init__.py +13 -0
- wingify/models/batch_event_data.py +68 -0
- wingify/models/campaign/__init__.py +13 -0
- wingify/models/campaign/campaign_model.py +140 -0
- wingify/models/campaign/feature_model.py +95 -0
- wingify/models/campaign/holdout_model.py +94 -0
- wingify/models/campaign/impact_campaign_model.py +60 -0
- wingify/models/campaign/metric_model.py +42 -0
- wingify/models/campaign/rule_model.py +42 -0
- wingify/models/campaign/variable_model.py +44 -0
- wingify/models/campaign/variation_model.py +109 -0
- wingify/models/gateway_service_model.py +48 -0
- wingify/models/schemas/__init__.py +13 -0
- wingify/models/schemas/campaign_group_schema.py +19 -0
- wingify/models/schemas/campaign_metric_schema.py +26 -0
- wingify/models/schemas/campaign_schema.py +37 -0
- wingify/models/schemas/campaign_variation_schema.py +34 -0
- wingify/models/schemas/empty_object_schema.py +15 -0
- wingify/models/schemas/feature_schema.py +38 -0
- wingify/models/schemas/group_schema.py +37 -0
- wingify/models/schemas/holdout_schema.py +29 -0
- wingify/models/schemas/rule_schema.py +24 -0
- wingify/models/schemas/settings_schema.py +47 -0
- wingify/models/schemas/variable_schema.py +24 -0
- wingify/models/settings/__init__.py +13 -0
- wingify/models/settings/internal_event_sampling_settings_model.py +53 -0
- wingify/models/settings/settings_model.py +127 -0
- wingify/models/storage/__init__.py +13 -0
- wingify/models/storage/storage_model.py +84 -0
- wingify/models/user/__init__.py +13 -0
- wingify/models/user/context_model.py +113 -0
- wingify/models/user/context_vwo_model.py +34 -0
- wingify/models/user/get_flag.py +47 -0
- wingify/models/vwo_options_model.py +21 -0
- wingify/models/wingify_options_model.py +129 -0
- wingify/packages/__init__.py +13 -0
- wingify/packages/decision_maker/__init__.py +13 -0
- wingify/packages/decision_maker/decision_maker.py +89 -0
- wingify/packages/logger/__init__.py +13 -0
- wingify/packages/logger/core/__init__.py +13 -0
- wingify/packages/logger/core/log_manager.py +123 -0
- wingify/packages/logger/core/log_transport_manager.py +57 -0
- wingify/packages/logger/enums/__init__.py +13 -0
- wingify/packages/logger/enums/log_level_enum.py +24 -0
- wingify/packages/logger/enums/log_level_number_enum.py +21 -0
- wingify/packages/logger/log_message_builder.py +70 -0
- wingify/packages/logger/logger.py +38 -0
- wingify/packages/logger/transports/__init__.py +13 -0
- wingify/packages/logger/transports/console_transport.py +43 -0
- wingify/packages/network_layer/__init__.py +13 -0
- wingify/packages/network_layer/client/__init__.py +13 -0
- wingify/packages/network_layer/client/network_client.py +167 -0
- wingify/packages/network_layer/handlers/__init__.py +13 -0
- wingify/packages/network_layer/handlers/request_handler.py +40 -0
- wingify/packages/network_layer/manager/__init__.py +13 -0
- wingify/packages/network_layer/manager/network_manager.py +79 -0
- wingify/packages/network_layer/models/__init__.py +13 -0
- wingify/packages/network_layer/models/global_request_model.py +70 -0
- wingify/packages/network_layer/models/request_model.py +133 -0
- wingify/packages/network_layer/models/response_model.py +55 -0
- wingify/packages/segmentation_evaluator/__init__.py +13 -0
- wingify/packages/segmentation_evaluator/core/__init__.py +13 -0
- wingify/packages/segmentation_evaluator/core/segmentation_manager.py +140 -0
- wingify/packages/segmentation_evaluator/enums/__init__.py +13 -0
- wingify/packages/segmentation_evaluator/enums/segment_operand_regex_enum.py +31 -0
- wingify/packages/segmentation_evaluator/enums/segment_operand_value_enum.py +29 -0
- wingify/packages/segmentation_evaluator/enums/segment_operator_value_enum.py +37 -0
- wingify/packages/segmentation_evaluator/evaluators/__init__.py +13 -0
- wingify/packages/segmentation_evaluator/evaluators/segment_evaluator.py +237 -0
- wingify/packages/segmentation_evaluator/evaluators/segment_operand_evaluator.py +518 -0
- wingify/packages/segmentation_evaluator/utils/__init__.py +13 -0
- wingify/packages/segmentation_evaluator/utils/segment_util.py +33 -0
- wingify/packages/segmentation_evaluator/utils/web_testing_segment_util.py +295 -0
- wingify/packages/storage/__init__.py +13 -0
- wingify/packages/storage/connector.py +25 -0
- wingify/packages/storage/storage.py +39 -0
- wingify/resources/__init__.py +13 -0
- wingify/resources/debug-messages.json +21 -0
- wingify/resources/error-messages.json +62 -0
- wingify/resources/info-message.json +47 -0
- wingify/resources/trace-messages.json +1 -0
- wingify/resources/warn-messages.json +1 -0
- wingify/services/__init__.py +13 -0
- wingify/services/batch_event_queue.py +140 -0
- wingify/services/campaign_decision_service.py +268 -0
- wingify/services/hooks_manager.py +65 -0
- wingify/services/internal_events_sampling_service.py +62 -0
- wingify/services/settings_manager.py +293 -0
- wingify/services/storage_service.py +58 -0
- wingify/services/url_service.py +51 -0
- wingify/utils/__init__.py +13 -0
- wingify/utils/aliasing_util.py +108 -0
- wingify/utils/brand_context.py +26 -0
- wingify/utils/brand_util.py +37 -0
- wingify/utils/campaign_util.py +592 -0
- wingify/utils/data_type_util.py +125 -0
- wingify/utils/debugger_service_util.py +58 -0
- wingify/utils/decision_util.py +589 -0
- wingify/utils/event_util.py +85 -0
- wingify/utils/function_util.py +188 -0
- wingify/utils/gateway_service_util.py +179 -0
- wingify/utils/holdout_util.py +264 -0
- wingify/utils/impression_util.py +151 -0
- wingify/utils/internal_events_sampling_util.py +106 -0
- wingify/utils/log_message_util.py +95 -0
- wingify/utils/meg_util.py +561 -0
- wingify/utils/model_utils.py +136 -0
- wingify/utils/network_util.py +706 -0
- wingify/utils/rule_evaluation_util.py +102 -0
- wingify/utils/settings_util.py +39 -0
- wingify/utils/usage_stats_util.py +116 -0
- wingify/utils/uuid_util.py +81 -0
- wingify/vwo_client.py +21 -0
- wingify/wingify.py +159 -0
- wingify/wingify_builder.py +282 -0
- wingify/wingify_client.py +520 -0
- wingify_fme_python_sdk-1.70.0.dist-info/METADATA +1415 -0
- wingify_fme_python_sdk-1.70.0.dist-info/RECORD +186 -0
- wingify_fme_python_sdk-1.70.0.dist-info/WHEEL +5 -0
- wingify_fme_python_sdk-1.70.0.dist-info/licenses/LICENSE +202 -0
- wingify_fme_python_sdk-1.70.0.dist-info/licenses/NOTICE +18 -0
- wingify_fme_python_sdk-1.70.0.dist-info/top_level.txt +3 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Copyright 2024-2026 Wingify Software Pvt. Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
# Copyright 2024-2026 Wingify Software Pvt. Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import sys
|
|
16
|
+
import os
|
|
17
|
+
import unittest
|
|
18
|
+
from unittest.mock import patch, MagicMock
|
|
19
|
+
from ....data.dummy_test_data_reader import segmentor_dummy_dsl as TESTS_DATA
|
|
20
|
+
|
|
21
|
+
# Add the parent directory to the sys.path
|
|
22
|
+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))
|
|
23
|
+
|
|
24
|
+
# Now you can import the module
|
|
25
|
+
from wingify.packages.segmentation_evaluator.evaluators.segment_evaluator import (
|
|
26
|
+
SegmentEvaluator,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# Test class for Segmentation using unittest
|
|
31
|
+
class TestSegmentation(unittest.TestCase):
|
|
32
|
+
def setUp(self):
|
|
33
|
+
self.segment_evaluator = SegmentEvaluator()
|
|
34
|
+
|
|
35
|
+
def test_and_operator(self):
|
|
36
|
+
test_data = TESTS_DATA["and_operator"]
|
|
37
|
+
for key in test_data:
|
|
38
|
+
dsl = test_data[key]["dsl"]
|
|
39
|
+
expectation = test_data[key]["expectation"]
|
|
40
|
+
custom_variables = test_data[key].get("customVariables", {})
|
|
41
|
+
|
|
42
|
+
pre_segmentation_result = self.segment_evaluator.is_segmentation_valid(
|
|
43
|
+
dsl, custom_variables
|
|
44
|
+
)
|
|
45
|
+
self.assertEqual(pre_segmentation_result, expectation)
|
|
46
|
+
|
|
47
|
+
def test_case_insensitive_equality_operand(self):
|
|
48
|
+
test_data = TESTS_DATA["case_insensitive_equality_operand"]
|
|
49
|
+
for key in test_data:
|
|
50
|
+
dsl = test_data[key]["dsl"]
|
|
51
|
+
expectation = test_data[key]["expectation"]
|
|
52
|
+
custom_variables = test_data[key].get("customVariables", {})
|
|
53
|
+
|
|
54
|
+
pre_segmentation_result = self.segment_evaluator.is_segmentation_valid(
|
|
55
|
+
dsl, custom_variables
|
|
56
|
+
)
|
|
57
|
+
self.assertEqual(pre_segmentation_result, expectation)
|
|
58
|
+
|
|
59
|
+
def test_complex_and_ors(self):
|
|
60
|
+
test_data = TESTS_DATA["complex_and_ors"]
|
|
61
|
+
for key in test_data:
|
|
62
|
+
dsl = test_data[key]["dsl"]
|
|
63
|
+
expectation = test_data[key]["expectation"]
|
|
64
|
+
custom_variables = test_data[key].get("customVariables", {})
|
|
65
|
+
|
|
66
|
+
pre_segmentation_result = self.segment_evaluator.is_segmentation_valid(
|
|
67
|
+
dsl, custom_variables
|
|
68
|
+
)
|
|
69
|
+
self.assertEqual(pre_segmentation_result, expectation)
|
|
70
|
+
|
|
71
|
+
def test_complex_dsl(self):
|
|
72
|
+
for test_case in [
|
|
73
|
+
"complex_dsl_1",
|
|
74
|
+
"complex_dsl_2",
|
|
75
|
+
"complex_dsl_3",
|
|
76
|
+
"complex_dsl_4",
|
|
77
|
+
]:
|
|
78
|
+
test_data = TESTS_DATA[test_case]
|
|
79
|
+
for key in test_data:
|
|
80
|
+
dsl = test_data[key]["dsl"]
|
|
81
|
+
expectation = test_data[key]["expectation"]
|
|
82
|
+
custom_variables = test_data[key].get("customVariables", {})
|
|
83
|
+
|
|
84
|
+
pre_segmentation_result = self.segment_evaluator.is_segmentation_valid(
|
|
85
|
+
dsl, custom_variables
|
|
86
|
+
)
|
|
87
|
+
self.assertEqual(pre_segmentation_result, expectation)
|
|
88
|
+
|
|
89
|
+
def test_contains_operand(self):
|
|
90
|
+
test_data = TESTS_DATA["contains_operand"]
|
|
91
|
+
for key in test_data:
|
|
92
|
+
dsl = test_data[key]["dsl"]
|
|
93
|
+
expectation = test_data[key]["expectation"]
|
|
94
|
+
custom_variables = test_data[key].get("customVariables", {})
|
|
95
|
+
|
|
96
|
+
pre_segmentation_result = self.segment_evaluator.is_segmentation_valid(
|
|
97
|
+
dsl, custom_variables
|
|
98
|
+
)
|
|
99
|
+
self.assertEqual(pre_segmentation_result, expectation)
|
|
100
|
+
|
|
101
|
+
def test_ends_with_operand(self):
|
|
102
|
+
test_data = TESTS_DATA["ends_with_operand"]
|
|
103
|
+
for key in test_data:
|
|
104
|
+
dsl = test_data[key]["dsl"]
|
|
105
|
+
expectation = test_data[key]["expectation"]
|
|
106
|
+
custom_variables = test_data[key].get("customVariables", {})
|
|
107
|
+
|
|
108
|
+
pre_segmentation_result = self.segment_evaluator.is_segmentation_valid(
|
|
109
|
+
dsl, custom_variables
|
|
110
|
+
)
|
|
111
|
+
self.assertEqual(pre_segmentation_result, expectation)
|
|
112
|
+
|
|
113
|
+
def test_equality_operand(self):
|
|
114
|
+
test_data = TESTS_DATA["equality_operand"]
|
|
115
|
+
for key in test_data:
|
|
116
|
+
dsl = test_data[key]["dsl"]
|
|
117
|
+
expectation = test_data[key]["expectation"]
|
|
118
|
+
custom_variables = test_data[key].get("customVariables", {})
|
|
119
|
+
|
|
120
|
+
pre_segmentation_result = self.segment_evaluator.is_segmentation_valid(
|
|
121
|
+
dsl, custom_variables
|
|
122
|
+
)
|
|
123
|
+
self.assertEqual(pre_segmentation_result, expectation)
|
|
124
|
+
|
|
125
|
+
def test_new_cases_for_decimal_mismatch(self):
|
|
126
|
+
test_data = TESTS_DATA["new_cases_for_decimal_mismatch"]
|
|
127
|
+
for key in test_data:
|
|
128
|
+
dsl = test_data[key]["dsl"]
|
|
129
|
+
expectation = test_data[key]["expectation"]
|
|
130
|
+
custom_variables = test_data[key].get("customVariables", {})
|
|
131
|
+
|
|
132
|
+
pre_segmentation_result = self.segment_evaluator.is_segmentation_valid(
|
|
133
|
+
dsl, custom_variables
|
|
134
|
+
)
|
|
135
|
+
self.assertEqual(pre_segmentation_result, expectation)
|
|
136
|
+
|
|
137
|
+
def test_not_operator(self):
|
|
138
|
+
test_data = TESTS_DATA["not_operator"]
|
|
139
|
+
for key in test_data:
|
|
140
|
+
dsl = test_data[key]["dsl"]
|
|
141
|
+
expectation = test_data[key]["expectation"]
|
|
142
|
+
custom_variables = test_data[key].get("customVariables", {})
|
|
143
|
+
|
|
144
|
+
pre_segmentation_result = self.segment_evaluator.is_segmentation_valid(
|
|
145
|
+
dsl, custom_variables
|
|
146
|
+
)
|
|
147
|
+
self.assertEqual(pre_segmentation_result, expectation)
|
|
148
|
+
|
|
149
|
+
def test_or_operator(self):
|
|
150
|
+
test_data = TESTS_DATA["or_operator"]
|
|
151
|
+
for key in test_data:
|
|
152
|
+
dsl = test_data[key]["dsl"]
|
|
153
|
+
expectation = test_data[key]["expectation"]
|
|
154
|
+
custom_variables = test_data[key].get("customVariables", {})
|
|
155
|
+
|
|
156
|
+
pre_segmentation_result = self.segment_evaluator.is_segmentation_valid(
|
|
157
|
+
dsl, custom_variables
|
|
158
|
+
)
|
|
159
|
+
self.assertEqual(pre_segmentation_result, expectation)
|
|
160
|
+
|
|
161
|
+
def test_regex(self):
|
|
162
|
+
test_data = TESTS_DATA["regex"]
|
|
163
|
+
for key in test_data:
|
|
164
|
+
dsl = test_data[key]["dsl"]
|
|
165
|
+
expectation = test_data[key]["expectation"]
|
|
166
|
+
custom_variables = test_data[key].get("customVariables", {})
|
|
167
|
+
|
|
168
|
+
pre_segmentation_result = self.segment_evaluator.is_segmentation_valid(
|
|
169
|
+
dsl, custom_variables
|
|
170
|
+
)
|
|
171
|
+
self.assertEqual(pre_segmentation_result, expectation)
|
|
172
|
+
|
|
173
|
+
def test_simple_and_ors(self):
|
|
174
|
+
test_data = TESTS_DATA["simple_and_ors"]
|
|
175
|
+
for key in test_data:
|
|
176
|
+
dsl = test_data[key]["dsl"]
|
|
177
|
+
expectation = test_data[key]["expectation"]
|
|
178
|
+
custom_variables = test_data[key].get("customVariables", {})
|
|
179
|
+
|
|
180
|
+
pre_segmentation_result = self.segment_evaluator.is_segmentation_valid(
|
|
181
|
+
dsl, custom_variables
|
|
182
|
+
)
|
|
183
|
+
self.assertEqual(pre_segmentation_result, expectation)
|
|
184
|
+
|
|
185
|
+
def test_starts_with_operand(self):
|
|
186
|
+
test_data = TESTS_DATA["starts_with_operand"]
|
|
187
|
+
for key in test_data:
|
|
188
|
+
dsl = test_data[key]["dsl"]
|
|
189
|
+
expectation = test_data[key]["expectation"]
|
|
190
|
+
custom_variables = test_data[key].get("customVariables", {})
|
|
191
|
+
|
|
192
|
+
pre_segmentation_result = self.segment_evaluator.is_segmentation_valid(
|
|
193
|
+
dsl, custom_variables
|
|
194
|
+
)
|
|
195
|
+
self.assertEqual(pre_segmentation_result, expectation)
|
|
196
|
+
|
|
197
|
+
def test_special_characters(self):
|
|
198
|
+
test_data = TESTS_DATA["special_characters"]
|
|
199
|
+
for key in test_data:
|
|
200
|
+
dsl = test_data[key]["dsl"]
|
|
201
|
+
expectation = test_data[key]["expectation"]
|
|
202
|
+
custom_variables = test_data[key].get("customVariables", {})
|
|
203
|
+
|
|
204
|
+
pre_segmentation_result = self.segment_evaluator.is_segmentation_valid(
|
|
205
|
+
dsl, custom_variables
|
|
206
|
+
)
|
|
207
|
+
self.assertEqual(pre_segmentation_result, expectation)
|
|
208
|
+
|
|
209
|
+
def test_user_operand_evaluator(self):
|
|
210
|
+
test_data = TESTS_DATA["user_operand_evaluator"]
|
|
211
|
+
for key in test_data:
|
|
212
|
+
dsl = test_data[key]["dsl"]
|
|
213
|
+
expectation = test_data[key]["expectation"]
|
|
214
|
+
custom_variables = test_data[key].get("customVariables", {})
|
|
215
|
+
|
|
216
|
+
pre_segmentation_result = self.segment_evaluator.is_segmentation_valid(
|
|
217
|
+
dsl, custom_variables
|
|
218
|
+
)
|
|
219
|
+
self.assertEqual(pre_segmentation_result, expectation)
|
|
220
|
+
|
|
221
|
+
def test_user_operand_evaluator_with_customVariables(self):
|
|
222
|
+
test_data = TESTS_DATA["user_operand_evaluator_with_customVariables"]
|
|
223
|
+
for key in test_data:
|
|
224
|
+
dsl = test_data[key]["dsl"]
|
|
225
|
+
expectation = test_data[key]["expectation"]
|
|
226
|
+
custom_variables = test_data[key].get("customVariables", {})
|
|
227
|
+
|
|
228
|
+
pre_segmentation_result = self.segment_evaluator.is_segmentation_valid(
|
|
229
|
+
dsl, custom_variables
|
|
230
|
+
)
|
|
231
|
+
self.assertEqual(pre_segmentation_result, expectation)
|
|
232
|
+
|
|
233
|
+
def test_customVariables_with_greater_than_operator(self):
|
|
234
|
+
test_data = TESTS_DATA["greater_than_operator"]
|
|
235
|
+
for key in test_data:
|
|
236
|
+
dsl = test_data[key]["dsl"]
|
|
237
|
+
expectation = test_data[key]["expectation"]
|
|
238
|
+
custom_variables = test_data[key].get("customVariables", {})
|
|
239
|
+
|
|
240
|
+
pre_segmentation_result = self.segment_evaluator.is_segmentation_valid(
|
|
241
|
+
dsl, custom_variables
|
|
242
|
+
)
|
|
243
|
+
self.assertEqual(pre_segmentation_result, expectation)
|
|
244
|
+
|
|
245
|
+
def test_customVariables_with_less_than_operator(self):
|
|
246
|
+
test_data = TESTS_DATA["less_than_operator"]
|
|
247
|
+
for key in test_data:
|
|
248
|
+
dsl = test_data[key]["dsl"]
|
|
249
|
+
expectation = test_data[key]["expectation"]
|
|
250
|
+
custom_variables = test_data[key].get("customVariables", {})
|
|
251
|
+
|
|
252
|
+
pre_segmentation_result = self.segment_evaluator.is_segmentation_valid(
|
|
253
|
+
dsl, custom_variables
|
|
254
|
+
)
|
|
255
|
+
self.assertEqual(pre_segmentation_result, expectation)
|
|
256
|
+
|
|
257
|
+
def test_customVariables_with_greater_than_equal_to_operator(self):
|
|
258
|
+
test_data = TESTS_DATA["greater_than_equal_to_operator"]
|
|
259
|
+
for key in test_data:
|
|
260
|
+
dsl = test_data[key]["dsl"]
|
|
261
|
+
expectation = test_data[key]["expectation"]
|
|
262
|
+
custom_variables = test_data[key].get("customVariables", {})
|
|
263
|
+
|
|
264
|
+
pre_segmentation_result = self.segment_evaluator.is_segmentation_valid(
|
|
265
|
+
dsl, custom_variables
|
|
266
|
+
)
|
|
267
|
+
self.assertEqual(pre_segmentation_result, expectation)
|
|
268
|
+
|
|
269
|
+
def test_customVariables_with_less_than_equal_to_operator(self):
|
|
270
|
+
test_data = TESTS_DATA["less_than_equal_to_operator"]
|
|
271
|
+
for key in test_data:
|
|
272
|
+
dsl = test_data[key]["dsl"]
|
|
273
|
+
expectation = test_data[key]["expectation"]
|
|
274
|
+
custom_variables = test_data[key].get("customVariables", {})
|
|
275
|
+
|
|
276
|
+
pre_segmentation_result = self.segment_evaluator.is_segmentation_valid(
|
|
277
|
+
dsl, custom_variables
|
|
278
|
+
)
|
|
279
|
+
self.assertEqual(pre_segmentation_result, expectation)
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
# To run the tests if this file is executed directly
|
|
283
|
+
if __name__ == "__main__":
|
|
284
|
+
unittest.main()
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# Copyright 2024-2026 Wingify Software Pvt. Ltd.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
"""Unit tests for gateway gating in ``SegmentationManager.set_contextual_data``."""
|
|
16
|
+
|
|
17
|
+
import unittest
|
|
18
|
+
from unittest.mock import patch
|
|
19
|
+
|
|
20
|
+
from wingify.models.campaign.feature_model import FeatureModel
|
|
21
|
+
from wingify.models.campaign.impact_campaign_model import ImpactCampaignModel
|
|
22
|
+
from wingify.models.settings.settings_model import SettingsModel
|
|
23
|
+
from wingify.models.user.context_model import ContextModel
|
|
24
|
+
from wingify.packages.logger.core.log_manager import LogManager
|
|
25
|
+
from wingify.packages.network_layer.manager.network_manager import NetworkManager
|
|
26
|
+
from wingify.packages.segmentation_evaluator.core.segmentation_manager import (
|
|
27
|
+
SegmentationManager,
|
|
28
|
+
)
|
|
29
|
+
from wingify.services.settings_manager import SettingsManager
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class SegmentationManagerGatewayTest(unittest.TestCase):
|
|
33
|
+
"""Tests that ``get-user-details`` is called only when gateway and segmentation require it."""
|
|
34
|
+
|
|
35
|
+
def setUp(self):
|
|
36
|
+
"""
|
|
37
|
+
Reset singletons and initialize logger/network for an isolated test run.
|
|
38
|
+
|
|
39
|
+
:return: None.
|
|
40
|
+
"""
|
|
41
|
+
SegmentationManager._instance = None
|
|
42
|
+
SettingsManager._instance = None
|
|
43
|
+
LogManager({"level": "ERROR"})
|
|
44
|
+
NetworkManager.get_instance({})
|
|
45
|
+
|
|
46
|
+
def _run_set_contextual_data(
|
|
47
|
+
self,
|
|
48
|
+
*,
|
|
49
|
+
is_gateway_service_provided: bool,
|
|
50
|
+
is_proxy_url_provided: bool,
|
|
51
|
+
feature_requires_gateway: bool,
|
|
52
|
+
):
|
|
53
|
+
"""
|
|
54
|
+
Execute ``set_contextual_data`` under a mocked gateway service call.
|
|
55
|
+
|
|
56
|
+
:param is_gateway_service_provided: Whether ``gateway_service`` is passed to init.
|
|
57
|
+
:param is_proxy_url_provided: Whether ``proxy_url`` is passed to init.
|
|
58
|
+
:param feature_requires_gateway: Whether the feature flag marks gateway as required.
|
|
59
|
+
:return: Mock object for ``get_from_gateway_service``.
|
|
60
|
+
"""
|
|
61
|
+
init_options = {
|
|
62
|
+
"sdk_key": "test-sdk-key",
|
|
63
|
+
"account_id": "123456",
|
|
64
|
+
}
|
|
65
|
+
# Optional proxy — routes HTTP but does not enable gateway enrichment
|
|
66
|
+
if is_proxy_url_provided:
|
|
67
|
+
init_options["proxy_url"] = "http://localhost:3400"
|
|
68
|
+
# Optional gateway — enables get-user-details when segmentation requires it
|
|
69
|
+
if is_gateway_service_provided:
|
|
70
|
+
init_options["gateway_service"] = {"url": "http://localhost:3000"}
|
|
71
|
+
|
|
72
|
+
SettingsManager(init_options)
|
|
73
|
+
|
|
74
|
+
feature = FeatureModel(
|
|
75
|
+
id=1,
|
|
76
|
+
key="feature1",
|
|
77
|
+
name="Feature1",
|
|
78
|
+
type="FEATURE_FLAG",
|
|
79
|
+
status="ON",
|
|
80
|
+
metrics=[],
|
|
81
|
+
rules=[],
|
|
82
|
+
impactCampaign=ImpactCampaignModel({}),
|
|
83
|
+
is_gateway_service_required=feature_requires_gateway,
|
|
84
|
+
)
|
|
85
|
+
settings = SettingsModel(
|
|
86
|
+
{
|
|
87
|
+
"features": [],
|
|
88
|
+
"campaigns": [],
|
|
89
|
+
"version": 1,
|
|
90
|
+
"accountId": 123456,
|
|
91
|
+
"sdkKey": "test-sdk-key",
|
|
92
|
+
}
|
|
93
|
+
)
|
|
94
|
+
# Context includes UA/IP fields used for gateway enrichment
|
|
95
|
+
context = ContextModel(
|
|
96
|
+
{
|
|
97
|
+
"id": "user-1",
|
|
98
|
+
"user_agent": "Mozilla/5.0 Test",
|
|
99
|
+
"ip_address": "127.0.0.1",
|
|
100
|
+
}
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
with patch(
|
|
104
|
+
"wingify.packages.segmentation_evaluator.core.segmentation_manager.get_from_gateway_service"
|
|
105
|
+
) as mock_get_from_gateway:
|
|
106
|
+
SegmentationManager.get_instance().set_contextual_data(
|
|
107
|
+
settings, feature, context
|
|
108
|
+
)
|
|
109
|
+
return mock_get_from_gateway
|
|
110
|
+
|
|
111
|
+
def test_proxy_url_only_with_ua_ip_does_not_call_gateway(self):
|
|
112
|
+
"""
|
|
113
|
+
Verify proxy-only init does not call gateway when segmentation does not require it.
|
|
114
|
+
|
|
115
|
+
``proxy_url`` alone must not trigger ``get-user-details``.
|
|
116
|
+
|
|
117
|
+
:return: None. Asserts gateway service is never invoked.
|
|
118
|
+
"""
|
|
119
|
+
mock_get_from_gateway = self._run_set_contextual_data(
|
|
120
|
+
is_gateway_service_provided=False,
|
|
121
|
+
is_proxy_url_provided=True,
|
|
122
|
+
feature_requires_gateway=False,
|
|
123
|
+
)
|
|
124
|
+
mock_get_from_gateway.assert_not_called()
|
|
125
|
+
|
|
126
|
+
def test_gateway_service_without_segmentation_requirement_does_not_call(self):
|
|
127
|
+
"""
|
|
128
|
+
Verify gateway configured without gateway-requiring segmentation skips the call.
|
|
129
|
+
|
|
130
|
+
:return: None. Asserts gateway service is never invoked.
|
|
131
|
+
"""
|
|
132
|
+
mock_get_from_gateway = self._run_set_contextual_data(
|
|
133
|
+
is_gateway_service_provided=True,
|
|
134
|
+
is_proxy_url_provided=False,
|
|
135
|
+
feature_requires_gateway=False,
|
|
136
|
+
)
|
|
137
|
+
mock_get_from_gateway.assert_not_called()
|
|
138
|
+
|
|
139
|
+
def test_gateway_service_with_segmentation_requirement_calls_gateway(self):
|
|
140
|
+
"""
|
|
141
|
+
Verify gateway is called when both gateway is configured and segmentation needs it.
|
|
142
|
+
|
|
143
|
+
:return: None. Asserts ``get_from_gateway_service`` is invoked exactly once.
|
|
144
|
+
"""
|
|
145
|
+
mock_get_from_gateway = self._run_set_contextual_data(
|
|
146
|
+
is_gateway_service_provided=True,
|
|
147
|
+
is_proxy_url_provided=False,
|
|
148
|
+
feature_requires_gateway=True,
|
|
149
|
+
)
|
|
150
|
+
mock_get_from_gateway.assert_called_once()
|
|
151
|
+
|
|
152
|
+
def test_proxy_url_with_segmentation_requirement_does_not_call_gateway(self):
|
|
153
|
+
"""
|
|
154
|
+
Verify proxy-only init does not call gateway even when segmentation requires it.
|
|
155
|
+
|
|
156
|
+
Segmentation may fail quietly without gateway (no error log).
|
|
157
|
+
|
|
158
|
+
:return: None. Asserts gateway service is never invoked.
|
|
159
|
+
"""
|
|
160
|
+
mock_get_from_gateway = self._run_set_contextual_data(
|
|
161
|
+
is_gateway_service_provided=False,
|
|
162
|
+
is_proxy_url_provided=True,
|
|
163
|
+
feature_requires_gateway=True,
|
|
164
|
+
)
|
|
165
|
+
mock_get_from_gateway.assert_not_called()
|
|
166
|
+
|
|
167
|
+
def test_no_ua_or_ip_skips_gateway_even_when_required(self):
|
|
168
|
+
"""
|
|
169
|
+
Verify gateway is not called when context lacks both user agent and IP address.
|
|
170
|
+
|
|
171
|
+
Early return in ``set_contextual_data`` applies before gateway gating.
|
|
172
|
+
|
|
173
|
+
:return: None. Asserts gateway service is never invoked.
|
|
174
|
+
"""
|
|
175
|
+
SettingsManager(
|
|
176
|
+
{
|
|
177
|
+
"sdk_key": "test-sdk-key",
|
|
178
|
+
"account_id": "123456",
|
|
179
|
+
"gateway_service": {"url": "http://localhost:3000"},
|
|
180
|
+
}
|
|
181
|
+
)
|
|
182
|
+
feature = FeatureModel(
|
|
183
|
+
id=1,
|
|
184
|
+
key="feature1",
|
|
185
|
+
name="Feature1",
|
|
186
|
+
type="FEATURE_FLAG",
|
|
187
|
+
status="ON",
|
|
188
|
+
metrics=[],
|
|
189
|
+
rules=[],
|
|
190
|
+
impactCampaign=ImpactCampaignModel({}),
|
|
191
|
+
is_gateway_service_required=True,
|
|
192
|
+
)
|
|
193
|
+
settings = SettingsModel(
|
|
194
|
+
{
|
|
195
|
+
"features": [],
|
|
196
|
+
"campaigns": [],
|
|
197
|
+
"version": 1,
|
|
198
|
+
"accountId": 123456,
|
|
199
|
+
"sdkKey": "test-sdk-key",
|
|
200
|
+
}
|
|
201
|
+
)
|
|
202
|
+
# No user_agent or ip_address — gateway enrichment cannot run
|
|
203
|
+
context = ContextModel({"id": "user-1"})
|
|
204
|
+
|
|
205
|
+
with patch(
|
|
206
|
+
"wingify.packages.segmentation_evaluator.core.segmentation_manager.get_from_gateway_service"
|
|
207
|
+
) as mock_get_from_gateway:
|
|
208
|
+
SegmentationManager.get_instance().set_contextual_data(
|
|
209
|
+
settings, feature, context
|
|
210
|
+
)
|
|
211
|
+
mock_get_from_gateway.assert_not_called()
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
if __name__ == "__main__":
|
|
215
|
+
unittest.main()
|