1010from .local_feature_flags import LocalFeatureFlagsProvider
1111
1212TEST_FLAG_KEY = "test_flag"
13- DISTINCT_ID = "user123"
1413
1514def create_test_flag (
1615 flag_key : str = TEST_FLAG_KEY ,
@@ -107,7 +106,7 @@ async def setup_flags_with_polling(self, flags_in_order: List[List[Experimentati
107106 @respx .mock
108107 async def test_get_variant_value_returns_fallback_when_no_flag_definitions (self ):
109108 await self .setup_flags ([])
110- result = self ._flags .get_variant_value ("nonexistent_flag" , "control" , {"distinct_id" : DISTINCT_ID })
109+ result = self ._flags .get_variant_value ("nonexistent_flag" , "control" , {"distinct_id" : "user123" })
111110 assert result == "control"
112111
113112 @respx .mock
@@ -117,14 +116,14 @@ async def test_get_variant_value_returns_fallback_if_flag_definition_call_fails(
117116 )
118117
119118 await self ._flags .astart_polling_for_definitions ()
120- result = self ._flags .get_variant_value ("nonexistent_flag" , "control" , {"distinct_id" : DISTINCT_ID })
119+ result = self ._flags .get_variant_value ("nonexistent_flag" , "control" , {"distinct_id" : "user123" })
121120 assert result == "control"
122121
123122 @respx .mock
124123 async def test_get_variant_value_returns_fallback_when_flag_does_not_exist (self ):
125124 other_flag = create_test_flag ("other_flag" )
126125 await self .setup_flags ([other_flag ])
127- result = self ._flags .get_variant_value ("nonexistent_flag" , "control" , {"distinct_id" : DISTINCT_ID })
126+ result = self ._flags .get_variant_value ("nonexistent_flag" , "control" , {"distinct_id" : "user123" })
128127 assert result == "control"
129128
130129 @respx .mock
@@ -138,7 +137,7 @@ async def test_get_variant_value_returns_fallback_when_no_context(self):
138137 async def test_get_variant_value_returns_fallback_when_wrong_context_key (self ):
139138 flag = create_test_flag (context = "user_id" )
140139 await self .setup_flags ([flag ])
141- result = self ._flags .get_variant_value (TEST_FLAG_KEY , "fallback" , {"distinct_id" : DISTINCT_ID })
140+ result = self ._flags .get_variant_value (TEST_FLAG_KEY , "fallback" , {"distinct_id" : "user123" })
142141 assert result == "fallback"
143142
144143 @respx .mock
@@ -176,14 +175,14 @@ async def test_get_variant_value_returns_fallback_when_test_user_variant_not_con
176175 async def test_get_variant_value_returns_fallback_when_rollout_percentage_zero (self ):
177176 flag = create_test_flag (rollout_percentage = 0.0 )
178177 await self .setup_flags ([flag ])
179- result = self ._flags .get_variant_value (TEST_FLAG_KEY , "fallback" , {"distinct_id" : DISTINCT_ID })
178+ result = self ._flags .get_variant_value (TEST_FLAG_KEY , "fallback" , {"distinct_id" : "user123" })
180179 assert result == "fallback"
181180
182181 @respx .mock
183182 async def test_get_variant_value_returns_variant_when_rollout_percentage_hundred (self ):
184183 flag = create_test_flag (rollout_percentage = 100.0 )
185184 await self .setup_flags ([flag ])
186- result = self ._flags .get_variant_value (TEST_FLAG_KEY , "fallback" , {"distinct_id" : DISTINCT_ID })
185+ result = self ._flags .get_variant_value (TEST_FLAG_KEY , "fallback" , {"distinct_id" : "user123" })
187186 assert result != "fallback"
188187
189188 # TODO Joshua start here
@@ -196,7 +195,7 @@ async def test_get_variant_value_respects_runtime_evaluation_rule_satisfied(self
196195 flag = create_test_flag (runtime_evaluation_rule = runtime_eval )
197196 await self .setup_flags ([flag ])
198197 context = {
199- "distinct_id" : DISTINCT_ID ,
198+ "distinct_id" : "user123" ,
200199 "custom_properties" : {
201200 "plan" : "premium" ,
202201 "region" : "US"
@@ -213,7 +212,7 @@ async def test_get_variant_value_respects_runtime_evaluation_rule_not_satisfied(
213212 flag = create_test_flag (runtime_evaluation_rule = runtime_eval )
214213 await self .setup_flags ([flag ])
215214 context = {
216- "distinct_id" : DISTINCT_ID ,
215+ "distinct_id" : "user123" ,
217216 "custom_properties" : {
218217 "plan" : "premium" ,
219218 "region" : "US"
@@ -228,7 +227,7 @@ async def test_get_variant_value_respects_runtime_evaluation_satisfied(self):
228227 flag = create_test_flag (runtime_evaluation_legacy_definition = runtime_eval )
229228 await self .setup_flags ([flag ])
230229 context = {
231- "distinct_id" : DISTINCT_ID ,
230+ "distinct_id" : "user123" ,
232231 "custom_properties" : {
233232 "plan" : "premium" ,
234233 "region" : "US"
@@ -243,7 +242,7 @@ async def test_get_variant_value_returns_fallback_when_runtime_evaluation_not_sa
243242 flag = create_test_flag (runtime_evaluation_legacy_definition = runtime_eval )
244243 await self .setup_flags ([flag ])
245244 context = {
246- "distinct_id" : DISTINCT_ID ,
245+ "distinct_id" : "user123" ,
247246 "custom_properties" : {
248247 "plan" : "basic" ,
249248 "region" : "US"
@@ -261,7 +260,7 @@ async def test_get_variant_value_picks_correct_variant_with_hundred_percent_spli
261260 ]
262261 flag = create_test_flag (variants = variants , rollout_percentage = 100.0 )
263262 await self .setup_flags ([flag ])
264- result = self ._flags .get_variant_value (TEST_FLAG_KEY , "fallback" , {"distinct_id" : DISTINCT_ID })
263+ result = self ._flags .get_variant_value (TEST_FLAG_KEY , "fallback" , {"distinct_id" : "user123" })
265264 assert result == "variant_a"
266265
267266 @respx .mock
@@ -274,7 +273,7 @@ async def test_get_variant_value_picks_correct_variant_with_half_migrated_group_
274273 variant_splits = {"A" : 0.0 , "B" : 100.0 , "C" : 0.0 }
275274 flag = create_test_flag (variants = variants , rollout_percentage = 100.0 , variant_splits = variant_splits )
276275 await self .setup_flags ([flag ])
277- result = self ._flags .get_variant_value (TEST_FLAG_KEY , "fallback" , {"distinct_id" : DISTINCT_ID })
276+ result = self ._flags .get_variant_value (TEST_FLAG_KEY , "fallback" , {"distinct_id" : "user123" })
278277 assert result == "variant_b"
279278
280279 @respx .mock
@@ -287,7 +286,7 @@ async def test_get_variant_value_picks_correct_variant_with_full_migrated_group_
287286 variant_splits = {"A" : 0.0 , "B" : 0.0 , "C" : 100.0 }
288287 flag = create_test_flag (variants = variants , rollout_percentage = 100.0 , variant_splits = variant_splits )
289288 await self .setup_flags ([flag ])
290- result = self ._flags .get_variant_value (TEST_FLAG_KEY , "fallback" , {"distinct_id" : DISTINCT_ID })
289+ result = self ._flags .get_variant_value (TEST_FLAG_KEY , "fallback" , {"distinct_id" : "user123" })
291290 assert result == "variant_c"
292291
293292 @respx .mock
@@ -298,7 +297,7 @@ async def test_get_variant_value_picks_overriden_variant(self):
298297 ]
299298 flag = create_test_flag (variants = variants , variant_override = VariantOverride (key = "B" ))
300299 await self .setup_flags ([flag ])
301- result = self ._flags .get_variant_value (TEST_FLAG_KEY , "control" , {"distinct_id" : DISTINCT_ID })
300+ result = self ._flags .get_variant_value (TEST_FLAG_KEY , "control" , {"distinct_id" : "user123" })
302301 assert result == "variant_b"
303302
304303 @respx .mock
@@ -307,7 +306,7 @@ async def test_get_variant_value_tracks_exposure_when_variant_selected(self):
307306 await self .setup_flags ([flag ])
308307 with patch ('mixpanel.flags.utils.normalized_hash' ) as mock_hash :
309308 mock_hash .return_value = 0.5
310- _ = self ._flags .get_variant_value (TEST_FLAG_KEY , "fallback" , {"distinct_id" : DISTINCT_ID })
309+ _ = self ._flags .get_variant_value (TEST_FLAG_KEY , "fallback" , {"distinct_id" : "user123" })
311310 self ._mock_tracker .assert_called_once ()
312311
313312 @respx .mock
@@ -350,7 +349,7 @@ async def test_get_variant_value_tracks_exposure_with_correct_properties(self, e
350349 @respx .mock
351350 async def test_get_variant_value_does_not_track_exposure_on_fallback (self ):
352351 await self .setup_flags ([])
353- _ = self ._flags .get_variant_value ("nonexistent_flag" , "fallback" , {"distinct_id" : DISTINCT_ID })
352+ _ = self ._flags .get_variant_value ("nonexistent_flag" , "fallback" , {"distinct_id" : "user123" })
354353 self ._mock_tracker .assert_not_called ()
355354
356355 @respx .mock
@@ -366,7 +365,7 @@ async def test_get_all_variants_returns_all_variants_when_user_in_rollout(self):
366365 flag2 = create_test_flag (flag_key = "flag2" , rollout_percentage = 100.0 )
367366 await self .setup_flags ([flag1 , flag2 ])
368367
369- result = self ._flags .get_all_variants ({"distinct_id" : DISTINCT_ID })
368+ result = self ._flags .get_all_variants ({"distinct_id" : "user123" })
370369
371370 assert len (result ) == 2 and "flag1" in result and "flag2" in result
372371
@@ -376,15 +375,15 @@ async def test_get_all_variants_returns_partial_variants_when_user_in_some_rollo
376375 flag2 = create_test_flag (flag_key = "flag2" , rollout_percentage = 0.0 )
377376 await self .setup_flags ([flag1 , flag2 ])
378377
379- result = self ._flags .get_all_variants ({"distinct_id" : DISTINCT_ID })
378+ result = self ._flags .get_all_variants ({"distinct_id" : "user123" })
380379
381380 assert len (result ) == 1 and "flag1" in result and "flag2" not in result
382381
383382 @respx .mock
384383 async def test_get_all_variants_returns_empty_dict_when_no_flags_configured (self ):
385384 await self .setup_flags ([])
386385
387- result = self ._flags .get_all_variants ({"distinct_id" : DISTINCT_ID })
386+ result = self ._flags .get_all_variants ({"distinct_id" : "user123" })
388387
389388 assert result == {}
390389
@@ -394,7 +393,7 @@ async def test_get_all_variants_does_not_track_exposure_events(self):
394393 flag2 = create_test_flag (flag_key = "flag2" , rollout_percentage = 100.0 )
395394 await self .setup_flags ([flag1 , flag2 ])
396395
397- _ = self ._flags .get_all_variants ({"distinct_id" : DISTINCT_ID })
396+ _ = self ._flags .get_all_variants ({"distinct_id" : "user123" })
398397
399398 self ._mock_tracker .assert_not_called ()
400399
@@ -404,7 +403,7 @@ async def test_track_exposure_event_successfully_tracks(self):
404403 await self .setup_flags ([flag ])
405404
406405 variant = SelectedVariant (key = "treatment" , variant_value = "treatment" )
407- self ._flags .track_exposure_event (TEST_FLAG_KEY , variant , {"distinct_id" : DISTINCT_ID })
406+ self ._flags .track_exposure_event (TEST_FLAG_KEY , variant , {"distinct_id" : "user123" })
408407
409408 self ._mock_tracker .assert_called_once ()
410409
@@ -424,7 +423,7 @@ async def test_are_flags_ready_returns_true_when_empty_flags_loaded(self):
424423 @respx .mock
425424 async def test_is_enabled_returns_false_for_nonexistent_flag (self ):
426425 await self .setup_flags ([])
427- result = self ._flags .is_enabled ("nonexistent_flag" , {"distinct_id" : DISTINCT_ID })
426+ result = self ._flags .is_enabled ("nonexistent_flag" , {"distinct_id" : "user123" })
428427 assert result == False
429428
430429 @respx .mock
@@ -434,7 +433,7 @@ async def test_is_enabled_returns_true_for_true_variant_value(self):
434433 ]
435434 flag = create_test_flag (variants = variants , rollout_percentage = 100.0 )
436435 await self .setup_flags ([flag ])
437- result = self ._flags .is_enabled (TEST_FLAG_KEY , {"distinct_id" : DISTINCT_ID })
436+ result = self ._flags .is_enabled (TEST_FLAG_KEY , {"distinct_id" : "user123" })
438437 assert result == True
439438
440439 @respx .mock
@@ -459,7 +458,7 @@ async def track_fetch_calls(self):
459458 async with polling_limit_check :
460459 await polling_limit_check .wait_for (lambda : polling_iterations >= len (flags_in_order ))
461460
462- result2 = self ._flags_with_polling .get_variant_value (TEST_FLAG_KEY , "fallback" , {"distinct_id" : DISTINCT_ID })
461+ result2 = self ._flags_with_polling .get_variant_value (TEST_FLAG_KEY , "fallback" , {"distinct_id" : "user123" })
463462 assert result2 != "fallback"
464463
465464class TestLocalFeatureFlagsProviderSync :
@@ -505,5 +504,5 @@ def track_fetch_calls(self):
505504 self .setup_flags_with_polling (flags_in_order )
506505 polling_event .wait (timeout = 5.0 )
507506 assert (polling_iterations >= 3 )
508- result2 = self ._flags_with_polling .get_variant_value (TEST_FLAG_KEY , "fallback" , {"distinct_id" : DISTINCT_ID })
507+ result2 = self ._flags_with_polling .get_variant_value (TEST_FLAG_KEY , "fallback" , {"distinct_id" : "user123" })
509508 assert result2 != "fallback"
0 commit comments