def test_personal_api_key_doesnt_exist(self, patch_get, patch_poll): client = Client(TEST_API_KEY) client.feature_flags = [] self.assertFalse(client.feature_enabled("doesnt-exist", "distinct_id")) self.assertTrue( client.feature_enabled("doesnt-exist", "distinct_id", True))
def test_feature_enabled_request(self, patch_get): patch_get.return_value = {"featureFlags": ["beta-feature"]} client = Client(TEST_API_KEY) client.feature_flags = [ {"id": 1, "name": "Beta Feature", "key": "beta-feature", "is_simple_flag": False, "rollout_percentage": 100} ] self.assertTrue(client.feature_enabled("beta-feature", "distinct_id"))
def test_feature_enabled_doesnt_exist(self, patch_get, patch_poll): client = Client(TEST_API_KEY, personal_api_key='test') client.feature_flags = [] self.assertFalse(client.feature_enabled('doesnt-exist', 'distinct_id')) self.assertTrue( client.feature_enabled('doesnt-exist', 'distinct_id', True))
def test_call_identify_fails(self, patch_get, patch_poll): def raise_effect(): raise Exception("http exception") patch_get.return_value.raiseError.side_effect = raise_effect client = Client(TEST_API_KEY, personal_api_key="test") client.feature_flags = [{"key": "example", "is_simple_flag": False}] self.assertFalse(client.feature_enabled("example", "distinct_id"))
def test_load_feature_flags_error(self, patch_get, patch_poll): def raise_effect(): raise Exception("http exception") patch_get.return_value.raiseError.side_effect = raise_effect client = Client(TEST_API_KEY, personal_api_key="test") client.feature_flags = [] self.assertFalse(client.feature_enabled("doesnt-exist", "distinct_id"))
def test_call_identify_fails(self, patch_get, patch_poll): def raise_effect(): raise Exception('http exception') patch_get.return_value.raiseError.side_effect = raise_effect client = Client(TEST_API_KEY, personal_api_key='test') client.feature_flags = [{'key': 'example', 'is_simple_flag': False}] self.assertFalse(client.feature_enabled('example', 'distinct_id'))
def test_feature_enabled_simple_without_rollout_percentage( self, patch_get): client = Client(TEST_API_KEY) client.feature_flags = [{ "id": 1, "name": "Beta Feature", "key": "beta-feature", "is_simple_flag": True }] self.assertTrue(client.feature_enabled("beta-feature", "distinct_id"))
def test_feature_enabled_simple_with_project_api_key(self, patch_get): client = Client(project_api_key=TEST_API_KEY, on_error=self.set_fail) client.feature_flags = [{ "id": 1, "name": "Beta Feature", "key": "beta-feature", "is_simple_flag": True, "rollout_percentage": 100 }] self.assertTrue(client.feature_enabled("beta-feature", "distinct_id"))
def test_feature_enabled_simple(self, patch_get): client = Client(TEST_API_KEY) client.feature_flags = [{ 'id': 1, 'name': 'Beta Feature', 'key': 'beta-feature', 'is_simple_flag': True, 'rollout_percentage': 100 }] self.assertTrue(client.feature_enabled('beta-feature', 'distinct_id'))
def test_feature_enabled_request(self, patch_get): patch_get.return_value = {'featureFlags': ['beta-feature']} client = Client(TEST_API_KEY) client.feature_flags = [{ 'id': 1, 'name': 'Beta Feature', 'key': 'beta-feature', 'is_simple_flag': False, 'rollout_percentage': 100 }] self.assertTrue(client.feature_enabled('beta-feature', 'distinct_id'))