@@ -404,13 +404,25 @@ def test_load_feature_flags_wrong_key(self):
404404 with freeze_time ("2020-01-01T12:01:00.0000Z" ):
405405 self .assertRaises (APIError , client .load_feature_flags )
406406
407+ @mock .patch ("posthog.client.decide" )
407408 @mock .patch ("posthog.client.get" )
408- def test_feature_enabled_simple (self , patch_get ):
409+ def test_feature_enabled_simple (self , patch_get , patch_decide ):
409410 client = Client (TEST_API_KEY )
410411 client .feature_flags = [
411412 {"id" : 1 , "name" : "Beta Feature" , "key" : "beta-feature" , "is_simple_flag" : True , "rollout_percentage" : 100 }
412413 ]
413414 self .assertTrue (client .feature_enabled ("beta-feature" , "distinct_id" ))
415+ self .assertEqual (patch_decide .call_count , 0 )
416+
417+ @mock .patch ("posthog.client.decide" )
418+ @mock .patch ("posthog.client.get" )
419+ def test_feature_enabled_simple_is_false (self , patch_get , patch_decide ):
420+ client = Client (TEST_API_KEY )
421+ client .feature_flags = [
422+ {"id" : 1 , "name" : "Beta Feature" , "key" : "beta-feature" , "is_simple_flag" : True , "rollout_percentage" : 0 }
423+ ]
424+ self .assertFalse (client .feature_enabled ("beta-feature" , "distinct_id" ))
425+ self .assertEqual (patch_decide .call_count , 0 )
414426
415427 @mock .patch ("posthog.client.get" )
416428 def test_feature_enabled_simple_with_project_api_key (self , patch_get ):
@@ -444,22 +456,24 @@ def test_feature_enabled_simple_with_none_rollout_percentage(self, patch_get):
444456 self .assertTrue (client .feature_enabled ("beta-feature" , "distinct_id" ))
445457
446458 @mock .patch ("posthog.client.Poller" )
447- @mock .patch ("posthog.client.get" )
448- def test_feature_enabled_doesnt_exist (self , patch_get , patch_poll ):
459+ @mock .patch ("posthog.client.decide" )
460+ def test_feature_enabled_doesnt_exist (self , patch_decide , patch_poll ):
461+ patch_decide .return_value = {"featureFlags" : []}
449462 client = Client (TEST_API_KEY , personal_api_key = "test" )
450463 client .feature_flags = []
451464
452465 self .assertFalse (client .feature_enabled ("doesnt-exist" , "distinct_id" ))
453466 self .assertTrue (client .feature_enabled ("doesnt-exist" , "distinct_id" , True ))
454467
455468 @mock .patch ("posthog.client.Poller" )
456- @mock .patch ("posthog.client.get " )
457- def test_personal_api_key_doesnt_exist (self , patch_get , patch_poll ):
469+ @mock .patch ("posthog.client.decide " )
470+ def test_personal_api_key_doesnt_exist (self , patch_decide , patch_poll ):
458471 client = Client (TEST_API_KEY )
459472 client .feature_flags = []
460473
461- self .assertFalse (client .feature_enabled ("doesnt-exist" , "distinct_id" ))
462- self .assertTrue (client .feature_enabled ("doesnt-exist" , "distinct_id" , True ))
474+ patch_decide .return_value = {"featureFlags" : ["feature-flag" ]}
475+
476+ self .assertTrue (client .feature_enabled ("feature-flag" , "distinct_id" ))
463477
464478 @mock .patch ("posthog.client.Poller" )
465479 @mock .patch ("posthog.client.get" )
0 commit comments