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.
Files changed (186) hide show
  1. tests/data/__init__.py +13 -0
  2. tests/data/dummy_test_data_reader.py +63 -0
  3. tests/data/user_storage.py +48 -0
  4. tests/e2e/__init__.py +13 -0
  5. tests/e2e/custom_bucketing_test.py +514 -0
  6. tests/e2e/force_users_test.py +368 -0
  7. tests/e2e/get_flag_test.py +195 -0
  8. tests/unit/__init__.py +13 -0
  9. tests/unit/packages/__init__.py +13 -0
  10. tests/unit/packages/decision_maker/__init__.py +13 -0
  11. tests/unit/packages/decision_maker/decision_maker_test.py +83 -0
  12. tests/unit/packages/segmentation_evaluator/__init__.py +13 -0
  13. tests/unit/packages/segmentation_evaluator/segmentation_evaluator_test.py +284 -0
  14. tests/unit/packages/segmentation_evaluator/segmentation_manager_test.py +215 -0
  15. tests/unit/packages/segmentation_evaluator/web_testing_segment_test.py +216 -0
  16. tests/unit/services/__init__.py +0 -0
  17. tests/unit/services/hooks_manager_test.py +80 -0
  18. tests/unit/services/internal_events_sampling_service_test.py +160 -0
  19. tests/unit/settings/__init__.py +13 -0
  20. tests/unit/settings/settings_schema_validation_test.py +67 -0
  21. tests/unit/utils/__init__.py +0 -0
  22. tests/unit/utils/campaign_util_test.py +248 -0
  23. tests/unit/utils/decision_util_force_users_test.py +790 -0
  24. tests/unit/utils/log_message_test.py +65 -0
  25. tests/unit/vwo_wingify_test.py +175 -0
  26. tests/unit/wingify_client_validation_test.py +72 -0
  27. vwo/__init__.py +35 -0
  28. vwo/models/__init__.py +13 -0
  29. vwo/models/batch_event_data.py +19 -0
  30. vwo/models/user/__init__.py +13 -0
  31. vwo/models/user/context_vwo_model.py +21 -0
  32. vwo/models/user/get_flag.py +19 -0
  33. vwo/models/vwo_options_model.py +21 -0
  34. vwo/packages/__init__.py +13 -0
  35. vwo/packages/logger/__init__.py +13 -0
  36. vwo/packages/logger/enums/__init__.py +13 -0
  37. vwo/packages/logger/enums/log_level_enum.py +19 -0
  38. vwo/packages/storage/__init__.py +13 -0
  39. vwo/packages/storage/connector.py +19 -0
  40. vwo/vwo.py +58 -0
  41. vwo/vwo_builder.py +21 -0
  42. vwo/vwo_client.py +22 -0
  43. wingify/__init__.py +36 -0
  44. wingify/api/__init__.py +13 -0
  45. wingify/api/get_flag_api.py +727 -0
  46. wingify/api/set_attribute_api.py +60 -0
  47. wingify/api/track_api.py +99 -0
  48. wingify/constants/Constants.py +94 -0
  49. wingify/constants/__init__.py +13 -0
  50. wingify/constants/sampled_debug_error_template_keys.py +34 -0
  51. wingify/decorators/__init__.py +13 -0
  52. wingify/decorators/storage_decorator.py +92 -0
  53. wingify/enums/__init__.py +13 -0
  54. wingify/enums/api_enum.py +26 -0
  55. wingify/enums/campaign_type_enum.py +22 -0
  56. wingify/enums/debug_category_enum.py +24 -0
  57. wingify/enums/event_enum.py +26 -0
  58. wingify/enums/headers_enum.py +21 -0
  59. wingify/enums/hooks_enum.py +24 -0
  60. wingify/enums/status_enum.py +21 -0
  61. wingify/enums/storage_enum.py +25 -0
  62. wingify/enums/url_enum.py +29 -0
  63. wingify/models/Alias.py +60 -0
  64. wingify/models/AliasSetResponse.py +43 -0
  65. wingify/models/__init__.py +13 -0
  66. wingify/models/batch_event_data.py +68 -0
  67. wingify/models/campaign/__init__.py +13 -0
  68. wingify/models/campaign/campaign_model.py +140 -0
  69. wingify/models/campaign/feature_model.py +95 -0
  70. wingify/models/campaign/holdout_model.py +94 -0
  71. wingify/models/campaign/impact_campaign_model.py +60 -0
  72. wingify/models/campaign/metric_model.py +42 -0
  73. wingify/models/campaign/rule_model.py +42 -0
  74. wingify/models/campaign/variable_model.py +44 -0
  75. wingify/models/campaign/variation_model.py +109 -0
  76. wingify/models/gateway_service_model.py +48 -0
  77. wingify/models/schemas/__init__.py +13 -0
  78. wingify/models/schemas/campaign_group_schema.py +19 -0
  79. wingify/models/schemas/campaign_metric_schema.py +26 -0
  80. wingify/models/schemas/campaign_schema.py +37 -0
  81. wingify/models/schemas/campaign_variation_schema.py +34 -0
  82. wingify/models/schemas/empty_object_schema.py +15 -0
  83. wingify/models/schemas/feature_schema.py +38 -0
  84. wingify/models/schemas/group_schema.py +37 -0
  85. wingify/models/schemas/holdout_schema.py +29 -0
  86. wingify/models/schemas/rule_schema.py +24 -0
  87. wingify/models/schemas/settings_schema.py +47 -0
  88. wingify/models/schemas/variable_schema.py +24 -0
  89. wingify/models/settings/__init__.py +13 -0
  90. wingify/models/settings/internal_event_sampling_settings_model.py +53 -0
  91. wingify/models/settings/settings_model.py +127 -0
  92. wingify/models/storage/__init__.py +13 -0
  93. wingify/models/storage/storage_model.py +84 -0
  94. wingify/models/user/__init__.py +13 -0
  95. wingify/models/user/context_model.py +113 -0
  96. wingify/models/user/context_vwo_model.py +34 -0
  97. wingify/models/user/get_flag.py +47 -0
  98. wingify/models/vwo_options_model.py +21 -0
  99. wingify/models/wingify_options_model.py +129 -0
  100. wingify/packages/__init__.py +13 -0
  101. wingify/packages/decision_maker/__init__.py +13 -0
  102. wingify/packages/decision_maker/decision_maker.py +89 -0
  103. wingify/packages/logger/__init__.py +13 -0
  104. wingify/packages/logger/core/__init__.py +13 -0
  105. wingify/packages/logger/core/log_manager.py +123 -0
  106. wingify/packages/logger/core/log_transport_manager.py +57 -0
  107. wingify/packages/logger/enums/__init__.py +13 -0
  108. wingify/packages/logger/enums/log_level_enum.py +24 -0
  109. wingify/packages/logger/enums/log_level_number_enum.py +21 -0
  110. wingify/packages/logger/log_message_builder.py +70 -0
  111. wingify/packages/logger/logger.py +38 -0
  112. wingify/packages/logger/transports/__init__.py +13 -0
  113. wingify/packages/logger/transports/console_transport.py +43 -0
  114. wingify/packages/network_layer/__init__.py +13 -0
  115. wingify/packages/network_layer/client/__init__.py +13 -0
  116. wingify/packages/network_layer/client/network_client.py +167 -0
  117. wingify/packages/network_layer/handlers/__init__.py +13 -0
  118. wingify/packages/network_layer/handlers/request_handler.py +40 -0
  119. wingify/packages/network_layer/manager/__init__.py +13 -0
  120. wingify/packages/network_layer/manager/network_manager.py +79 -0
  121. wingify/packages/network_layer/models/__init__.py +13 -0
  122. wingify/packages/network_layer/models/global_request_model.py +70 -0
  123. wingify/packages/network_layer/models/request_model.py +133 -0
  124. wingify/packages/network_layer/models/response_model.py +55 -0
  125. wingify/packages/segmentation_evaluator/__init__.py +13 -0
  126. wingify/packages/segmentation_evaluator/core/__init__.py +13 -0
  127. wingify/packages/segmentation_evaluator/core/segmentation_manager.py +140 -0
  128. wingify/packages/segmentation_evaluator/enums/__init__.py +13 -0
  129. wingify/packages/segmentation_evaluator/enums/segment_operand_regex_enum.py +31 -0
  130. wingify/packages/segmentation_evaluator/enums/segment_operand_value_enum.py +29 -0
  131. wingify/packages/segmentation_evaluator/enums/segment_operator_value_enum.py +37 -0
  132. wingify/packages/segmentation_evaluator/evaluators/__init__.py +13 -0
  133. wingify/packages/segmentation_evaluator/evaluators/segment_evaluator.py +237 -0
  134. wingify/packages/segmentation_evaluator/evaluators/segment_operand_evaluator.py +518 -0
  135. wingify/packages/segmentation_evaluator/utils/__init__.py +13 -0
  136. wingify/packages/segmentation_evaluator/utils/segment_util.py +33 -0
  137. wingify/packages/segmentation_evaluator/utils/web_testing_segment_util.py +295 -0
  138. wingify/packages/storage/__init__.py +13 -0
  139. wingify/packages/storage/connector.py +25 -0
  140. wingify/packages/storage/storage.py +39 -0
  141. wingify/resources/__init__.py +13 -0
  142. wingify/resources/debug-messages.json +21 -0
  143. wingify/resources/error-messages.json +62 -0
  144. wingify/resources/info-message.json +47 -0
  145. wingify/resources/trace-messages.json +1 -0
  146. wingify/resources/warn-messages.json +1 -0
  147. wingify/services/__init__.py +13 -0
  148. wingify/services/batch_event_queue.py +140 -0
  149. wingify/services/campaign_decision_service.py +268 -0
  150. wingify/services/hooks_manager.py +65 -0
  151. wingify/services/internal_events_sampling_service.py +62 -0
  152. wingify/services/settings_manager.py +293 -0
  153. wingify/services/storage_service.py +58 -0
  154. wingify/services/url_service.py +51 -0
  155. wingify/utils/__init__.py +13 -0
  156. wingify/utils/aliasing_util.py +108 -0
  157. wingify/utils/brand_context.py +26 -0
  158. wingify/utils/brand_util.py +37 -0
  159. wingify/utils/campaign_util.py +592 -0
  160. wingify/utils/data_type_util.py +125 -0
  161. wingify/utils/debugger_service_util.py +58 -0
  162. wingify/utils/decision_util.py +589 -0
  163. wingify/utils/event_util.py +85 -0
  164. wingify/utils/function_util.py +188 -0
  165. wingify/utils/gateway_service_util.py +179 -0
  166. wingify/utils/holdout_util.py +264 -0
  167. wingify/utils/impression_util.py +151 -0
  168. wingify/utils/internal_events_sampling_util.py +106 -0
  169. wingify/utils/log_message_util.py +95 -0
  170. wingify/utils/meg_util.py +561 -0
  171. wingify/utils/model_utils.py +136 -0
  172. wingify/utils/network_util.py +706 -0
  173. wingify/utils/rule_evaluation_util.py +102 -0
  174. wingify/utils/settings_util.py +39 -0
  175. wingify/utils/usage_stats_util.py +116 -0
  176. wingify/utils/uuid_util.py +81 -0
  177. wingify/vwo_client.py +21 -0
  178. wingify/wingify.py +159 -0
  179. wingify/wingify_builder.py +282 -0
  180. wingify/wingify_client.py +520 -0
  181. wingify_fme_python_sdk-1.70.0.dist-info/METADATA +1415 -0
  182. wingify_fme_python_sdk-1.70.0.dist-info/RECORD +186 -0
  183. wingify_fme_python_sdk-1.70.0.dist-info/WHEEL +5 -0
  184. wingify_fme_python_sdk-1.70.0.dist-info/licenses/LICENSE +202 -0
  185. wingify_fme_python_sdk-1.70.0.dist-info/licenses/NOTICE +18 -0
  186. wingify_fme_python_sdk-1.70.0.dist-info/top_level.txt +3 -0
