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
tests/data/__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,63 @@
|
|
|
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 os
|
|
16
|
+
import json
|
|
17
|
+
from typing import Dict
|
|
18
|
+
|
|
19
|
+
# Determine the base directory (the directory containing this script)
|
|
20
|
+
base_dir = os.path.dirname(__file__)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def load_settings_json_files(directory_path):
|
|
24
|
+
"""
|
|
25
|
+
Load all JSON files from a specified directory into a dictionary.
|
|
26
|
+
|
|
27
|
+
:param directory_path: Path to the directory containing JSON files.
|
|
28
|
+
:return: Dictionary where keys are filenames and values are JSON contents.
|
|
29
|
+
"""
|
|
30
|
+
json_files_content = {}
|
|
31
|
+
|
|
32
|
+
# Iterate through all files in the directory
|
|
33
|
+
for filename in os.listdir(directory_path):
|
|
34
|
+
if filename.endswith(".json"):
|
|
35
|
+
file_path = os.path.join(directory_path, filename)
|
|
36
|
+
try:
|
|
37
|
+
with open(file_path, "r", encoding="utf-8") as file:
|
|
38
|
+
json_content = json.load(file)
|
|
39
|
+
# remove .json from filename
|
|
40
|
+
filename = filename.split(".")[0]
|
|
41
|
+
json_files_content[filename] = json_content
|
|
42
|
+
except (json.JSONDecodeError, IOError) as e:
|
|
43
|
+
print(f"Error reading {filename}: {e}")
|
|
44
|
+
|
|
45
|
+
return json_files_content
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def load_test_data_json_file(filename: str) -> Dict[str, str]:
|
|
49
|
+
"""
|
|
50
|
+
Loads a JSON file and returns its content as a dictionary.
|
|
51
|
+
|
|
52
|
+
:param filename: The name of the JSON file to load.
|
|
53
|
+
:return: A dictionary with the contents of the JSON file.
|
|
54
|
+
"""
|
|
55
|
+
filepath = os.path.join(base_dir, "test_cases", filename)
|
|
56
|
+
with open(filepath, "r") as file:
|
|
57
|
+
return json.load(file)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
# Load the JSON files
|
|
61
|
+
settings_files = load_settings_json_files(os.path.join(base_dir, "settings"))
|
|
62
|
+
test_data = load_test_data_json_file("index.json")
|
|
63
|
+
segmentor_dummy_dsl = load_test_data_json_file("dummy_dsl.json")
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
from typing import Any, Dict
|
|
16
|
+
import sys
|
|
17
|
+
import os
|
|
18
|
+
|
|
19
|
+
# Add the parent directory to the sys.path
|
|
20
|
+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))
|
|
21
|
+
|
|
22
|
+
# Now you can import the module
|
|
23
|
+
from vwo.packages.storage.connector import StorageConnector
|
|
24
|
+
|
|
25
|
+
client_db: Dict[str, Dict] = {}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class user_storage(StorageConnector):
|
|
29
|
+
def get(self, key: str, user_id: str):
|
|
30
|
+
return client_db.get(key + "_" + user_id)
|
|
31
|
+
|
|
32
|
+
def set(self, value: Dict[str, Any]):
|
|
33
|
+
key = value.get("featureKey") + "_" + value.get("userId")
|
|
34
|
+
client_db[key] = {
|
|
35
|
+
"rolloutKey": value.get("rolloutKey"),
|
|
36
|
+
"rolloutVariationId": value.get("rolloutVariationId"),
|
|
37
|
+
"rolloutId": value.get("rolloutId"),
|
|
38
|
+
"experimentKey": value.get("experimentKey"),
|
|
39
|
+
"experimentVariationId": value.get("experimentVariationId"),
|
|
40
|
+
"experimentId": value.get("experimentId"),
|
|
41
|
+
"isInHoldoutId": value.get("isInHoldoutId"),
|
|
42
|
+
"notInHoldoutId": value.get("notInHoldoutId"),
|
|
43
|
+
}
|
|
44
|
+
return True
|
|
45
|
+
|
|
46
|
+
def clear(self):
|
|
47
|
+
"""Clear the storage."""
|
|
48
|
+
client_db.clear()
|
tests/e2e/__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,514 @@
|
|
|
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
|
+
from vwo import init
|
|
24
|
+
|
|
25
|
+
# Mock settings matching Node.js test for parity
|
|
26
|
+
MOCK_SETTINGS_FILE = {
|
|
27
|
+
"version": 1,
|
|
28
|
+
"sdkKey": "abcdef",
|
|
29
|
+
"accountId": 123456,
|
|
30
|
+
"campaigns": [
|
|
31
|
+
{
|
|
32
|
+
"segments": {},
|
|
33
|
+
"status": "RUNNING",
|
|
34
|
+
"variations": [
|
|
35
|
+
{
|
|
36
|
+
"weight": 100,
|
|
37
|
+
"segments": {},
|
|
38
|
+
"id": 1,
|
|
39
|
+
"variables": [
|
|
40
|
+
{
|
|
41
|
+
"id": 1,
|
|
42
|
+
"type": "string",
|
|
43
|
+
"value": "def",
|
|
44
|
+
"key": "kaus"
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
"name": "Rollout-rule-1"
|
|
48
|
+
}
|
|
49
|
+
],
|
|
50
|
+
"type": "FLAG_ROLLOUT",
|
|
51
|
+
"isAlwaysCheckSegment": False,
|
|
52
|
+
"isForcedVariationEnabled": False,
|
|
53
|
+
"name": "featureOne : Rollout",
|
|
54
|
+
"key": "featureOne_rolloutRule1",
|
|
55
|
+
"id": 1
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"segments": {},
|
|
59
|
+
"status": "RUNNING",
|
|
60
|
+
"key": "featureOne_testingRule1",
|
|
61
|
+
"type": "FLAG_TESTING",
|
|
62
|
+
"isAlwaysCheckSegment": False,
|
|
63
|
+
"name": "featureOne : Testing rule 1",
|
|
64
|
+
"isForcedVariationEnabled": True,
|
|
65
|
+
"variations": [
|
|
66
|
+
{
|
|
67
|
+
"weight": 50,
|
|
68
|
+
"segments": {},
|
|
69
|
+
"id": 1,
|
|
70
|
+
"variables": [
|
|
71
|
+
{
|
|
72
|
+
"id": 1,
|
|
73
|
+
"type": "string",
|
|
74
|
+
"value": "def",
|
|
75
|
+
"key": "kaus"
|
|
76
|
+
}
|
|
77
|
+
],
|
|
78
|
+
"name": "Default"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"weight": 50,
|
|
82
|
+
"segments": {},
|
|
83
|
+
"id": 2,
|
|
84
|
+
"variables": [
|
|
85
|
+
{
|
|
86
|
+
"id": 1,
|
|
87
|
+
"type": "string",
|
|
88
|
+
"value": "var1",
|
|
89
|
+
"key": "kaus"
|
|
90
|
+
}
|
|
91
|
+
],
|
|
92
|
+
"name": "Variation-1"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"weight": 0,
|
|
96
|
+
"segments": {
|
|
97
|
+
"or": [
|
|
98
|
+
{
|
|
99
|
+
"user": "forcedKaustubh"
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
},
|
|
103
|
+
"id": 3,
|
|
104
|
+
"variables": [
|
|
105
|
+
{
|
|
106
|
+
"id": 1,
|
|
107
|
+
"type": "string",
|
|
108
|
+
"value": "var2",
|
|
109
|
+
"key": "kaus"
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
"name": "Variation-2"
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"weight": 0,
|
|
116
|
+
"segments": {},
|
|
117
|
+
"id": 4,
|
|
118
|
+
"variables": [
|
|
119
|
+
{
|
|
120
|
+
"id": 1,
|
|
121
|
+
"type": "string",
|
|
122
|
+
"value": "var3",
|
|
123
|
+
"key": "kaus"
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
"name": "Variation-3"
|
|
127
|
+
}
|
|
128
|
+
],
|
|
129
|
+
"id": 2,
|
|
130
|
+
"percentTraffic": 100
|
|
131
|
+
}
|
|
132
|
+
],
|
|
133
|
+
"features": [
|
|
134
|
+
{
|
|
135
|
+
"impactCampaign": {},
|
|
136
|
+
"rules": [
|
|
137
|
+
{
|
|
138
|
+
"campaignId": 1,
|
|
139
|
+
"type": "FLAG_ROLLOUT",
|
|
140
|
+
"ruleKey": "rolloutRule1",
|
|
141
|
+
"variationId": 1
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"type": "FLAG_TESTING",
|
|
145
|
+
"ruleKey": "testingRule1",
|
|
146
|
+
"campaignId": 2
|
|
147
|
+
}
|
|
148
|
+
],
|
|
149
|
+
"status": "ON",
|
|
150
|
+
"key": "featureOne",
|
|
151
|
+
"metrics": [
|
|
152
|
+
{
|
|
153
|
+
"type": "CUSTOM_GOAL",
|
|
154
|
+
"identifier": "e1",
|
|
155
|
+
"id": 1
|
|
156
|
+
}
|
|
157
|
+
],
|
|
158
|
+
"type": "FEATURE_FLAG",
|
|
159
|
+
"name": "featureOne",
|
|
160
|
+
"id": 1
|
|
161
|
+
}
|
|
162
|
+
]
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
class TestGetFlagWithoutBucketingSeed(unittest.TestCase):
|
|
167
|
+
"""Test cases for getFlag without bucketing seed."""
|
|
168
|
+
|
|
169
|
+
sdk_key = "abcdef"
|
|
170
|
+
account_id = "123456"
|
|
171
|
+
|
|
172
|
+
def test_should_assign_different_variations_to_users_with_different_user_ids(self):
|
|
173
|
+
"""
|
|
174
|
+
Case 1: Standard bucketing (no custom seed)
|
|
175
|
+
Scenario: Two different users ('KaustubhVWO', 'RandomUserVWO') with NO bucketing seed.
|
|
176
|
+
Expected: They should be bucketed into different variations based on their User IDs.
|
|
177
|
+
We know from our settings that KaustubhVWO -> Variation-1 and RandomUserVWO -> Default.
|
|
178
|
+
"""
|
|
179
|
+
mock_response = MagicMock(status_code=200, headers={"Content-Type": "application/json"}, json=lambda: {})
|
|
180
|
+
with patch(
|
|
181
|
+
"vwo.vwo_builder.VWOBuilder.get_settings",
|
|
182
|
+
return_value=MOCK_SETTINGS_FILE,
|
|
183
|
+
), patch(
|
|
184
|
+
"vwo.vwo_builder.VWOBuilder.update_poll_interval_and_check_and_poll",
|
|
185
|
+
return_value=None,
|
|
186
|
+
), patch(
|
|
187
|
+
"requests.Session.post",
|
|
188
|
+
return_value=mock_response,
|
|
189
|
+
):
|
|
190
|
+
options = {"sdk_key": self.sdk_key, "account_id": self.account_id}
|
|
191
|
+
vwo_client = init(options)
|
|
192
|
+
|
|
193
|
+
user1_flag = vwo_client.get_flag("featureOne", {"id": "KaustubhVWO"})
|
|
194
|
+
user2_flag = vwo_client.get_flag("featureOne", {"id": "RandomUserVWO"})
|
|
195
|
+
|
|
196
|
+
# Users with different IDs should get different variations for this split
|
|
197
|
+
self.assertNotEqual(user1_flag.get_variables(), user2_flag.get_variables())
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
class TestGetFlagWithBucketingSeed(unittest.TestCase):
|
|
201
|
+
"""Test cases for getFlag with bucketing seed."""
|
|
202
|
+
|
|
203
|
+
sdk_key = "abcdef"
|
|
204
|
+
account_id = "123456"
|
|
205
|
+
|
|
206
|
+
def test_should_assign_same_variation_to_different_users_with_same_bucketing_seed(self):
|
|
207
|
+
"""
|
|
208
|
+
Case 2: Bucketing Seed Provided
|
|
209
|
+
Scenario: Two different users ('KaustubhVWO', 'RandomUserVWO') are provided with the SAME bucketingSeed.
|
|
210
|
+
Expected: Since the seed is identical, they MUST get the same variation.
|
|
211
|
+
"""
|
|
212
|
+
mock_response = MagicMock(status_code=200, headers={"Content-Type": "application/json"}, json=lambda: {})
|
|
213
|
+
with patch(
|
|
214
|
+
"vwo.vwo_builder.VWOBuilder.get_settings",
|
|
215
|
+
return_value=MOCK_SETTINGS_FILE,
|
|
216
|
+
), patch(
|
|
217
|
+
"vwo.vwo_builder.VWOBuilder.update_poll_interval_and_check_and_poll",
|
|
218
|
+
return_value=None,
|
|
219
|
+
), patch(
|
|
220
|
+
"requests.Session.post",
|
|
221
|
+
return_value=mock_response,
|
|
222
|
+
):
|
|
223
|
+
options = {"sdk_key": self.sdk_key, "account_id": self.account_id}
|
|
224
|
+
vwo_client = init(options)
|
|
225
|
+
|
|
226
|
+
same_bucketing_seed = "common-seed-123"
|
|
227
|
+
|
|
228
|
+
user1_flag = vwo_client.get_flag("featureOne", {
|
|
229
|
+
"id": "KaustubhVWO",
|
|
230
|
+
"bucketingSeed": same_bucketing_seed,
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
user2_flag = vwo_client.get_flag("featureOne", {
|
|
234
|
+
"id": "RandomUserVWO",
|
|
235
|
+
"bucketingSeed": same_bucketing_seed,
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
self.assertEqual(user1_flag.get_variables(), user2_flag.get_variables())
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def test_should_assign_different_variations_to_users_with_different_bucketing_seeds(self):
|
|
242
|
+
"""
|
|
243
|
+
Case 3: Different Seeds
|
|
244
|
+
Scenario: The SAME User ID is used, but with DIFFERENT bucketing seeds.
|
|
245
|
+
Expected: The SDK should bucket based on the seed. Since we use seeds known
|
|
246
|
+
to produce different results ('KaustubhVWO' vs 'RandomUserVWO'), the outcomes should differ.
|
|
247
|
+
"""
|
|
248
|
+
mock_response = MagicMock(status_code=200, headers={"Content-Type": "application/json"}, json=lambda: {})
|
|
249
|
+
with patch(
|
|
250
|
+
"vwo.vwo_builder.VWOBuilder.get_settings",
|
|
251
|
+
return_value=MOCK_SETTINGS_FILE,
|
|
252
|
+
), patch(
|
|
253
|
+
"vwo.vwo_builder.VWOBuilder.update_poll_interval_and_check_and_poll",
|
|
254
|
+
return_value=None,
|
|
255
|
+
), patch(
|
|
256
|
+
"requests.Session.post",
|
|
257
|
+
return_value=mock_response,
|
|
258
|
+
):
|
|
259
|
+
options = {"sdk_key": self.sdk_key, "account_id": self.account_id}
|
|
260
|
+
vwo_client = init(options)
|
|
261
|
+
|
|
262
|
+
# Same user ID, different seeds
|
|
263
|
+
# Using the names as seeds to simulate the difference
|
|
264
|
+
user1_flag = vwo_client.get_flag("featureOne", {
|
|
265
|
+
"id": "sameId",
|
|
266
|
+
"bucketingSeed": "KaustubhVWO"
|
|
267
|
+
})
|
|
268
|
+
user2_flag = vwo_client.get_flag("featureOne", {
|
|
269
|
+
"id": "sameId",
|
|
270
|
+
"bucketingSeed": "RandomUserVWO"
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
self.assertNotEqual(user1_flag.get_variables(), user2_flag.get_variables())
|
|
274
|
+
|
|
275
|
+
def test_should_fallback_to_user_id_when_bucketing_seed_is_empty_string(self):
|
|
276
|
+
"""
|
|
277
|
+
Case 4: Empty String Seed
|
|
278
|
+
Scenario: bucketingSeed is provided but it's an empty string.
|
|
279
|
+
Expected: Empty string is falsy, so it should fall back to userId.
|
|
280
|
+
Different users should get different variations.
|
|
281
|
+
"""
|
|
282
|
+
mock_response = MagicMock(status_code=200, headers={"Content-Type": "application/json"}, json=lambda: {})
|
|
283
|
+
with patch(
|
|
284
|
+
"vwo.vwo_builder.VWOBuilder.get_settings",
|
|
285
|
+
return_value=MOCK_SETTINGS_FILE,
|
|
286
|
+
), patch(
|
|
287
|
+
"vwo.vwo_builder.VWOBuilder.update_poll_interval_and_check_and_poll",
|
|
288
|
+
return_value=None,
|
|
289
|
+
), patch(
|
|
290
|
+
"requests.Session.post",
|
|
291
|
+
return_value=mock_response,
|
|
292
|
+
):
|
|
293
|
+
options = {"sdk_key": self.sdk_key, "account_id": self.account_id}
|
|
294
|
+
vwo_client = init(options)
|
|
295
|
+
|
|
296
|
+
# Empty string should be treated as no seed
|
|
297
|
+
user1_flag = vwo_client.get_flag("featureOne", {
|
|
298
|
+
"id": "KaustubhVWO",
|
|
299
|
+
"bucketingSeed": ""
|
|
300
|
+
})
|
|
301
|
+
user2_flag = vwo_client.get_flag("featureOne", {
|
|
302
|
+
"id": "RandomUserVWO",
|
|
303
|
+
"bucketingSeed": ""
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
# Should use userIds since empty strings are falsy
|
|
307
|
+
self.assertNotEqual(user1_flag.get_variables(), user2_flag.get_variables())
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
class TestGetFlagWithCustomSaltAndBucketingSeedCombinations(unittest.TestCase):
|
|
311
|
+
"""Test cases for getFlag with custom salt and bucketing seed combinations."""
|
|
312
|
+
|
|
313
|
+
sdk_key = "abcdef"
|
|
314
|
+
account_id = "123456"
|
|
315
|
+
|
|
316
|
+
def test_no_bucketing_seed_custom_salt_present(self):
|
|
317
|
+
"""
|
|
318
|
+
No bucketing seed, custom salt present - 10 users, randomly distributed,
|
|
319
|
+
but each user getting same variation in both flags.
|
|
320
|
+
"""
|
|
321
|
+
from tests.data.dummy_test_data_reader import settings_files
|
|
322
|
+
settings_with_same_salt = settings_files.get("SETTINGS_WITH_SAME_SALT")
|
|
323
|
+
|
|
324
|
+
mock_response = MagicMock(status_code=200, headers={"Content-Type": "application/json"}, json=lambda: {})
|
|
325
|
+
with patch(
|
|
326
|
+
"vwo.vwo_builder.VWOBuilder.get_settings",
|
|
327
|
+
return_value=settings_with_same_salt,
|
|
328
|
+
), patch(
|
|
329
|
+
"vwo.vwo_builder.VWOBuilder.update_poll_interval_and_check_and_poll",
|
|
330
|
+
return_value=None,
|
|
331
|
+
), patch(
|
|
332
|
+
"requests.Session.post",
|
|
333
|
+
return_value=mock_response,
|
|
334
|
+
):
|
|
335
|
+
options = {"sdk_key": self.sdk_key, "account_id": self.account_id}
|
|
336
|
+
vwo_client = init(options)
|
|
337
|
+
|
|
338
|
+
for i in range(1, 11):
|
|
339
|
+
user_id = f"user{i}"
|
|
340
|
+
flag1 = vwo_client.get_flag("feature1", {"id": user_id})
|
|
341
|
+
flag2 = vwo_client.get_flag("feature2", {"id": user_id})
|
|
342
|
+
|
|
343
|
+
# Both flags should yield the exact same variation for the same user due to identical salt
|
|
344
|
+
self.assertEqual(flag1.get_variables(), flag2.get_variables())
|
|
345
|
+
|
|
346
|
+
def test_bucketing_seed_present_salt_present(self):
|
|
347
|
+
"""
|
|
348
|
+
Bucketing seed present, salt present - 10 users, all users getting same variation in both flags.
|
|
349
|
+
"""
|
|
350
|
+
from tests.data.dummy_test_data_reader import settings_files
|
|
351
|
+
settings_with_same_salt = settings_files.get("SETTINGS_WITH_SAME_SALT")
|
|
352
|
+
|
|
353
|
+
mock_response = MagicMock(status_code=200, headers={"Content-Type": "application/json"}, json=lambda: {})
|
|
354
|
+
with patch(
|
|
355
|
+
"vwo.vwo_builder.VWOBuilder.get_settings",
|
|
356
|
+
return_value=settings_with_same_salt,
|
|
357
|
+
), patch(
|
|
358
|
+
"vwo.vwo_builder.VWOBuilder.update_poll_interval_and_check_and_poll",
|
|
359
|
+
return_value=None,
|
|
360
|
+
), patch(
|
|
361
|
+
"requests.Session.post",
|
|
362
|
+
return_value=mock_response,
|
|
363
|
+
):
|
|
364
|
+
options = {"sdk_key": self.sdk_key, "account_id": self.account_id}
|
|
365
|
+
vwo_client = init(options)
|
|
366
|
+
|
|
367
|
+
common_bucketing_seed = "common_seed_456"
|
|
368
|
+
variations_assigned = set()
|
|
369
|
+
# loop for 10 users
|
|
370
|
+
for i in range(1, 11):
|
|
371
|
+
user_id = f"user{i}"
|
|
372
|
+
flag1 = vwo_client.get_flag("feature1", {"id": user_id, "bucketingSeed": common_bucketing_seed})
|
|
373
|
+
flag2 = vwo_client.get_flag("feature2", {"id": user_id, "bucketingSeed": common_bucketing_seed})
|
|
374
|
+
|
|
375
|
+
# Both flags should yield the exact same variation
|
|
376
|
+
self.assertEqual(flag1.get_variables(), flag2.get_variables())
|
|
377
|
+
|
|
378
|
+
# Using string representation matching Node's JSON.stringify check
|
|
379
|
+
import json
|
|
380
|
+
variations_assigned.add(json.dumps(flag1.get_variables(), sort_keys=True))
|
|
381
|
+
|
|
382
|
+
# Since the bucketing seed is the exact same for all 10 users, they MUST all get the same variation
|
|
383
|
+
self.assertEqual(len(variations_assigned), 1)
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
class TestGetFlagWithForcedVariationAndBucketingSeed(unittest.TestCase):
|
|
387
|
+
"""Test cases for getFlag with forced variation (whitelisting) and bucketing seed."""
|
|
388
|
+
|
|
389
|
+
sdk_key = "abcdef"
|
|
390
|
+
account_id = "123456"
|
|
391
|
+
|
|
392
|
+
def test_should_return_forced_variation_for_whitelisted_user_without_bucketing_seed(self):
|
|
393
|
+
"""
|
|
394
|
+
In MOCK_SETTINGS_FILE, 'forcedKaustubh' is whitelisted to Variation-2 (value: 'var2').
|
|
395
|
+
"""
|
|
396
|
+
mock_response = MagicMock(status_code=200, headers={"Content-Type": "application/json"}, json=lambda: {})
|
|
397
|
+
with patch(
|
|
398
|
+
"vwo.vwo_builder.VWOBuilder.get_settings",
|
|
399
|
+
return_value=MOCK_SETTINGS_FILE,
|
|
400
|
+
), patch(
|
|
401
|
+
"vwo.vwo_builder.VWOBuilder.update_poll_interval_and_check_and_poll",
|
|
402
|
+
return_value=None,
|
|
403
|
+
), patch(
|
|
404
|
+
"requests.Session.post",
|
|
405
|
+
return_value=mock_response,
|
|
406
|
+
):
|
|
407
|
+
options = {"sdk_key": self.sdk_key, "account_id": self.account_id}
|
|
408
|
+
vwo_client = init(options)
|
|
409
|
+
|
|
410
|
+
forced_user_flag = vwo_client.get_flag("featureOne", {"id": "forcedKaustubh"})
|
|
411
|
+
|
|
412
|
+
variables = forced_user_flag.get_variables()
|
|
413
|
+
self.assertTrue(any(var.get('value') == 'var2' for var in variables))
|
|
414
|
+
|
|
415
|
+
def test_should_still_return_forced_variation_for_whitelisted_user_when_bucketing_seed_is_present(self):
|
|
416
|
+
mock_response = MagicMock(status_code=200, headers={"Content-Type": "application/json"}, json=lambda: {})
|
|
417
|
+
with patch(
|
|
418
|
+
"vwo.vwo_builder.VWOBuilder.get_settings",
|
|
419
|
+
return_value=MOCK_SETTINGS_FILE,
|
|
420
|
+
), patch(
|
|
421
|
+
"vwo.vwo_builder.VWOBuilder.update_poll_interval_and_check_and_poll",
|
|
422
|
+
return_value=None,
|
|
423
|
+
), patch(
|
|
424
|
+
"requests.Session.post",
|
|
425
|
+
return_value=mock_response,
|
|
426
|
+
):
|
|
427
|
+
options = {"sdk_key": self.sdk_key, "account_id": self.account_id}
|
|
428
|
+
vwo_client = init(options)
|
|
429
|
+
|
|
430
|
+
forced_user_flag = vwo_client.get_flag("featureOne", {
|
|
431
|
+
"id": "forcedKaustubh",
|
|
432
|
+
"bucketingSeed": "some-seed-xyz"
|
|
433
|
+
})
|
|
434
|
+
|
|
435
|
+
variables = forced_user_flag.get_variables()
|
|
436
|
+
self.assertTrue(any(var.get('value') == 'var2' for var in variables))
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
class TestGetFlagWithAliasingEnabledAndBucketingSeed(unittest.TestCase):
|
|
440
|
+
"""Test cases for getFlag with aliasing enabled and bucketing seed."""
|
|
441
|
+
|
|
442
|
+
sdk_key = "abcdef"
|
|
443
|
+
account_id = "123456"
|
|
444
|
+
|
|
445
|
+
def test_aliased_users_resolving_to_different_user_ids_should_get_same_variation_with_same_seed(self):
|
|
446
|
+
mock_response = MagicMock(status_code=200, headers={"Content-Type": "application/json"}, json=lambda: {})
|
|
447
|
+
with patch(
|
|
448
|
+
"vwo.vwo_builder.VWOBuilder.get_settings",
|
|
449
|
+
return_value=MOCK_SETTINGS_FILE,
|
|
450
|
+
), patch(
|
|
451
|
+
"vwo.vwo_builder.VWOBuilder.update_poll_interval_and_check_and_poll",
|
|
452
|
+
return_value=None,
|
|
453
|
+
), patch(
|
|
454
|
+
"requests.Session.post",
|
|
455
|
+
return_value=mock_response,
|
|
456
|
+
), patch(
|
|
457
|
+
"requests.Session.get",
|
|
458
|
+
return_value=mock_response,
|
|
459
|
+
):
|
|
460
|
+
options = {
|
|
461
|
+
"sdk_key": self.sdk_key,
|
|
462
|
+
"account_id": self.account_id,
|
|
463
|
+
"is_aliasing_enabled": True,
|
|
464
|
+
"gateway_service": {"url": "https://gateway.vwo.com"}
|
|
465
|
+
}
|
|
466
|
+
vwo_client = init(options)
|
|
467
|
+
bucketing_seed = "shared-seed-abc"
|
|
468
|
+
|
|
469
|
+
with patch("wingify.wingify_client.get_alias_user_id", side_effect=["RandomUserVWO", "WingifyVWO"]) as mock_alias:
|
|
470
|
+
flag1 = vwo_client.get_flag("featureOne", {
|
|
471
|
+
"id": "aliasUserA",
|
|
472
|
+
"bucketingSeed": bucketing_seed
|
|
473
|
+
})
|
|
474
|
+
flag2 = vwo_client.get_flag("featureOne", {
|
|
475
|
+
"id": "aliasUserB",
|
|
476
|
+
"bucketingSeed": bucketing_seed
|
|
477
|
+
})
|
|
478
|
+
|
|
479
|
+
self.assertEqual(mock_alias.call_count, 2)
|
|
480
|
+
self.assertEqual(flag1.get_variables(), flag2.get_variables())
|
|
481
|
+
|
|
482
|
+
def test_aliased_users_resolving_to_different_user_ids_should_get_different_variations_without_seed(self):
|
|
483
|
+
mock_response = MagicMock(status_code=200, headers={"Content-Type": "application/json"}, json=lambda: {})
|
|
484
|
+
with patch(
|
|
485
|
+
"vwo.vwo_builder.VWOBuilder.get_settings",
|
|
486
|
+
return_value=MOCK_SETTINGS_FILE,
|
|
487
|
+
), patch(
|
|
488
|
+
"vwo.vwo_builder.VWOBuilder.update_poll_interval_and_check_and_poll",
|
|
489
|
+
return_value=None,
|
|
490
|
+
), patch(
|
|
491
|
+
"requests.Session.post",
|
|
492
|
+
return_value=mock_response,
|
|
493
|
+
), patch(
|
|
494
|
+
"requests.Session.get",
|
|
495
|
+
return_value=mock_response,
|
|
496
|
+
):
|
|
497
|
+
options = {
|
|
498
|
+
"sdk_key": self.sdk_key,
|
|
499
|
+
"account_id": self.account_id,
|
|
500
|
+
"is_aliasing_enabled": True,
|
|
501
|
+
"gateway_service": {"url": "https://gateway.vwo.com"}
|
|
502
|
+
}
|
|
503
|
+
vwo_client = init(options)
|
|
504
|
+
|
|
505
|
+
with patch("wingify.wingify_client.get_alias_user_id", side_effect=["RandomUserVWO", "WingifyVWO"]) as mock_alias:
|
|
506
|
+
flag1 = vwo_client.get_flag("featureOne", {"id": "aliasUserA"})
|
|
507
|
+
flag2 = vwo_client.get_flag("featureOne", {"id": "aliasUserB"})
|
|
508
|
+
|
|
509
|
+
self.assertEqual(mock_alias.call_count, 2)
|
|
510
|
+
self.assertNotEqual(flag1.get_variables(), flag2.get_variables())
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
if __name__ == "__main__":
|
|
514
|
+
unittest.main()
|