Skip to content

Commit 8b2ed8b

Browse files
authored
Fix integrity issues (#41)
* Fix integrity issues * fix black, tests * add test for new behavior * run black properly * remove accidental commit
1 parent a139795 commit 8b2ed8b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

posthog/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ def shutdown(self):
286286

287287
def _load_feature_flags(self):
288288
try:
289-
self.feature_flags = get(self.personal_api_key, "/api/feature_flag/", self.host)["results"]
289+
flags = get(self.personal_api_key, f"/api/feature_flag/?token={self.api_key}", self.host)["results"]
290+
self.feature_flags = [flag for flag in flags if flag["active"]]
290291
except APIError as e:
291292
if e.status == 401:
292293
raise APIError(

posthog/test/test_client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,16 @@ def test_default_timeout_15(self):
319319
@mock.patch("posthog.client.Poller")
320320
@mock.patch("posthog.client.get")
321321
def test_load_feature_flags(self, patch_get, patch_poll):
322-
patch_get.return_value = {"results": [{"id": 1, "name": "Beta Feature", "key": "beta-feature"}]}
322+
patch_get.return_value = {
323+
"results": [
324+
{"id": 1, "name": "Beta Feature", "key": "beta-feature", "active": True},
325+
{"id": 2, "name": "Alpha Feature", "key": "alpha-feature", "active": False},
326+
]
327+
}
323328
client = Client(TEST_API_KEY, personal_api_key="test")
324329
with freeze_time("2020-01-01T12:01:00.0000Z"):
325330
client.load_feature_flags()
331+
self.assertEqual(len(client.feature_flags), 1)
326332
self.assertEqual(client.feature_flags[0]["key"], "beta-feature")
327333
self.assertEqual(client._last_feature_flag_poll.isoformat(), "2020-01-01T12:01:00+00:00")
328334
self.assertEqual(patch_poll.call_count, 1)

0 commit comments

Comments
 (0)