@@ -0,0 +1,216 @@
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 sys
17
+ import unittest
18
+ from unittest.mock import patch
19
+
20
+ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..", "..")))
21
+
22
+ from wingify.models.user.context_model import ContextModel
23
+ from wingify.packages.segmentation_evaluator.evaluators.segment_evaluator import (
24
+ SegmentEvaluator,
25
+ )
26
+ from wingify.packages.segmentation_evaluator.core.segmentation_manager import (
27
+ SegmentationManager,
28
+ )
29
+ from wingify.packages.segmentation_evaluator.utils.web_testing_segment_util import (
30
+ evaluate_web_testing_campaign_variation,
31
+ normalize_web_testing_campaigns_map,
32
+ parse_web_testing_campaigns_from_context,
33
+ )
34
+ from wingify.services.settings_manager import SettingsManager
35
+
36
+
37
+ def _context_with_platform_vars(extra: dict):
38
+ base = {"id": "user-1", **extra}
39
+ with patch.object(SettingsManager, "get_instance") as m:
40
+ m.return_value.get_account_id.return_value = "1"
41
+ return ContextModel(base)
42
+
43
+
44
+ class TestWebTestingSegmentUtil(unittest.TestCase):
45
+ def test_evaluate_variation_patterns(self):
46
+ campaign_assignments_map = {"1": "1", "2": "2"}
47
+ self.assertTrue(evaluate_web_testing_campaign_variation("1_1", campaign_assignments_map)[0])
48
+ self.assertFalse(evaluate_web_testing_campaign_variation("1_1", campaign_assignments_map)[1])
49
+ self.assertFalse(evaluate_web_testing_campaign_variation("1_2", campaign_assignments_map)[0])
50
+ self.assertFalse(evaluate_web_testing_campaign_variation("99_1", campaign_assignments_map)[0])
51
+ self.assertTrue(evaluate_web_testing_campaign_variation("1_!2", campaign_assignments_map)[0])
52
+ self.assertFalse(evaluate_web_testing_campaign_variation("1_!1", campaign_assignments_map)[0])
53
+ self.assertFalse(evaluate_web_testing_campaign_variation("99_!1", campaign_assignments_map)[0])
54
+ self.assertTrue(evaluate_web_testing_campaign_variation("!99", campaign_assignments_map)[0])
55
+ self.assertFalse(evaluate_web_testing_campaign_variation("!1", campaign_assignments_map)[0])
56
+
57
+ def test_null_map_like_node(self):
58
+ self.assertTrue(evaluate_web_testing_campaign_variation("!1", None)[0])
59
+ self.assertFalse(evaluate_web_testing_campaign_variation("1_1", None)[0])
60
+
61
+ def test_invalid_encoding(self):
62
+ evaluation_result_pair = evaluate_web_testing_campaign_variation("bogus", {"1": "1"})
63
+ self.assertFalse(evaluation_result_pair[0])
64
+ self.assertTrue(evaluation_result_pair[1])
65
+
66
+ def test_multi_digit_ids(self):
67
+ campaign_assignments_map = {"122": "4"}
68
+ self.assertTrue(evaluate_web_testing_campaign_variation("122_4", campaign_assignments_map)[0])
69
+ self.assertTrue(evaluate_web_testing_campaign_variation("122_!1", campaign_assignments_map)[0])
70
+ self.assertFalse(evaluate_web_testing_campaign_variation("!122", campaign_assignments_map)[0])
71
+
72
+ def test_campaign_only_any_variation(self):
73
+ self.assertTrue(
74
+ evaluate_web_testing_campaign_variation("100", {"100": "1"})[0]
75
+ )
76
+ self.assertTrue(
77
+ evaluate_web_testing_campaign_variation("100", {"100": "9"})[0]
78
+ )
79
+ self.assertFalse(evaluate_web_testing_campaign_variation("100", {})[0])
80
+ self.assertFalse(
81
+ evaluate_web_testing_campaign_variation("100", {"99": "1"})[0]
82
+ )
83
+ self.assertFalse(
84
+ evaluate_web_testing_campaign_variation(
85
+ "100", {"1": "1", "2": "2"}
86
+ )[0]
87
+ )
88
+
89
+ def test_normalize_coerces_types(self):
90
+ self.assertEqual(
91
+ normalize_web_testing_campaigns_map({129: 1, "14": 2}),
92
+ {"129": "1", "14": "2"},
93
+ )
94
+
95
+
96
+ class TestWebTestingSegmentEvaluator(unittest.TestCase):
97
+ def _evaluator(self, context: ContextModel):
98
+ ev = SegmentEvaluator()
99
+ ev.context = context
100
+ return ev
101
+
102
+ def test_or_json_string_web_testing_campaigns(self):
103
+ ctx = _context_with_platform_vars(
104
+ {
105
+ "platform_variables": {
106
+ "web_testing_campaigns": '{"1":"1"}',
107
+ }
108
+ }
109
+ )
110
+ ev = self._evaluator(ctx)
111
+ self.assertTrue(ev.is_segmentation_valid({"or": [{"campaignVariation": "1_1"}]}, {}))
112
+
113
+ def test_or_object_web_testing_campaigns(self):
114
+ ctx = _context_with_platform_vars(
115
+ {"platform_variables": {"web_testing_campaigns": {"1": 1}}}
116
+ )
117
+ ev = self._evaluator(ctx)
118
+ self.assertTrue(ev.is_segmentation_valid({"or": [{"campaignVariation": "1_1"}]}, {}))
119
+
120
+ def test_not_in_campaign(self):
121
+ ctx = _context_with_platform_vars(
122
+ {"platform_variables": {"web_testing_campaigns": "{}"}}
123
+ )
124
+ ev = self._evaluator(ctx)
125
+ self.assertTrue(ev.is_segmentation_valid({"or": [{"campaignVariation": "!1"}]}, {}))
126
+
127
+ def test_nested_not_campaign_variation(self):
128
+ ctx = _context_with_platform_vars(
129
+ {"platform_variables": {"web_testing_campaigns": '{"1":"1"}'}}
130
+ )
131
+ ev = self._evaluator(ctx)
132
+ self.assertFalse(
133
+ ev.is_segmentation_valid({"not": {"campaignVariation": "1_1"}}, {})
134
+ )
135
+
136
+ def test_campaign_id_only(self):
137
+ ctx = _context_with_platform_vars(
138
+ {"platform_variables": {"web_testing_campaigns": '{"100":"2"}'}}
139
+ )
140
+ ev = self._evaluator(ctx)
141
+ self.assertTrue(ev.is_segmentation_valid({"or": [{"campaignVariation": "100"}]}, {}))
142
+
143
+ def test_operand_trimmed(self):
144
+ ctx = _context_with_platform_vars(
145
+ {"platform_variables": {"web_testing_campaigns": '{"1":"1"}'}}
146
+ )
147
+ ev = self._evaluator(ctx)
148
+ self.assertTrue(
149
+ ev.is_segmentation_valid({"or": [{"campaignVariation": " 1_1 "}]}, {})
150
+ )
151
+
152
+ def test_json_array_rejected(self):
153
+ ctx = _context_with_platform_vars(
154
+ {"platform_variables": {"web_testing_campaigns": "[]"}}
155
+ )
156
+ ev = self._evaluator(ctx)
157
+ self.assertFalse(
158
+ ev.is_segmentation_valid({"or": [{"campaignVariation": "1_1"}]}, {})
159
+ )
160
+
161
+ def test_numeric_operand_coerced_to_string(self):
162
+ ctx = _context_with_platform_vars(
163
+ {"platform_variables": {"web_testing_campaigns": '{"1":"1"}'}}
164
+ )
165
+ ev = self._evaluator(ctx)
166
+ self.assertTrue(ev.is_segmentation_valid({"or": [{"campaignVariation": 1}]}, {}))
167
+ ctx_float = _context_with_platform_vars(
168
+ {"platform_variables": {"web_testing_campaigns": '{"100":"2"}'}}
169
+ )
170
+ ev_float = self._evaluator(ctx_float)
171
+ self.assertTrue(
172
+ ev_float.is_segmentation_valid({"or": [{"campaignVariation": 100.0}]}, {})
173
+ )
174
+
175
+
176
+ class TestWebTestingValidateSegmentationPrecheck(unittest.TestCase):
177
+ def test_precheck_false_when_campaign_variation_without_assignments_feed(self):
178
+ ctx = _context_with_platform_vars({})
179
+ segmentation_manager = SegmentationManager.get_instance()
180
+ segmentation_manager.attach_evaluator()
181
+ segmentation_manager.evaluator.context = ctx
182
+ self.assertFalse(
183
+ segmentation_manager.validate_segmentation(
184
+ {"not": {"campaignVariation": "1_1"}}, {}
185
+ )
186
+ )
187
+
188
+ def test_precheck_true_when_campaign_variation_with_empty_assignment_object_string(
189
+ self,
190
+ ):
191
+ ctx = _context_with_platform_vars(
192
+ {"platform_variables": {"web_testing_campaigns": "{}"}}
193
+ )
194
+ segmentation_manager = SegmentationManager.get_instance()
195
+ segmentation_manager.attach_evaluator()
196
+ segmentation_manager.evaluator.context = ctx
197
+ self.assertTrue(
198
+ segmentation_manager.validate_segmentation(
199
+ {"or": [{"campaignVariation": "!1"}]}, {}
200
+ )
201
+ )
202
+
203
+ def test_duplicate_keys_in_json_string_last_value_wins(self):
204
+ ctx = _context_with_platform_vars(
205
+ {
206
+ "platform_variables": {
207
+ "web_testing_campaigns": '{"122":"1","122":"2"}',
208
+ }
209
+ }
210
+ )
211
+ campaigns_map_from_context = parse_web_testing_campaigns_from_context(ctx)
212
+ self.assertEqual(campaigns_map_from_context, {"122": "2"})
213
+
214
+
215
+ if __name__ == "__main__":
216
+ unittest.main()
File without changes
@@ -0,0 +1,80 @@
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 integrations callback error handling in ``HooksManager``."""
16
+
17
+ import unittest
18
+ from unittest.mock import patch
19
+
20
+ from wingify.packages.logger.core.log_manager import LogManager
21
+ from wingify.services.hooks_manager import HooksManager
22
+
23
+
24
+ class HooksManagerTest(unittest.TestCase):
25
+ """Tests for ``HooksManager.execute`` integrations callback behavior."""
26
+
27
+ def setUp(self):
28
+ """
29
+ Initialize logger for tests that assert on ``error_log`` output.
30
+
31
+ :return: None.
32
+ """
33
+ LogManager({"level": "ERROR"})
34
+
35
+ def test_execute_logs_integrations_callback_failure_without_raising(self):
36
+ """
37
+ Verify callback exceptions are logged and do not propagate to the caller.
38
+
39
+ Ensures ``getFlag`` / ``trackEvent`` continue after an integrations failure
40
+ with a clear ``INTEGRATIONS_CALLBACK_FAILED`` message.
41
+
42
+ :return: None. Asserts error log key and message content.
43
+ """
44
+ def failing_callback(_properties):
45
+ # Simulates user-thrown error inside integrations callback
46
+ raise RuntimeError("callback exploded")
47
+
48
+ manager = HooksManager(
49
+ {"integrations": {"callback": failing_callback}}
50
+ )
51
+
52
+ with patch.object(
53
+ LogManager.get_instance(), "error_log"
54
+ ) as mock_error_log:
55
+ # Must not raise — API flow should continue
56
+ manager.execute({"api": "getFlag", "featureKey": "feature1"})
57
+
58
+ mock_error_log.assert_called_once()
59
+ self.assertEqual(mock_error_log.call_args[0][0], "INTEGRATIONS_CALLBACK_FAILED")
60
+ self.assertIn("callback exploded", mock_error_log.call_args[1]["data"]["err"])
61
+
62
+ def test_execute_runs_successful_callback(self):
63
+ """
64
+ Verify a valid integrations callback receives properties and runs normally.
65
+
66
+ :return: None. Asserts callback payload is passed through unchanged.
67
+ """
68
+ received = {}
69
+
70
+ def callback(properties):
71
+ received.update(properties)
72
+
73
+ manager = HooksManager({"integrations": {"callback": callback}})
74
+ manager.execute({"api": "trackEvent", "event_name": "clickElement"})
75
+
76
+ self.assertEqual(received["event_name"], "clickElement")
77
+
78
+
79
+ if __name__ == "__main__":
80
+ unittest.main()
@@ -0,0 +1,160 @@
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 unittest
16
+ from wingify.constants.Constants import Constants
17
+ from wingify.models.settings.settings_model import SettingsModel
18
+ from wingify.services.internal_events_sampling_service import InternalEventsSamplingService
19
+ from wingify.utils import internal_events_sampling_util
20
+
21
+ class InternalEventsSamplingServiceTest(unittest.TestCase):
22
+ """
23
+ Unit tests for internal SDK event sampling.
24
+
25
+ Covers two layers:
26
+ - `internal_events_sampling_util` — reads DaCDN sampling config and evaluates pure sampling math
27
+ - `InternalEventsSamplingService` — applies send/drop decisions for usage-stats and sampled debug events
28
+ """
29
+
30
+ def setUp(self):
31
+ self.mock_sampling_settings = self.create_mock_sampling_settings()
32
+
33
+ def create_mock_sampling_settings(self):
34
+ """
35
+ Builds a representative SettingsModel object for sampling tests.
36
+ """
37
+ data = {
38
+ "accountId": 123456,
39
+ "sdkKey": "test-sdk-key",
40
+ "version": 1,
41
+ "features": [],
42
+ "campaigns": [],
43
+ "sdkMetaInfo": {
44
+ "wasInitializedEarlier": False
45
+ },
46
+ "sampling": {
47
+ "usage": {"server": 20.0},
48
+ "debug": {"server": 50.0}
49
+ },
50
+ "alwaysApplySampling": {
51
+ "server": True
52
+ }
53
+ }
54
+ return SettingsModel(data)
55
+
56
+ def create_empty_settings(self):
57
+ data = {
58
+ "accountId": 123456,
59
+ "sdkKey": "test-sdk-key",
60
+ "version": 1,
61
+ "features": [],
62
+ "campaigns": []
63
+ }
64
+ return SettingsModel(data)
65
+
66
+ # --- InternalEventsSamplingUtil: defaults and config parsing ---
67
+
68
+ def test_server_default_sampling_is_used_when_value_missing(self):
69
+ self.assertEqual(
70
+ Constants.INTERNAL_EVENTS_DEFAULT_SAMPLING_PERCENT_SERVER,
71
+ internal_events_sampling_util.get_default_sampling_percent()
72
+ )
73
+ self.assertEqual(10.0, internal_events_sampling_util.normalize_sampling_percent(None))
74
+ self.assertEqual(10.0, internal_events_sampling_util.normalize_sampling_percent(150.0))
75
+
76
+ def test_runtime_defaults_are_used_when_sampling_absent(self):
77
+ empty_settings = self.create_empty_settings()
78
+ self.assertEqual(10.0, internal_events_sampling_util.get_usage_stats_sampling_percent(empty_settings))
79
+ self.assertEqual(10.0, internal_events_sampling_util.get_debug_event_sampling_percent(empty_settings))
80
+
81
+ def test_usage_stats_sampling_is_read_for_server_runtime(self):
82
+ self.assertEqual(20.0, internal_events_sampling_util.get_usage_stats_sampling_percent(self.mock_sampling_settings))
83
+
84
+ def test_always_apply_sampling_server_is_read_from_settings(self):
85
+ self.assertTrue(internal_events_sampling_util.should_apply_sampling(self.mock_sampling_settings))
86
+ self.assertFalse(internal_events_sampling_util.should_apply_sampling(self.create_empty_settings()))
87
+
88
+ # --- InternalEventsSamplingUtil: sampling math and debug key classification ---
89
+
90
+ def test_sampling_passes_within_threshold(self):
91
+ # 0.1 maps to bucket 10, which is within a 20% threshold
92
+ self.assertTrue(internal_events_sampling_util.passes_sampling_percent(20.0, 0.1))
93
+
94
+ def test_sampling_fails_above_threshold(self):
95
+ # 0.99 maps to bucket 99, which exceeds a 20% threshold
96
+ self.assertFalse(internal_events_sampling_util.passes_sampling_percent(20.0, 0.99))
97
+
98
+ def test_sampled_debug_keys_are_detected(self):
99
+ self.assertTrue(internal_events_sampling_util.is_sampled_debug_error_template_key("EVENT_NOT_FOUND"))
100
+ self.assertTrue(internal_events_sampling_util.is_sampled_debug_error_template_key("FEATURE_NOT_FOUND"))
101
+
102
+ def test_non_sampled_debug_keys_are_not_detected(self):
103
+ self.assertFalse(internal_events_sampling_util.is_sampled_debug_error_template_key("INVALID_OPTIONS"))
104
+ self.assertFalse(internal_events_sampling_util.is_sampled_debug_error_template_key("EXECUTION_FAILED"))
105
+ self.assertFalse(internal_events_sampling_util.is_sampled_debug_error_template_key("NETWORK_CALL_FAILED"))
106
+ self.assertFalse(internal_events_sampling_util.is_sampled_debug_error_template_key(""))
107
+
108
+ # --- InternalEventsSamplingService: usage-stats send decisions ---
109
+
110
+ def test_usage_stats_always_send_when_always_apply_sampling_false(self):
111
+ sampling_service = InternalEventsSamplingService(lambda: 0.0)
112
+ settings = self.create_empty_settings()
113
+ settings._always_apply_sampling = type('AlwaysApplySampling', (object,), {'get_server': lambda self: False})()
114
+ settings._sampling = type('EventCategorySamplingRates', (object,), {
115
+ 'get_usage': lambda self: type('PlatformSamplingRates', (object,), {'get_server': lambda self: 0.0})(),
116
+ 'get_debug': lambda self: None
117
+ })()
118
+
119
+ self.assertTrue(sampling_service.should_send_usage_stats_event(settings))
120
+
121
+ def test_usage_stats_sampling_applies_when_always_apply_sampling_true(self):
122
+ # random=1.0 always fails sampling; with 0% usage threshold the event is dropped
123
+ sampling_service = InternalEventsSamplingService(lambda: 1.0)
124
+ settings = self.create_empty_settings()
125
+ settings._always_apply_sampling = type('AlwaysApplySampling', (object,), {'get_server': lambda self: True})()
126
+ settings._sampling = type('EventCategorySamplingRates', (object,), {
127
+ 'get_usage': lambda self: type('PlatformSamplingRates', (object,), {'get_server': lambda self: 0.0})(),
128
+ 'get_debug': lambda self: None
129
+ })()
130
+
131
+ self.assertFalse(sampling_service.should_send_usage_stats_event(settings))
132
+
133
+ # --- InternalEventsSamplingService: sampled debug send decisions ---
134
+
135
+ def test_sampled_debug_events_always_send_when_always_apply_sampling_false(self):
136
+ sampling_service = InternalEventsSamplingService(lambda: 1.0)
137
+ settings = self.create_empty_settings()
138
+ settings._always_apply_sampling = type('AlwaysApplySampling', (object,), {'get_server': lambda self: False})()
139
+ settings._sampling = type('EventCategorySamplingRates', (object,), {
140
+ 'get_usage': lambda self: None,
141
+ 'get_debug': lambda self: type('PlatformSamplingRates', (object,), {'get_server': lambda self: 0.0})()
142
+ })()
143
+
144
+ self.assertTrue(sampling_service.should_send_sampled_debug_event(settings))
145
+
146
+ def test_sampled_debug_events_apply_debug_sampling_when_always_apply_sampling_true(self):
147
+ # mock_sampling_settings has debug.server=50%, alwaysApplySampling.server=True; random=0.0 always passes
148
+ sampling_service = InternalEventsSamplingService(lambda: 0.0)
149
+ self.assertTrue(sampling_service.should_send_sampled_debug_event(self.mock_sampling_settings))
150
+
151
+ def test_sampled_debug_events_blocked_when_always_apply_sampling_true_and_sampling_zero(self):
152
+ sampling_service = InternalEventsSamplingService(lambda: 1.0)
153
+ settings = self.create_empty_settings()
154
+ settings._always_apply_sampling = type('AlwaysApplySampling', (object,), {'get_server': lambda self: True})()
155
+ settings._sampling = type('EventCategorySamplingRates', (object,), {
156
+ 'get_usage': lambda self: None,
157
+ 'get_debug': lambda self: type('PlatformSamplingRates', (object,), {'get_server': lambda self: 0.0})()
158
+ })()
159
+
160
+ self.assertFalse(sampling_service.should_send_sampled_debug_event(settings))
@@ -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,67 @@
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 wingify.services.settings_manager import SettingsManager
20
+ from tests.data.dummy_test_data_reader import settings_files
21
+
22
+ # Add the parent directory to the sys.path
23
+ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..")))
24
+
25
+ class SettingsSchemaValidationTest(unittest.TestCase):
26
+ """Test suite for settings schema validation."""
27
+ def setUp(self):
28
+ """Set up test fixtures before each test method."""
29
+ # Clear all mocks before each test
30
+ self.settings_manager = None
31
+ # Mock LogManager
32
+ self.log_manager_mock = MagicMock()
33
+ self.log_manager_instance_mock = MagicMock()
34
+ self.log_manager_mock.get_instance.return_value = self.log_manager_instance_mock
35
+ with patch('wingify.services.settings_manager.LogManager', self.log_manager_mock):
36
+ self.settings_manager = SettingsManager({
37
+ "account_id": 123,
38
+ "sdk_key": "123"
39
+ })
40
+
41
+ def test_settings_with_wrong_type_for_values_should_fail_validation(self):
42
+ """Test that settings with wrong type for values should fail validation."""
43
+ settings = settings_files.get("SETTINGS_WITH_WRONG_TYPE_FOR_VALUES")
44
+ result = SettingsManager.is_settings_valid(settings)
45
+ self.assertFalse(result)
46
+
47
+ def test_settings_with_extra_key_at_root_level_should_not_fail_validation(self):
48
+ """Test that settings with extra key at root level should not fail validation."""
49
+ settings = settings_files.get("SETTINGS_WITH_EXTRA_KEYS_AT_ROOT_LEVEL")
50
+ result = SettingsManager.is_settings_valid(settings)
51
+ self.assertTrue(result)
52
+
53
+ def test_settings_with_extra_key_inside_objects_should_not_fail_validation(self):
54
+ """Test that settings with extra key inside objects should not fail validation."""
55
+ settings = settings_files.get("SETTINGS_WITH_EXTRA_KEYS_INSIDE_OBJECTS")
56
+ result = SettingsManager.is_settings_valid(settings)
57
+ self.assertTrue(result)
58
+
59
+ def test_settings_with_no_feature_and_campaign_should_not_fail_validation(self):
60
+ """Test that settings with no feature and campaign should not fail validation."""
61
+ settings = settings_files.get("SETTINGS_WITH_NO_FEATURES_AND_CAMPAIGNS")
62
+ result = SettingsManager.is_settings_valid(settings)
63
+ self.assertTrue(result)
64
+
65
+
66
+ if __name__ == "__main__":
67
+ unittest.main()
File without changes