fb-python-sdk 1.1.4__py3-none-any.whl → 1.1.6__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.
- {fb_python_sdk-1.1.4.dist-info → fb_python_sdk-1.1.6.dist-info}/METADATA +26 -18
- {fb_python_sdk-1.1.4.dist-info → fb_python_sdk-1.1.6.dist-info}/RECORD +11 -16
- {fb_python_sdk-1.1.4.dist-info → fb_python_sdk-1.1.6.dist-info}/WHEEL +1 -1
- fb_python_sdk-1.1.6.dist-info/top_level.txt +2 -0
- fbclient/client.py +2 -2
- fbclient/common_types.py +18 -0
- fbclient/flag_change_notification.py +15 -14
- fbclient/utils/rwlock.py +1 -1
- tests/test_fbclient.py +15 -0
- tests/test_flag_change_notification.py +5 -0
- fb_python_sdk-1.1.4.dist-info/top_level.txt +0 -3
- fbclient/version.py +0 -1
- intergration_tests/__init__.py +0 -0
- intergration_tests/readme.py +0 -25
- intergration_tests/run_in_start_no_wait.py +0 -36
- intergration_tests/run_in_start_wait.py +0 -50
- {fb_python_sdk-1.1.4.dist-info → fb_python_sdk-1.1.6.dist-info}/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: fb-python-sdk
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.6
|
|
4
4
|
Summary: A Python SDK for FeatBit plateform
|
|
5
5
|
Home-page: https://github.com/featbit/featbit-python-sdk
|
|
6
6
|
Author: Dian SUN
|
|
@@ -19,18 +19,19 @@ Classifier: Programming Language :: Python :: 3.8
|
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.9
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.10
|
|
21
21
|
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
-
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Requires-Python: >=3.6, <=3.12
|
|
23
24
|
Description-Content-Type: text/markdown
|
|
24
25
|
License-File: LICENSE
|
|
25
|
-
Requires-Dist: certifi
|
|
26
|
-
Requires-Dist: urllib3
|
|
27
|
-
Requires-Dist: python-dateutil
|
|
28
|
-
Requires-Dist: websocket-client
|
|
26
|
+
Requires-Dist: certifi >=2018.4.16
|
|
27
|
+
Requires-Dist: urllib3 >=1.22.0
|
|
28
|
+
Requires-Dist: python-dateutil >=2.8.2
|
|
29
|
+
Requires-Dist: websocket-client >=1.0.0
|
|
29
30
|
Provides-Extra: dev
|
|
30
|
-
Requires-Dist: certifi
|
|
31
|
-
Requires-Dist: urllib3
|
|
32
|
-
Requires-Dist: websocket-client
|
|
33
|
-
Requires-Dist: python-dateutil
|
|
31
|
+
Requires-Dist: certifi >=2018.4.16 ; extra == 'dev'
|
|
32
|
+
Requires-Dist: urllib3 >=1.22.0 ; extra == 'dev'
|
|
33
|
+
Requires-Dist: websocket-client >=1.0.0 ; extra == 'dev'
|
|
34
|
+
Requires-Dist: python-dateutil >=2.8.2 ; extra == 'dev'
|
|
34
35
|
Requires-Dist: flake8 ; extra == 'dev'
|
|
35
36
|
Requires-Dist: pytest ; extra == 'dev'
|
|
36
37
|
Requires-Dist: pytest-mock ; extra == 'dev'
|
|
@@ -70,8 +71,8 @@ Before using the SDK, you need to obtain the environment secret and SDK URLs.
|
|
|
70
71
|
|
|
71
72
|
Follow the documentation below to retrieve these values
|
|
72
73
|
|
|
73
|
-
- [How to get the environment secret](https://docs.featbit.co/
|
|
74
|
-
- [How to get the SDK URLs](https://docs.featbit.co/
|
|
74
|
+
- [How to get the environment secret](https://docs.featbit.co/sdk/faq#how-to-get-the-environment-secret)
|
|
75
|
+
- [How to get the SDK URLs](https://docs.featbit.co/sdk/faq#how-to-get-the-sdk-urls)
|
|
75
76
|
|
|
76
77
|
### Quick Start
|
|
77
78
|
|
|
@@ -184,10 +185,17 @@ If you would like to get variations of all feature flags in a special environmen
|
|
|
184
185
|
if client.initialize:
|
|
185
186
|
user = {'key': user_key, 'name': user_name}
|
|
186
187
|
all_flag_values = client.get_all_latest_flag_variations(user)
|
|
187
|
-
|
|
188
|
+
# get all feature flag keys
|
|
189
|
+
keys = all_flag_values.keys()
|
|
190
|
+
for flag_key in keys:
|
|
191
|
+
# get viariation detail
|
|
192
|
+
detail = all_flag_values.get(flag_key, default=None)
|
|
193
|
+
# get viariation
|
|
194
|
+
value = all_flag_values.get_variation(flag_key, default=None)
|
|
188
195
|
```
|
|
189
196
|
|
|
190
|
-
> Note
|
|
197
|
+
> **Note**
|
|
198
|
+
> If evaluation happened before the client is initialized, or you provide the wrong flag key/user for evaluation, the `variation` calls will return the default value. The `fbclient.common_types.EvalDetail` will explain the details of the latest evaluation including error reason.
|
|
191
199
|
|
|
192
200
|
### Flag Tracking
|
|
193
201
|
|
|
@@ -198,7 +206,7 @@ Note that a flag value change listener is bound to a specific user and flag key.
|
|
|
198
206
|
The flag value change listener will be notified whenever the SDK receives any change to any feature flag's configuration,
|
|
199
207
|
or to a user segment that is referenced by a feature flag. To register a flag value change listener, use `add_flag_value_may_changed_listener` or `add_flag_value_changed_listener`
|
|
200
208
|
|
|
201
|
-
When you track a flag change using `
|
|
209
|
+
When you track a flag change using `add_flag_value_maybe_changed_listener`, this does not necessarily mean the flag's value has changed for any particular flag, only that some part of the flag configuration was changed so that it *_MAY_* return a different value than it previously returned for some user.
|
|
202
210
|
|
|
203
211
|
If you want to track a flag whose value *_MUST_* be changed, `add_flag_value_changed_listener` will register a listener that will be notified if and only if the flag value changes.
|
|
204
212
|
|
|
@@ -208,9 +216,9 @@ If the SDK is in offline mode, then it cannot know when there is a change, becau
|
|
|
208
216
|
```python
|
|
209
217
|
if client.initialize:
|
|
210
218
|
# flag value may be changed
|
|
211
|
-
client.flag_tracker.
|
|
219
|
+
client.flag_tracker.add_flag_value_maybe_changed_listener(flag_key, user, flag_value_maybe_changed_callback_fn)
|
|
212
220
|
# flag value must be changed
|
|
213
|
-
client.flag_tracker.add_flag_value_changed_listener(flag_key, user,
|
|
221
|
+
client.flag_tracker.add_flag_value_changed_listener(flag_key, user, flag_value_changed_callback_fn)
|
|
214
222
|
|
|
215
223
|
```
|
|
216
224
|
`flag_key`: the key of the feature flag to track
|
|
@@ -268,4 +276,4 @@ otherwise, the custom event may not be included into the experiment result.
|
|
|
268
276
|
feature, [submit an issue](https://github.com/featbit/featbit-python-sdk/issues/new).
|
|
269
277
|
|
|
270
278
|
## See Also
|
|
271
|
-
- [Connect To Python Sdk](https://docs.featbit.co/
|
|
279
|
+
- [Connect To Python Sdk](https://docs.featbit.co/sdk/overview#python)
|
|
@@ -1,39 +1,34 @@
|
|
|
1
1
|
fbclient/__init__.py,sha256=GMbobi6viAXPaNedEqyUOgIhoJsDqP2_W-PMUAFKC5A,2249
|
|
2
2
|
fbclient/category.py,sha256=DzblPnzVwsPKK_FSnLkK3HyWXStbNdPiRfdgSoEODVY,1058
|
|
3
|
-
fbclient/client.py,sha256=
|
|
4
|
-
fbclient/common_types.py,sha256=
|
|
3
|
+
fbclient/client.py,sha256=njobS5wNA_WtCkp3P-DTBEZbEtu9wHvUjHuHSFLAq9Y,18434
|
|
4
|
+
fbclient/common_types.py,sha256=5G4jJtG5Q1TL4NlBDSzVmNgRKh4OysYCfheigMDxgXU,11391
|
|
5
5
|
fbclient/config.py,sha256=BMWMAVcModtDVMrBmSFI3V4jZFEZX0jlKZ-ENqC0hDA,8913
|
|
6
6
|
fbclient/data_storage.py,sha256=gLYBAUTV-cR0rzoCxTCRYqAeGXhbIhQ7-_xh5OwLkqw,3342
|
|
7
7
|
fbclient/evaluator.py,sha256=OqPTmUXHl30NCb0RvD6fxBeSEpXHdZti-sWNPMIShlE,12387
|
|
8
8
|
fbclient/event_processor.py,sha256=tVnP_YLcIX4RakEqBv5VSCKBAHrMPZBJIPHDA04CtVI,9022
|
|
9
9
|
fbclient/event_types.py,sha256=0gorQ-RIjEw9OUYmV8MUoAgd4u1xlIVGayTeXkM-gAI,4597
|
|
10
|
-
fbclient/flag_change_notification.py,sha256=
|
|
10
|
+
fbclient/flag_change_notification.py,sha256=0JTd2w7nkgJtawKlnqmdB6JFQ_mcpLU2L3y_FNvdUQM,8664
|
|
11
11
|
fbclient/interfaces.py,sha256=eEB5y71uhL2Wlv47zNbG5kx43pZT8GcjBRPYA_tcod8,9861
|
|
12
12
|
fbclient/notice_broadcaster.py,sha256=fbR9QJzPu_tbmLpk-jBJB93eH2T95xVfR51OH_Wqqc0,2126
|
|
13
13
|
fbclient/status.py,sha256=f3Hif4aWCtn0bOvX_C6mtsDaynSRU5mvB3_Bp_r09qs,3794
|
|
14
14
|
fbclient/status_types.py,sha256=-xB4zf2qHPNE1GHOSkO1h3SJ_5vQZqrvOymBVvvh5ts,3160
|
|
15
15
|
fbclient/streaming.py,sha256=lyvmoE-yVohhp42OXm2rar4IDd5jdVGnv8AQjX5aV2A,12866
|
|
16
16
|
fbclient/update_processor.py,sha256=E2AChTLh38i_D2yR7Wz3p4nxO6TlaBoRmF3kj-0pCsw,629
|
|
17
|
-
fbclient/version.py,sha256=SQcsz5J97So94LUbpqgj8qnhlSEQGJV-x0R0enSYzoE,18
|
|
18
17
|
fbclient/utils/__init__.py,sha256=3HjFPtGBWwU_7GQarELbNV0VuuQMuPw9TCDsR93t7u0,4339
|
|
19
18
|
fbclient/utils/exponential_backoff_jitter_strategy.py,sha256=xZk7Y0yi3__U8c3DaX3PRb55vZAsRX__Rna3b2Wj9JA,1950
|
|
20
19
|
fbclient/utils/http_client.py,sha256=LCTZWg-ukoHGTRaf9gozhNqNZW-htKHS7DnSr1RZPV4,5502
|
|
21
20
|
fbclient/utils/repeatable_task.py,sha256=R8f9BgyoP0y2CHJYaVBEOYHYpH8XDcgmFmCVe3iyTlM,1320
|
|
22
|
-
fbclient/utils/rwlock.py,sha256=
|
|
21
|
+
fbclient/utils/rwlock.py,sha256=BfgKYNwZ8y63yk-CphlFTCZ1-0Txh4XQ8Pzh2pohh5A,1159
|
|
23
22
|
fbclient/utils/variation_splitting_algorithm.py,sha256=4_qBeVANWIFPacifmV1zl_JZXywOd-wv1fQmnb8qyAE,864
|
|
24
|
-
intergration_tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
25
|
-
intergration_tests/readme.py,sha256=8kipas95E7ZMbDPuQKqQqyjhIjwdtNAOsucgtFqN0D0,942
|
|
26
|
-
intergration_tests/run_in_start_no_wait.py,sha256=Cg3U4kzKU22kQUMXOiYcWeyrmkk6YaFudPdgJ49XQ7Q,1398
|
|
27
|
-
intergration_tests/run_in_start_wait.py,sha256=P0zt6O4u-zcE11bZP4tjXCZMpTPhU2sane_Xj5-DDV8,1898
|
|
28
23
|
tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
29
24
|
tests/test_data_storage.py,sha256=q5tgVI3smztXLMdNpFUF1ES-rFuanwamYAKF8K1cEWc,3785
|
|
30
25
|
tests/test_data_update_status_provider.py,sha256=O5xVZqG7atwUZA-AnH4XwLljV5yJzsBA0IcwOB1NOs8,4435
|
|
31
26
|
tests/test_evaluator.py,sha256=8SH9lfSzVXLCQ3NR_OKf2bwYGbZcnwkAhwMNNObprUI,4675
|
|
32
27
|
tests/test_event_processor.py,sha256=ceKHT5U7X_JfAwrnu_KJuwAsOTCsM8AdoXuNILMpwKI,4475
|
|
33
|
-
tests/test_fbclient.py,sha256=
|
|
34
|
-
tests/test_flag_change_notification.py,sha256=
|
|
35
|
-
fb_python_sdk-1.1.
|
|
36
|
-
fb_python_sdk-1.1.
|
|
37
|
-
fb_python_sdk-1.1.
|
|
38
|
-
fb_python_sdk-1.1.
|
|
39
|
-
fb_python_sdk-1.1.
|
|
28
|
+
tests/test_fbclient.py,sha256=_hmu7PWgHEURw95FXDQI8NkIIYHeiC81Z22UZoiuQhI,11535
|
|
29
|
+
tests/test_flag_change_notification.py,sha256=pDLCxq7_x63eJiWfPwf0_AgyvelLW_YPu-rhmto-TNs,3592
|
|
30
|
+
fb_python_sdk-1.1.6.dist-info/LICENSE,sha256=Pp1Gaxzlu2F3GAFJ314grnBHifZdIK7_ZvCFV_khanM,1064
|
|
31
|
+
fb_python_sdk-1.1.6.dist-info/METADATA,sha256=Z4we-3EBvhLH_cYh8qTmA6a0PctCjuC23XIwoX1lyrI,13385
|
|
32
|
+
fb_python_sdk-1.1.6.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
33
|
+
fb_python_sdk-1.1.6.dist-info/top_level.txt,sha256=im9taLLXhMbB6_5DAbFwqLVV0gk1rOgAkYmsVJu5pbY,15
|
|
34
|
+
fb_python_sdk-1.1.6.dist-info/RECORD,,
|
fbclient/client.py
CHANGED
|
@@ -343,7 +343,7 @@ class FBClient:
|
|
|
343
343
|
:param event_name: the name of the event, which may correspond to a goal in A/B tests
|
|
344
344
|
:param metric_value: a numeric value used by the experiment, default value is 1.0
|
|
345
345
|
"""
|
|
346
|
-
if not event_name
|
|
346
|
+
if not event_name:
|
|
347
347
|
log.warning('FB Python SDK: event/metric invalid')
|
|
348
348
|
return
|
|
349
349
|
try:
|
|
@@ -375,7 +375,7 @@ class FBClient:
|
|
|
375
375
|
|
|
376
376
|
metric_event = MetricEvent(fb_user)
|
|
377
377
|
for event_name, metric_value in metrics.items():
|
|
378
|
-
if event_name
|
|
378
|
+
if event_name:
|
|
379
379
|
metric_event.add(Metric(event_name, metric_value))
|
|
380
380
|
self._event_handler(metric_event)
|
|
381
381
|
|
fbclient/common_types.py
CHANGED
|
@@ -215,6 +215,24 @@ class AllFlagStates(BasicFlagState, Jsonfy):
|
|
|
215
215
|
self._data = dict((ed.key_name, (ed, fb_event)) for ed, fb_event in data.items()) if data else {}
|
|
216
216
|
self._event_handler = event_handler
|
|
217
217
|
|
|
218
|
+
def keys(self):
|
|
219
|
+
"""
|
|
220
|
+
return all feature flag keys
|
|
221
|
+
"""
|
|
222
|
+
return self._data.keys()
|
|
223
|
+
|
|
224
|
+
def get_variation(self, key_name: str, default: Any = None) -> Any:
|
|
225
|
+
"""Return the variation of a given feature flag key
|
|
226
|
+
|
|
227
|
+
This method will send event to back to feature flag center immediately
|
|
228
|
+
|
|
229
|
+
The default value should be a string, boolean, numeric, or json type.
|
|
230
|
+
|
|
231
|
+
:param key_name: key name of the flag
|
|
232
|
+
:return: the variation of the flag in any type of string, boolean, numeric, or json type
|
|
233
|
+
"""
|
|
234
|
+
return self.get(key_name, default).variation
|
|
235
|
+
|
|
218
236
|
def get(self, key_name: str, default: Any = None) -> EvalDetail:
|
|
219
237
|
"""Return the flag evaluation details of a given feature flag key
|
|
220
238
|
|
|
@@ -38,7 +38,7 @@ class FlagValueChangedListener(FlagChangedListener):
|
|
|
38
38
|
flag_key: str,
|
|
39
39
|
user: dict,
|
|
40
40
|
evaluate_fn: Callable[[str, dict, Any], Any],
|
|
41
|
-
flag_value_changed_fn: Callable[[str, Any], None]):
|
|
41
|
+
flag_value_changed_fn: Callable[[str, Any, Any], None]):
|
|
42
42
|
self.__flag_key = flag_key
|
|
43
43
|
self.__user = user
|
|
44
44
|
self.__evaluate_fn = evaluate_fn
|
|
@@ -51,20 +51,20 @@ class FlagValueChangedListener(FlagChangedListener):
|
|
|
51
51
|
prev_flag_value = self.__prvious_flag_value
|
|
52
52
|
curr_flag_value = self.__evaluate_fn(self.__flag_key, self.__user, None)
|
|
53
53
|
if prev_flag_value != curr_flag_value:
|
|
54
|
-
self.__fn(self.__flag_key, curr_flag_value)
|
|
54
|
+
self.__fn(self.__flag_key, prev_flag_value, curr_flag_value)
|
|
55
55
|
self.__prvious_flag_value = curr_flag_value
|
|
56
56
|
|
|
57
57
|
|
|
58
|
-
class
|
|
58
|
+
class FlagValueMaybeChangedListener(FlagChangedListener):
|
|
59
59
|
def __init__(self,
|
|
60
60
|
flag_key: str,
|
|
61
61
|
user: dict,
|
|
62
62
|
evaluate_fn: Callable[[str, dict, Any], Any],
|
|
63
|
-
|
|
63
|
+
flag_value_maybe_changed_fn: Callable[[str, Any], None]):
|
|
64
64
|
self.__flag_key = flag_key
|
|
65
65
|
self.__user = user
|
|
66
66
|
self.__evaluate_fn = evaluate_fn
|
|
67
|
-
self.__fn =
|
|
67
|
+
self.__fn = flag_value_maybe_changed_fn
|
|
68
68
|
|
|
69
69
|
def on_flag_change(self, notice: FlagChangedNotice):
|
|
70
70
|
if notice.flag_key == self.__flag_key:
|
|
@@ -95,7 +95,7 @@ class FlagTracker:
|
|
|
95
95
|
def add_flag_value_changed_listener(self,
|
|
96
96
|
flag_key: str,
|
|
97
97
|
user: dict,
|
|
98
|
-
flag_value_changed_fn: Callable[[str, Any], None]) -> FlagValueChangedListener:
|
|
98
|
+
flag_value_changed_fn: Callable[[str, Any, Any], None]) -> FlagValueChangedListener:
|
|
99
99
|
"""
|
|
100
100
|
Registers a listener to be notified of a change in a specific feature flag's value for a specific FeatBit user.
|
|
101
101
|
|
|
@@ -110,7 +110,8 @@ class FlagTracker:
|
|
|
110
110
|
:param user: The user to evaluate the flag value
|
|
111
111
|
:param flag_value_changed_fn: The function to be called only when this flag value changes
|
|
112
112
|
* the first argument is the flag key
|
|
113
|
-
* the second argument is the
|
|
113
|
+
* the second argument is the previous flag value
|
|
114
|
+
* the third argument is the current flag value
|
|
114
115
|
|
|
115
116
|
:return: A listener object that can be used to remove it later on.
|
|
116
117
|
"""
|
|
@@ -128,10 +129,10 @@ class FlagTracker:
|
|
|
128
129
|
self.add_flag_changed_listener(listener)
|
|
129
130
|
return listener
|
|
130
131
|
|
|
131
|
-
def
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
def add_flag_value_maybe_changed_listener(self,
|
|
133
|
+
flag_key: str,
|
|
134
|
+
user: dict,
|
|
135
|
+
flag_value_maybe_changed_fn: Callable[[str, Any], None]) -> FlagValueMaybeChangedListener:
|
|
135
136
|
"""
|
|
136
137
|
Registers a listener to be notified of a change in a specific feature flag's value for a specific FeatBit user.
|
|
137
138
|
|
|
@@ -145,7 +146,7 @@ class FlagTracker:
|
|
|
145
146
|
|
|
146
147
|
:param flag_key: The key of the feature flag to track
|
|
147
148
|
:param user: The user to evaluate the flag value
|
|
148
|
-
:param
|
|
149
|
+
:param flag_value_maybe_changed_fn: The function to be called if any changes to a specific flag
|
|
149
150
|
* the first argument is the flag key
|
|
150
151
|
* the second argument is the latest flag value, this value may be same as the previous value
|
|
151
152
|
|
|
@@ -159,10 +160,10 @@ class FlagTracker:
|
|
|
159
160
|
# check user
|
|
160
161
|
FBUser.from_dict(user)
|
|
161
162
|
# check flag_value_changed_fn
|
|
162
|
-
if not isinstance(
|
|
163
|
+
if not isinstance(flag_value_maybe_changed_fn, Callable) or not flag_value_maybe_changed_fn:
|
|
163
164
|
raise ValueError('flag_value_changed_fn must be a callable function')
|
|
164
165
|
|
|
165
|
-
listener =
|
|
166
|
+
listener = FlagValueMaybeChangedListener(flag_key, user, self.__evaluate_fn, flag_value_maybe_changed_fn)
|
|
166
167
|
self.add_flag_changed_listener(listener)
|
|
167
168
|
return listener
|
|
168
169
|
|
fbclient/utils/rwlock.py
CHANGED
|
@@ -25,7 +25,7 @@ class ReadWriteLock:
|
|
|
25
25
|
with self._read_ready:
|
|
26
26
|
self._readers = self._readers - 1 if self._readers > 0 else 0
|
|
27
27
|
if self._readers == 0:
|
|
28
|
-
self._read_ready.
|
|
28
|
+
self._read_ready.notify_all()
|
|
29
29
|
|
|
30
30
|
def write_lock(self):
|
|
31
31
|
""" Acquire a write lock. Blocks until there are no
|
tests/test_fbclient.py
CHANGED
|
@@ -206,15 +206,30 @@ def test_get_all_latest_flag_variations():
|
|
|
206
206
|
assert client.initialize
|
|
207
207
|
all_states = client.get_all_latest_flag_variations(USER_1)
|
|
208
208
|
ed = all_states.get("ff-test-bool", False)
|
|
209
|
+
value = all_states.get_variation("ff-test-bool", False)
|
|
209
210
|
assert ed is not None and ed.variation is True
|
|
211
|
+
assert value is True
|
|
212
|
+
assert "ff-test-bool" in all_states.keys()
|
|
210
213
|
ed = all_states.get("ff-test-number", -1)
|
|
214
|
+
value = all_states.get_variation("ff-test-number", -1)
|
|
211
215
|
assert ed is not None and ed.variation == 1
|
|
216
|
+
assert value == 1
|
|
217
|
+
assert "ff-test-number" in all_states.keys()
|
|
212
218
|
ed = all_states.get("ff-test-string", 'error')
|
|
219
|
+
value = all_states.get_variation("ff-test-string", 'error')
|
|
213
220
|
assert ed is not None and ed.variation == "others"
|
|
221
|
+
assert value == "others"
|
|
222
|
+
assert "ff-test-string" in all_states.keys()
|
|
214
223
|
ed = all_states.get("ff-test-seg", 'error')
|
|
224
|
+
value = all_states.get_variation("ff-test-seg", 'error')
|
|
215
225
|
assert ed is not None and ed.variation == "teamA"
|
|
226
|
+
assert value == "teamA"
|
|
227
|
+
assert "ff-test-seg" in all_states.keys()
|
|
216
228
|
ed = all_states.get("ff-test-json", {})
|
|
229
|
+
value = all_states.get_variation("ff-test-json", {})
|
|
217
230
|
assert ed is not None and ed.variation["code"] == 200
|
|
231
|
+
assert value["code"] == 200
|
|
232
|
+
assert "ff-test-json" in all_states.keys()
|
|
218
233
|
|
|
219
234
|
|
|
220
235
|
def test_variation_argument_error():
|
|
@@ -13,6 +13,9 @@ TEST_NOTICE_TYPE = 'test_notice_type'
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
class TestNotice(Notice):
|
|
16
|
+
# https://stackoverflow.com/questions/62460557/cannot-collect-test-class-testmain-because-it-has-a-init-constructor-from
|
|
17
|
+
__test__ = False
|
|
18
|
+
|
|
16
19
|
def __init__(self, notice_type: str, content: str):
|
|
17
20
|
self.__notice_type = notice_type
|
|
18
21
|
self.__content = content
|
|
@@ -27,6 +30,8 @@ class TestNotice(Notice):
|
|
|
27
30
|
|
|
28
31
|
|
|
29
32
|
class FakeFlagChangedListener(FlagChangedListener):
|
|
33
|
+
__test__ = False
|
|
34
|
+
|
|
30
35
|
def __init__(self, queue: Queue):
|
|
31
36
|
self.__queue = queue
|
|
32
37
|
|
fbclient/version.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
VERSION = "1.1.4"
|
intergration_tests/__init__.py
DELETED
|
File without changes
|
intergration_tests/readme.py
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
from fbclient import get, set_config
|
|
3
|
-
from fbclient.config import Config
|
|
4
|
-
|
|
5
|
-
logging.basicConfig(level=logging.DEBUG,
|
|
6
|
-
format='%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s',
|
|
7
|
-
datefmt='%m-%d %H:%M')
|
|
8
|
-
|
|
9
|
-
env_secret = 'fXWjg00OTEa-M_iBCyYiBwFPfdBisjAkiY3ycIMOWw1Q'
|
|
10
|
-
event_url = 'http://localhost:5100'
|
|
11
|
-
streaming_url = 'ws://localhost:5100'
|
|
12
|
-
|
|
13
|
-
set_config(Config(env_secret, event_url, streaming_url))
|
|
14
|
-
client = get()
|
|
15
|
-
|
|
16
|
-
if client.initialize:
|
|
17
|
-
flag_key = 'ff-test-bool'
|
|
18
|
-
user_key = 'user-test-1'
|
|
19
|
-
user_name = 'user-test-1'
|
|
20
|
-
user = {'key': user_key, 'name': user_name}
|
|
21
|
-
detail = client.variation_detail(flag_key, user, default=None)
|
|
22
|
-
print(f'flag {flag_key} returns {detail.variation} for user {user_key}, reason: {detail.reason}')
|
|
23
|
-
|
|
24
|
-
# ensure that the SDK shuts down cleanly and has a chance to deliver events to FeatBit before the program exits
|
|
25
|
-
client.stop()
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
from time import time
|
|
3
|
-
|
|
4
|
-
from fbclient.client import FBClient
|
|
5
|
-
from fbclient.common_types import FBUser
|
|
6
|
-
from fbclient.config import Config
|
|
7
|
-
from fbclient.utils import log
|
|
8
|
-
|
|
9
|
-
logging.basicConfig(level=logging.DEBUG,
|
|
10
|
-
format='%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s',
|
|
11
|
-
datefmt='%m-%d %H:%M')
|
|
12
|
-
|
|
13
|
-
env_secret = 'fXWjg00OTEa-M_iBCyYiBwFPfdBisjAkiY3ycIMOWw1Q'
|
|
14
|
-
|
|
15
|
-
config = Config(env_secret, event_url='http://localhost:5100', streaming_url='ws://localhost:5100')
|
|
16
|
-
client = FBClient(config, start_wait=0)
|
|
17
|
-
|
|
18
|
-
if client.update_status_provider.wait_for_OKState(timeout=15.):
|
|
19
|
-
while True:
|
|
20
|
-
line = input('input user key and flag key seperated by / \n')
|
|
21
|
-
if 'exit' == line.strip():
|
|
22
|
-
break
|
|
23
|
-
try:
|
|
24
|
-
user_key, flag_key, *_ = tuple(line.split('/'))
|
|
25
|
-
user = {'key': user_key, 'name': user_key, 'country': 'cn'}
|
|
26
|
-
fb_user = FBUser.from_dict(user)
|
|
27
|
-
log.info('FB Python SDK Test: user= %s' % fb_user.to_json_str())
|
|
28
|
-
t1 = time()
|
|
29
|
-
log.info('FB Python SDK Test: variation= %s' % client.variation_detail(flag_key, user).to_json_str())
|
|
30
|
-
t2 = time()
|
|
31
|
-
log.info('FB Python SDK Test: execution time= %f' % (t2 - t1))
|
|
32
|
-
except:
|
|
33
|
-
log.exception('FB Python SDK Test: unexpected error')
|
|
34
|
-
break
|
|
35
|
-
|
|
36
|
-
client.stop()
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
from time import time
|
|
3
|
-
|
|
4
|
-
from fbclient import get, set_config
|
|
5
|
-
from fbclient.common_types import FBUser
|
|
6
|
-
from fbclient.config import Config
|
|
7
|
-
from fbclient.utils import log
|
|
8
|
-
|
|
9
|
-
logging.basicConfig(level=logging.DEBUG,
|
|
10
|
-
format='%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s',
|
|
11
|
-
datefmt='%m-%d %H:%M')
|
|
12
|
-
|
|
13
|
-
env_secret = '9T0GABTXokagxhUZ81hUnws9_E2uOpIEyTjScBRr6JKA'
|
|
14
|
-
|
|
15
|
-
config = Config(env_secret, event_url='http://localhost:5100', streaming_url='ws://localhost:5100')
|
|
16
|
-
|
|
17
|
-
set_config(config)
|
|
18
|
-
|
|
19
|
-
client = get()
|
|
20
|
-
|
|
21
|
-
previous_flag_changed_keys = []
|
|
22
|
-
|
|
23
|
-
if client.initialize:
|
|
24
|
-
# client.identify({'key': 'test-python-sdk-user', 'name': 'test-python-sdk-user'})
|
|
25
|
-
def fn(flag_key, new_flag_value):
|
|
26
|
-
return log.info("%s value is %s" % (flag_key, new_flag_value))
|
|
27
|
-
while True:
|
|
28
|
-
line = input('input user key and flag key seperated by / \n')
|
|
29
|
-
if 'exit' == line.strip():
|
|
30
|
-
break
|
|
31
|
-
try:
|
|
32
|
-
user_key, flag_key, *_ = tuple(line.split('/'))
|
|
33
|
-
user = {'key': user_key, 'name': user_key, 'country': 'cn'}
|
|
34
|
-
flag_changed_key = f'{user_key}_{flag_key}'
|
|
35
|
-
if flag_changed_key not in previous_flag_changed_keys:
|
|
36
|
-
client \
|
|
37
|
-
.flag_tracker \
|
|
38
|
-
.add_flag_value_changed_listener(flag_key, user, fn)
|
|
39
|
-
previous_flag_changed_keys.append(flag_key)
|
|
40
|
-
fb_user = FBUser.from_dict(user)
|
|
41
|
-
log.info('FB Python SDK Test: user= %s' % fb_user.to_json_str())
|
|
42
|
-
t1 = time()
|
|
43
|
-
log.info('FB Python SDK Test: variation= %s' % client.variation_detail(flag_key, user).to_json_str())
|
|
44
|
-
t2 = time()
|
|
45
|
-
log.info('FB Python SDK Test: execution time= %f' % (t2 - t1))
|
|
46
|
-
except:
|
|
47
|
-
log.exception('FB Python SDK Test: unexpected error')
|
|
48
|
-
break
|
|
49
|
-
|
|
50
|
-
client.stop()
|
|
File without changes
|