@@ -210,24 +210,83 @@ def test_basic_capture_with_locally_evaluated_feature_flags(self, patch_decide):
210210 assert "$active_feature_flags" not in msg ["properties" ]
211211
212212 @mock .patch ("posthog.client.decide" )
213- def test_get_active_feature_flags (self , patch_decide ):
214- patch_decide .return_value = {
215- "featureFlags" : {"beta-feature" : "random-variant" , "alpha-feature" : True , "off-feature" : False }
213+ def test_dont_override_capture_with_local_flags (self , patch_decide ):
214+ patch_decide .return_value = {"featureFlags" : {"beta-feature" : "random-variant" }}
215+ client = Client (FAKE_TEST_API_KEY , on_error = self .set_fail , personal_api_key = FAKE_TEST_API_KEY )
216+
217+ multivariate_flag = {
218+ "id" : 1 ,
219+ "name" : "Beta Feature" ,
220+ "key" : "beta-feature-local" ,
221+ "is_simple_flag" : False ,
222+ "active" : True ,
223+ "rollout_percentage" : 100 ,
224+ "filters" : {
225+ "groups" : [
226+ {
227+ "properties" : [
228+ {
"key" :
"email" ,
"type" :
"person" ,
"value" :
"[email protected] " ,
"operator" :
"exact" }
229+ ],
230+ "rollout_percentage" : 100 ,
231+ },
232+ {
233+ "rollout_percentage" : 50 ,
234+ },
235+ ],
236+ "multivariate" : {
237+ "variants" : [
238+ {"key" : "first-variant" , "name" : "First Variant" , "rollout_percentage" : 50 },
239+ {"key" : "second-variant" , "name" : "Second Variant" , "rollout_percentage" : 25 },
240+ {"key" : "third-variant" , "name" : "Third Variant" , "rollout_percentage" : 25 },
241+ ]
242+ },
243+ "payloads" : {"first-variant" : "some-payload" , "third-variant" : {"a" : "json" }},
244+ },
216245 }
246+ basic_flag = {
247+ "id" : 1 ,
248+ "name" : "Beta Feature" ,
249+ "key" : "person-flag" ,
250+ "is_simple_flag" : True ,
251+ "active" : True ,
252+ "filters" : {
253+ "groups" : [
254+ {
255+ "properties" : [
256+ {
257+ "key" : "region" ,
258+ "operator" : "exact" ,
259+ "value" : ["USA" ],
260+ "type" : "person" ,
261+ }
262+ ],
263+ "rollout_percentage" : 100 ,
264+ }
265+ ],
266+ "payloads" : {"true" : 300 },
267+ },
268+ }
269+ client .feature_flags = [multivariate_flag , basic_flag ]
217270
218- client = Client (FAKE_TEST_API_KEY , on_error = self .set_fail , personal_api_key = FAKE_TEST_API_KEY )
219- variants = client ._get_active_feature_variants ("some_id" , None , None , None , False )
220- self .assertEqual (variants , {"beta-feature" : "random-variant" , "alpha-feature" : True })
221- patch_decide .assert_called_with (
222- "random_key" ,
223- None ,
224- timeout = 10 ,
225- distinct_id = "some_id" ,
226- groups = {},
227- person_properties = None ,
228- group_properties = None ,
229- disable_geoip = False ,
271+ success , msg = client .capture (
272+ "distinct_id" , "python test event" , {"$feature/beta-feature-local" : "my-custom-variant" }
230273 )
274+ client .flush ()
275+ self .assertTrue (success )
276+ self .assertFalse (self .failed )
277+
278+ self .assertEqual (msg ["event" ], "python test event" )
279+ self .assertTrue (isinstance (msg ["timestamp" ], str ))
280+ self .assertIsNone (msg .get ("uuid" ))
281+ self .assertEqual (msg ["distinct_id" ], "distinct_id" )
282+ self .assertEqual (msg ["properties" ]["$lib" ], "posthog-python" )
283+ self .assertEqual (msg ["properties" ]["$lib_version" ], VERSION )
284+ self .assertEqual (msg ["properties" ]["$feature/beta-feature-local" ], "my-custom-variant" )
285+ self .assertEqual (msg ["properties" ]["$active_feature_flags" ], ["beta-feature-local" ])
286+ assert "$feature/beta-feature" not in msg ["properties" ]
287+ assert "$feature/person-flag" not in msg ["properties" ]
288+
289+ self .assertEqual (patch_decide .call_count , 0 )
231290
232291 @mock .patch ("posthog.client.decide" )
233292 def test_basic_capture_with_feature_flags_returns_active_only (self , patch_decide ):
0 commit comments