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,368 @@
|
|
|
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
|
+
"""E2E tests for Force Users on Rollout and Personalize rules."""
|
|
16
|
+
|
|
17
|
+
import copy
|
|
18
|
+
import sys
|
|
19
|
+
import os
|
|
20
|
+
import unittest
|
|
21
|
+
from unittest.mock import MagicMock, patch
|
|
22
|
+
|
|
23
|
+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))
|
|
24
|
+
|
|
25
|
+
from vwo import init
|
|
26
|
+
from wingify.utils.uuid_util import get_uuid
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
ACCOUNT_ID = "12345"
|
|
30
|
+
SDK_KEY = "test-sdk-key"
|
|
31
|
+
|
|
32
|
+
FORCED_ON_USER = "forced_on_user"
|
|
33
|
+
FORCED_OFF_USER = "forced_off_user"
|
|
34
|
+
NORMAL_USER = "normal_user"
|
|
35
|
+
PERSONALIZE_FORCED_USER = "personalize_forced_user"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _hashed(user_id: str) -> str:
|
|
39
|
+
return get_uuid(user_id, ACCOUNT_ID)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _variables(string_value: str):
|
|
43
|
+
return [
|
|
44
|
+
{"id": 1, "type": "integer", "value": 10, "key": "int"},
|
|
45
|
+
{"id": 2, "type": "double", "value": 20.01, "key": "float"},
|
|
46
|
+
{"id": 3, "type": "string", "value": string_value, "key": "string"},
|
|
47
|
+
{"id": 4, "type": "boolean", "value": False, "key": "boolean"},
|
|
48
|
+
{"id": 5, "type": "json", "value": {"name": "VWO"}, "key": "json"},
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _rollout_force_settings(
|
|
53
|
+
*,
|
|
54
|
+
traffic_weight: float = 0,
|
|
55
|
+
audience_segments=None,
|
|
56
|
+
whitelisted_segments=None,
|
|
57
|
+
):
|
|
58
|
+
"""
|
|
59
|
+
Build rollout settings for Force Users scenarios.
|
|
60
|
+
|
|
61
|
+
Default traffic is 0% so only Force On users should receive the experience.
|
|
62
|
+
"""
|
|
63
|
+
if audience_segments is None:
|
|
64
|
+
audience_segments = {}
|
|
65
|
+
return {
|
|
66
|
+
"version": 1,
|
|
67
|
+
"sdkKey": SDK_KEY,
|
|
68
|
+
"accountId": int(ACCOUNT_ID),
|
|
69
|
+
"features": [
|
|
70
|
+
{
|
|
71
|
+
"status": "ON",
|
|
72
|
+
"name": "Feature1",
|
|
73
|
+
"impactCampaign": {},
|
|
74
|
+
"rules": [
|
|
75
|
+
{
|
|
76
|
+
"ruleKey": "rolloutRule1",
|
|
77
|
+
"type": "FLAG_ROLLOUT",
|
|
78
|
+
"variationId": 1,
|
|
79
|
+
"campaignId": 1,
|
|
80
|
+
}
|
|
81
|
+
],
|
|
82
|
+
"type": "FEATURE_FLAG",
|
|
83
|
+
"metrics": [
|
|
84
|
+
{
|
|
85
|
+
"identifier": "custom1",
|
|
86
|
+
"mca": -1,
|
|
87
|
+
"id": 1,
|
|
88
|
+
"type": "REVENUE_TRACKING",
|
|
89
|
+
}
|
|
90
|
+
],
|
|
91
|
+
"id": 1,
|
|
92
|
+
"key": "feature1",
|
|
93
|
+
}
|
|
94
|
+
],
|
|
95
|
+
"campaigns": [
|
|
96
|
+
{
|
|
97
|
+
"status": "RUNNING",
|
|
98
|
+
"variations": [
|
|
99
|
+
{
|
|
100
|
+
"variables": _variables("forced-rollout"),
|
|
101
|
+
"name": "Rollout-rule-1",
|
|
102
|
+
"segments": audience_segments,
|
|
103
|
+
"whitelistedSegments": whitelisted_segments or {},
|
|
104
|
+
"id": 1,
|
|
105
|
+
"weight": traffic_weight,
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
"segments": {},
|
|
109
|
+
"type": "FLAG_ROLLOUT",
|
|
110
|
+
"isForcedVariationEnabled": True,
|
|
111
|
+
"id": 1,
|
|
112
|
+
"key": "feature1_rolloutRule1",
|
|
113
|
+
"name": "feature1_rolloutRule1",
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _personalize_force_settings(*, whitelisted_segments=None, traffic_weight: float = 0):
|
|
120
|
+
return {
|
|
121
|
+
"version": 1,
|
|
122
|
+
"sdkKey": SDK_KEY,
|
|
123
|
+
"accountId": int(ACCOUNT_ID),
|
|
124
|
+
"features": [
|
|
125
|
+
{
|
|
126
|
+
"status": "ON",
|
|
127
|
+
"name": "Feature1",
|
|
128
|
+
"impactCampaign": {},
|
|
129
|
+
"rules": [
|
|
130
|
+
{
|
|
131
|
+
"ruleKey": "personalizeRule1",
|
|
132
|
+
"type": "FLAG_PERSONALIZE",
|
|
133
|
+
"variationId": 1,
|
|
134
|
+
"campaignId": 1,
|
|
135
|
+
}
|
|
136
|
+
],
|
|
137
|
+
"type": "FEATURE_FLAG",
|
|
138
|
+
"metrics": [
|
|
139
|
+
{
|
|
140
|
+
"identifier": "custom1",
|
|
141
|
+
"mca": -1,
|
|
142
|
+
"id": 1,
|
|
143
|
+
"type": "REVENUE_TRACKING",
|
|
144
|
+
}
|
|
145
|
+
],
|
|
146
|
+
"id": 1,
|
|
147
|
+
"key": "feature1",
|
|
148
|
+
}
|
|
149
|
+
],
|
|
150
|
+
"campaigns": [
|
|
151
|
+
{
|
|
152
|
+
"status": "RUNNING",
|
|
153
|
+
"variations": [
|
|
154
|
+
{
|
|
155
|
+
"variables": _variables("forced-personalize"),
|
|
156
|
+
"name": "Personalize-rule-1",
|
|
157
|
+
"segments": {
|
|
158
|
+
"or": [{"custom_variable": {"price": "999"}}]
|
|
159
|
+
},
|
|
160
|
+
"whitelistedSegments": whitelisted_segments or {},
|
|
161
|
+
"id": 1,
|
|
162
|
+
"weight": traffic_weight,
|
|
163
|
+
}
|
|
164
|
+
],
|
|
165
|
+
"segments": {},
|
|
166
|
+
"type": "FLAG_PERSONALIZE",
|
|
167
|
+
"isForcedVariationEnabled": True,
|
|
168
|
+
"id": 1,
|
|
169
|
+
"key": "feature1_personalizeRule1",
|
|
170
|
+
"name": "feature1_personalizeRule1",
|
|
171
|
+
}
|
|
172
|
+
],
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
class ForceUsersGetFlagTest(unittest.TestCase):
|
|
177
|
+
"""get_flag coverage for Rollout Force On / Force Off and Personalize Force On."""
|
|
178
|
+
|
|
179
|
+
def _init_client(self, settings):
|
|
180
|
+
mock_response = MagicMock(
|
|
181
|
+
status_code=200,
|
|
182
|
+
headers={"Content-Type": "application/json"},
|
|
183
|
+
json=lambda: {},
|
|
184
|
+
)
|
|
185
|
+
self._patches = [
|
|
186
|
+
patch(
|
|
187
|
+
"vwo.vwo_builder.VWOBuilder.get_settings",
|
|
188
|
+
return_value=copy.deepcopy(settings),
|
|
189
|
+
),
|
|
190
|
+
patch(
|
|
191
|
+
"vwo.vwo_builder.VWOBuilder.update_poll_interval_and_check_and_poll",
|
|
192
|
+
return_value=None,
|
|
193
|
+
),
|
|
194
|
+
patch("requests.Session.post", return_value=mock_response),
|
|
195
|
+
patch(
|
|
196
|
+
"wingify.packages.network_layer.manager.network_manager.NetworkManager.post",
|
|
197
|
+
return_value=None,
|
|
198
|
+
),
|
|
199
|
+
]
|
|
200
|
+
for p in self._patches:
|
|
201
|
+
p.start()
|
|
202
|
+
return init({"sdk_key": SDK_KEY, "account_id": ACCOUNT_ID})
|
|
203
|
+
|
|
204
|
+
def tearDown(self):
|
|
205
|
+
for p in getattr(self, "_patches", []):
|
|
206
|
+
p.stop()
|
|
207
|
+
|
|
208
|
+
def test_rollout_force_on_bypasses_zero_traffic(self):
|
|
209
|
+
settings = _rollout_force_settings(
|
|
210
|
+
traffic_weight=0,
|
|
211
|
+
whitelisted_segments={"or": [{"user": _hashed(FORCED_ON_USER)}]},
|
|
212
|
+
)
|
|
213
|
+
client = self._init_client(settings)
|
|
214
|
+
|
|
215
|
+
forced_flag = client.get_flag("feature1", {"id": FORCED_ON_USER})
|
|
216
|
+
normal_flag = client.get_flag("feature1", {"id": NORMAL_USER})
|
|
217
|
+
|
|
218
|
+
self.assertTrue(forced_flag.is_enabled())
|
|
219
|
+
self.assertEqual(forced_flag.get_variable("string", ""), "forced-rollout")
|
|
220
|
+
self.assertFalse(normal_flag.is_enabled())
|
|
221
|
+
|
|
222
|
+
def test_rollout_force_on_bypasses_failed_audience(self):
|
|
223
|
+
settings = _rollout_force_settings(
|
|
224
|
+
traffic_weight=100,
|
|
225
|
+
audience_segments={"or": [{"custom_variable": {"price": "999"}}]},
|
|
226
|
+
whitelisted_segments={"or": [{"user": _hashed(FORCED_ON_USER)}]},
|
|
227
|
+
)
|
|
228
|
+
client = self._init_client(settings)
|
|
229
|
+
|
|
230
|
+
forced_flag = client.get_flag(
|
|
231
|
+
"feature1",
|
|
232
|
+
{"id": FORCED_ON_USER, "custom_variables": {"price": 1}},
|
|
233
|
+
)
|
|
234
|
+
normal_flag = client.get_flag(
|
|
235
|
+
"feature1",
|
|
236
|
+
{"id": NORMAL_USER, "custom_variables": {"price": 1}},
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
self.assertTrue(forced_flag.is_enabled())
|
|
240
|
+
self.assertFalse(normal_flag.is_enabled())
|
|
241
|
+
|
|
242
|
+
def test_rollout_force_off_hard_excludes_user(self):
|
|
243
|
+
settings = _rollout_force_settings(
|
|
244
|
+
traffic_weight=100,
|
|
245
|
+
whitelisted_segments={
|
|
246
|
+
"or": [
|
|
247
|
+
{"user": _hashed(FORCED_ON_USER)},
|
|
248
|
+
{"not": {"or": [{"user": _hashed(FORCED_OFF_USER)}]}},
|
|
249
|
+
]
|
|
250
|
+
},
|
|
251
|
+
)
|
|
252
|
+
client = self._init_client(settings)
|
|
253
|
+
|
|
254
|
+
forced_off_flag = client.get_flag("feature1", {"id": FORCED_OFF_USER})
|
|
255
|
+
normal_flag = client.get_flag("feature1", {"id": NORMAL_USER})
|
|
256
|
+
forced_on_flag = client.get_flag("feature1", {"id": FORCED_ON_USER})
|
|
257
|
+
|
|
258
|
+
self.assertFalse(forced_off_flag.is_enabled())
|
|
259
|
+
self.assertTrue(normal_flag.is_enabled())
|
|
260
|
+
self.assertTrue(forced_on_flag.is_enabled())
|
|
261
|
+
|
|
262
|
+
def test_personalize_force_on_bypasses_audience_and_traffic(self):
|
|
263
|
+
settings = _personalize_force_settings(
|
|
264
|
+
traffic_weight=0,
|
|
265
|
+
whitelisted_segments={"or": [{"user": _hashed(PERSONALIZE_FORCED_USER)}]},
|
|
266
|
+
)
|
|
267
|
+
client = self._init_client(settings)
|
|
268
|
+
|
|
269
|
+
forced_flag = client.get_flag(
|
|
270
|
+
"feature1",
|
|
271
|
+
{
|
|
272
|
+
"id": PERSONALIZE_FORCED_USER,
|
|
273
|
+
"custom_variables": {"price": 1},
|
|
274
|
+
},
|
|
275
|
+
)
|
|
276
|
+
normal_flag = client.get_flag(
|
|
277
|
+
"feature1",
|
|
278
|
+
{"id": NORMAL_USER, "custom_variables": {"price": 1}},
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
self.assertTrue(forced_flag.is_enabled())
|
|
282
|
+
self.assertEqual(
|
|
283
|
+
forced_flag.get_variable("string", ""), "forced-personalize"
|
|
284
|
+
)
|
|
285
|
+
self.assertFalse(normal_flag.is_enabled())
|
|
286
|
+
|
|
287
|
+
def test_rollout_force_off_only_uses_audience_for_other_users(self):
|
|
288
|
+
settings = _rollout_force_settings(
|
|
289
|
+
traffic_weight=100,
|
|
290
|
+
audience_segments={"or": [{"custom_variable": {"country": "US"}}]},
|
|
291
|
+
whitelisted_segments={
|
|
292
|
+
"and": [
|
|
293
|
+
{"not": {"or": [{"user": _hashed(FORCED_OFF_USER)}]}}
|
|
294
|
+
]
|
|
295
|
+
},
|
|
296
|
+
)
|
|
297
|
+
client = self._init_client(settings)
|
|
298
|
+
|
|
299
|
+
failing = client.get_flag(
|
|
300
|
+
"feature1",
|
|
301
|
+
{"id": NORMAL_USER, "custom_variables": {"country": "IN"}},
|
|
302
|
+
)
|
|
303
|
+
passing = client.get_flag(
|
|
304
|
+
"feature1",
|
|
305
|
+
{"id": NORMAL_USER, "custom_variables": {"country": "US"}},
|
|
306
|
+
)
|
|
307
|
+
excluded = client.get_flag(
|
|
308
|
+
"feature1",
|
|
309
|
+
{"id": FORCED_OFF_USER, "custom_variables": {"country": "US"}},
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
self.assertFalse(failing.is_enabled())
|
|
313
|
+
self.assertTrue(passing.is_enabled())
|
|
314
|
+
self.assertEqual(passing.get_variable("string", ""), "forced-rollout")
|
|
315
|
+
self.assertFalse(excluded.is_enabled())
|
|
316
|
+
|
|
317
|
+
def test_personalize_not_only_does_not_force_other_users(self):
|
|
318
|
+
settings = _personalize_force_settings(
|
|
319
|
+
traffic_weight=100,
|
|
320
|
+
whitelisted_segments={
|
|
321
|
+
"not": {"or": [{"user": _hashed(FORCED_OFF_USER)}]}
|
|
322
|
+
},
|
|
323
|
+
)
|
|
324
|
+
client = self._init_client(settings)
|
|
325
|
+
|
|
326
|
+
other = client.get_flag("feature1", {"id": NORMAL_USER})
|
|
327
|
+
matching_audience = client.get_flag(
|
|
328
|
+
"feature1",
|
|
329
|
+
{"id": NORMAL_USER, "custom_variables": {"price": "999"}},
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
self.assertFalse(other.is_enabled())
|
|
333
|
+
self.assertTrue(matching_audience.is_enabled())
|
|
334
|
+
self.assertEqual(
|
|
335
|
+
matching_audience.get_variable("string", ""), "forced-personalize"
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
def test_personalize_force_on_still_works_beside_not(self):
|
|
339
|
+
settings = _personalize_force_settings(
|
|
340
|
+
traffic_weight=0,
|
|
341
|
+
whitelisted_segments={
|
|
342
|
+
"and": [
|
|
343
|
+
{"not": {"or": [{"user": _hashed(FORCED_OFF_USER)}]}},
|
|
344
|
+
{"or": [{"user": _hashed(PERSONALIZE_FORCED_USER)}]},
|
|
345
|
+
]
|
|
346
|
+
},
|
|
347
|
+
)
|
|
348
|
+
client = self._init_client(settings)
|
|
349
|
+
|
|
350
|
+
forced = client.get_flag(
|
|
351
|
+
"feature1",
|
|
352
|
+
{
|
|
353
|
+
"id": PERSONALIZE_FORCED_USER,
|
|
354
|
+
"custom_variables": {"price": 1},
|
|
355
|
+
},
|
|
356
|
+
)
|
|
357
|
+
other = client.get_flag(
|
|
358
|
+
"feature1",
|
|
359
|
+
{"id": NORMAL_USER, "custom_variables": {"price": 1}},
|
|
360
|
+
)
|
|
361
|
+
|
|
362
|
+
self.assertTrue(forced.is_enabled())
|
|
363
|
+
self.assertEqual(forced.get_variable("string", ""), "forced-personalize")
|
|
364
|
+
self.assertFalse(other.is_enabled())
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
if __name__ == "__main__":
|
|
368
|
+
unittest.main()
|
|
@@ -0,0 +1,195 @@
|
|
|
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
|
+
|
|
20
|
+
# Add the parent directory to the sys.path
|
|
21
|
+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))
|
|
22
|
+
|
|
23
|
+
# Now you can import the module
|
|
24
|
+
from vwo import init
|
|
25
|
+
from ..data.dummy_test_data_reader import settings_files, test_data
|
|
26
|
+
from typing import Dict, List, Any
|
|
27
|
+
from ..data.user_storage import user_storage
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class VWOTest(unittest.TestCase):
|
|
31
|
+
|
|
32
|
+
sdk_key = "abcd"
|
|
33
|
+
account_id = "1234"
|
|
34
|
+
|
|
35
|
+
def test_01_get_flag_without_storage(self):
|
|
36
|
+
self._helper_function_to_run_test(
|
|
37
|
+
test_data.get("GETFLAG_WITHOUT_STORAGE"), False
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
def test_05_get_flag_with_salt(self):
|
|
41
|
+
self._helper_function_to_run_salt_test(test_data.get("GETFLAG_WITH_SALT"))
|
|
42
|
+
|
|
43
|
+
def test_02_get_flag_with_meg_random(self):
|
|
44
|
+
self._helper_function_to_run_test(test_data.get("GETFLAG_MEG_RANDOM"), False)
|
|
45
|
+
|
|
46
|
+
def test_03_get_flag_with_meg_advance(self):
|
|
47
|
+
self._helper_function_to_run_test(test_data.get("GETFLAG_MEG_ADVANCE"), False)
|
|
48
|
+
|
|
49
|
+
def test_04_get_flag_with_storage(self):
|
|
50
|
+
self._helper_function_to_run_test(test_data.get("GETFLAG_WITH_STORAGE"), True)
|
|
51
|
+
|
|
52
|
+
def _helper_function_to_run_test(
|
|
53
|
+
self, test_data: List[Dict[str, Any]], is_storage: bool
|
|
54
|
+
):
|
|
55
|
+
for data in test_data:
|
|
56
|
+
with patch(
|
|
57
|
+
"vwo.vwo_builder.VWOBuilder.get_settings",
|
|
58
|
+
return_value=settings_files.get(data.get("settings")),
|
|
59
|
+
) as mock_get_settings, patch(
|
|
60
|
+
"vwo.vwo_builder.VWOBuilder.update_poll_interval_and_check_and_poll",
|
|
61
|
+
return_value=None, # Mocking the method to return nothing
|
|
62
|
+
), patch(
|
|
63
|
+
"wingify.packages.network_layer.manager.network_manager.NetworkManager.post",
|
|
64
|
+
return_value=None, # Mocking the post method to return nothing
|
|
65
|
+
):
|
|
66
|
+
storage = user_storage()
|
|
67
|
+
options = {"sdk_key": self.sdk_key, "account_id": self.account_id}
|
|
68
|
+
|
|
69
|
+
if is_storage:
|
|
70
|
+
options["storage"] = storage
|
|
71
|
+
|
|
72
|
+
vwo_instance = init(options)
|
|
73
|
+
|
|
74
|
+
if is_storage:
|
|
75
|
+
storage_data = storage.get(
|
|
76
|
+
data["featureKey"], data["context"]["id"]
|
|
77
|
+
)
|
|
78
|
+
self.assertIsNone(storage_data)
|
|
79
|
+
|
|
80
|
+
feature_flag = vwo_instance.get_flag(
|
|
81
|
+
data["featureKey"], data["context"]
|
|
82
|
+
)
|
|
83
|
+
self.assertEqual(
|
|
84
|
+
data["expectation"]["isEnabled"], feature_flag.is_enabled()
|
|
85
|
+
)
|
|
86
|
+
self.assertEqual(
|
|
87
|
+
data["expectation"]["intVariable"],
|
|
88
|
+
feature_flag.get_variable("int", 1),
|
|
89
|
+
)
|
|
90
|
+
self.assertEqual(
|
|
91
|
+
data["expectation"]["stringVariable"],
|
|
92
|
+
feature_flag.get_variable("string", "VWO"),
|
|
93
|
+
data["settings"] + " " + data["description"],
|
|
94
|
+
)
|
|
95
|
+
self.assertEqual(
|
|
96
|
+
data["expectation"]["floatVariable"],
|
|
97
|
+
feature_flag.get_variable("float", 1.1),
|
|
98
|
+
)
|
|
99
|
+
self.assertEqual(
|
|
100
|
+
data["expectation"]["booleanVariable"],
|
|
101
|
+
feature_flag.get_variable("boolean", False),
|
|
102
|
+
)
|
|
103
|
+
self.assertEqual(
|
|
104
|
+
data["expectation"]["jsonVariable"],
|
|
105
|
+
feature_flag.get_variable("json", {}),
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
if is_storage:
|
|
109
|
+
if data["expectation"]["isEnabled"]:
|
|
110
|
+
updated_storage_data = storage.get(
|
|
111
|
+
data["featureKey"], data["context"]["id"]
|
|
112
|
+
)
|
|
113
|
+
self.assertEqual(
|
|
114
|
+
data["expectation"]["storageData"].get("rolloutKey", None),
|
|
115
|
+
updated_storage_data["rolloutKey"],
|
|
116
|
+
)
|
|
117
|
+
self.assertEqual(
|
|
118
|
+
data["expectation"]["storageData"].get(
|
|
119
|
+
"rolloutVariationId", None
|
|
120
|
+
),
|
|
121
|
+
updated_storage_data["rolloutVariationId"],
|
|
122
|
+
)
|
|
123
|
+
self.assertEqual(
|
|
124
|
+
data["expectation"]["storageData"].get(
|
|
125
|
+
"experimentKey", None
|
|
126
|
+
),
|
|
127
|
+
updated_storage_data["experimentKey"],
|
|
128
|
+
)
|
|
129
|
+
self.assertEqual(
|
|
130
|
+
data["expectation"]["storageData"].get(
|
|
131
|
+
"experimentVariationId", None
|
|
132
|
+
),
|
|
133
|
+
updated_storage_data["experimentVariationId"],
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
def _helper_function_to_run_salt_test(self, salt_test_data: List[Dict[str, Any]]):
|
|
137
|
+
storage = user_storage()
|
|
138
|
+
for test_data in salt_test_data:
|
|
139
|
+
# Debug print for the test data
|
|
140
|
+
storage.clear()
|
|
141
|
+
|
|
142
|
+
with patch(
|
|
143
|
+
"vwo.vwo_builder.VWOBuilder.get_settings",
|
|
144
|
+
return_value=settings_files.get(test_data.get("settings")),
|
|
145
|
+
) as mock_get_settings, patch(
|
|
146
|
+
"vwo.vwo_builder.VWOBuilder.update_poll_interval_and_check_and_poll",
|
|
147
|
+
return_value=None, # Mocking the method to return nothing
|
|
148
|
+
), patch(
|
|
149
|
+
"wingify.packages.network_layer.manager.network_manager.NetworkManager.post",
|
|
150
|
+
return_value=None, # Mocking the post method to return nothing
|
|
151
|
+
):
|
|
152
|
+
# Debug print for the settings file being used
|
|
153
|
+
settings_file = settings_files.get(test_data.get("settings"))
|
|
154
|
+
options = {
|
|
155
|
+
"sdk_key": self.sdk_key,
|
|
156
|
+
"account_id": self.account_id,
|
|
157
|
+
"logger": {"level": "DEBUG"},
|
|
158
|
+
}
|
|
159
|
+
vwo_instance = init(options)
|
|
160
|
+
|
|
161
|
+
# Extract user IDs directly from the "userIds" key in test data
|
|
162
|
+
user_ids = test_data["userIds"]
|
|
163
|
+
feature_key_1 = test_data["featureKey"]
|
|
164
|
+
feature_key_2 = test_data["featureKey2"]
|
|
165
|
+
|
|
166
|
+
for user_id in user_ids:
|
|
167
|
+
# Pass user_id as part of the context
|
|
168
|
+
feature_flag_1 = vwo_instance.get_flag(
|
|
169
|
+
feature_key_1, {"id": user_id}
|
|
170
|
+
)
|
|
171
|
+
feature_flag_2 = vwo_instance.get_flag(
|
|
172
|
+
feature_key_2, {"id": user_id}
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
# Get variables for comparison
|
|
176
|
+
variables_1 = feature_flag_1.get_variables()
|
|
177
|
+
variables_2 = feature_flag_2.get_variables()
|
|
178
|
+
|
|
179
|
+
# Validate variations based on expectation
|
|
180
|
+
if test_data["expectation"]["shouldReturnSameVariation"]:
|
|
181
|
+
self.assertEqual(
|
|
182
|
+
variables_1,
|
|
183
|
+
variables_2,
|
|
184
|
+
f"Variables for user {user_id} are not the same!",
|
|
185
|
+
)
|
|
186
|
+
else:
|
|
187
|
+
self.assertNotEqual(
|
|
188
|
+
variables_1,
|
|
189
|
+
variables_2,
|
|
190
|
+
f"Variables for user {user_id} should not be the same!",
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
if __name__ == "__main__":
|
|
195
|
+
unittest.main()
|
tests/unit/__init__.py
ADDED
|
@@ -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,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,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,83 @@
|
|
|
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
|
+
|
|
20
|
+
# Add the parent directory to the sys.path
|
|
21
|
+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))
|
|
22
|
+
|
|
23
|
+
# Now you can import the module
|
|
24
|
+
from wingify.packages.decision_maker.decision_maker import DecisionMaker
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class DecisionMakerTest(unittest.TestCase):
|
|
28
|
+
|
|
29
|
+
def setUp(self):
|
|
30
|
+
self.decisionMaker = DecisionMaker()
|
|
31
|
+
|
|
32
|
+
def test_generate_bucket_value(self):
|
|
33
|
+
hash_value = 2147483647
|
|
34
|
+
max_value = 100
|
|
35
|
+
multiplier = 1
|
|
36
|
+
expected_bucket_value = int(
|
|
37
|
+
(max_value * (hash_value / (2**32)) + 1) * multiplier
|
|
38
|
+
)
|
|
39
|
+
bucket_value = self.decisionMaker.generate_bucket_value(
|
|
40
|
+
hash_value, max_value, multiplier
|
|
41
|
+
)
|
|
42
|
+
self.assertEqual(bucket_value, expected_bucket_value)
|
|
43
|
+
|
|
44
|
+
@patch.object(DecisionMaker, "generate_hash_value")
|
|
45
|
+
def test_get_bucket_value_for_user(self, mock_generateHashValue):
|
|
46
|
+
user_id = "user123"
|
|
47
|
+
max_value = 100
|
|
48
|
+
mock_hash_value = 123456789
|
|
49
|
+
mock_generateHashValue.return_value = mock_hash_value
|
|
50
|
+
|
|
51
|
+
expected_bucket_value = self.decisionMaker.generate_bucket_value(
|
|
52
|
+
mock_hash_value, max_value
|
|
53
|
+
)
|
|
54
|
+
bucket_value = self.decisionMaker.get_bucket_value_for_user(user_id, max_value)
|
|
55
|
+
|
|
56
|
+
self.assertEqual(bucket_value, expected_bucket_value)
|
|
57
|
+
|
|
58
|
+
@patch.object(DecisionMaker, "generate_hash_value")
|
|
59
|
+
def test_calculate_bucket_value(self, mock_generateHashValue):
|
|
60
|
+
string = "testString"
|
|
61
|
+
multiplier = 1
|
|
62
|
+
max_value = 10000
|
|
63
|
+
mock_hash_value = 987654321
|
|
64
|
+
mock_generateHashValue.return_value = mock_hash_value
|
|
65
|
+
|
|
66
|
+
expected_bucket_value = self.decisionMaker.generate_bucket_value(
|
|
67
|
+
mock_hash_value, max_value, multiplier
|
|
68
|
+
)
|
|
69
|
+
bucket_value = self.decisionMaker.calculate_bucket_value(
|
|
70
|
+
string, multiplier, max_value
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
self.assertEqual(bucket_value, expected_bucket_value)
|
|
74
|
+
|
|
75
|
+
def test_generateHashValue(self):
|
|
76
|
+
hash_key = "key123"
|
|
77
|
+
expected_hash_value = 2360047679
|
|
78
|
+
hash_value = self.decisionMaker.generate_hash_value(hash_key)
|
|
79
|
+
self.assertEqual(hash_value, expected_hash_value)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
if __name__ == "__main__":
|
|
83
|
+
unittest.main()
|