posthoganalytics 6.5.0__py3-none-any.whl → 6.6.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1742,6 +1742,7 @@ class TestClient(unittest.TestCase):
1742
1742
  person_properties={"distinct_id": "some_id"},
1743
1743
  group_properties={},
1744
1744
  geoip_disable=True,
1745
+ flag_keys_to_evaluate=["random_key"],
1745
1746
  )
1746
1747
  patch_flags.reset_mock()
1747
1748
  client.feature_enabled(
@@ -1756,6 +1757,7 @@ class TestClient(unittest.TestCase):
1756
1757
  person_properties={"distinct_id": "feature_enabled_distinct_id"},
1757
1758
  group_properties={},
1758
1759
  geoip_disable=True,
1760
+ flag_keys_to_evaluate=["random_key"],
1759
1761
  )
1760
1762
  patch_flags.reset_mock()
1761
1763
  client.get_all_flags_and_payloads("all_flags_payloads_id")
@@ -1816,6 +1818,7 @@ class TestClient(unittest.TestCase):
1816
1818
  "instance": {"$group_key": "app.posthog.com"},
1817
1819
  },
1818
1820
  geoip_disable=False,
1821
+ flag_keys_to_evaluate=["random_key"],
1819
1822
  )
1820
1823
 
1821
1824
  patch_flags.reset_mock()
@@ -1842,6 +1845,7 @@ class TestClient(unittest.TestCase):
1842
1845
  "instance": {"$group_key": "app.posthog.com"},
1843
1846
  },
1844
1847
  geoip_disable=False,
1848
+ flag_keys_to_evaluate=["random_key"],
1845
1849
  )
1846
1850
 
1847
1851
  patch_flags.reset_mock()
@@ -2187,6 +2191,7 @@ class TestClient(unittest.TestCase):
2187
2191
  "only_evaluate_locally": None,
2188
2192
  "person_properties": None,
2189
2193
  "group_properties": None,
2194
+ "flag_keys_filter": None,
2190
2195
  }
2191
2196
  self.assertEqual(result, expected)
2192
2197
 
@@ -2197,6 +2202,7 @@ class TestClient(unittest.TestCase):
2197
2202
  "only_evaluate_locally": None,
2198
2203
  "person_properties": None,
2199
2204
  "group_properties": None,
2205
+ "flag_keys_filter": None,
2200
2206
  }
2201
2207
  self.assertEqual(result, expected)
2202
2208
 
@@ -2212,6 +2218,7 @@ class TestClient(unittest.TestCase):
2212
2218
  "only_evaluate_locally": True,
2213
2219
  "person_properties": {"plan": "premium"},
2214
2220
  "group_properties": {"company": {"type": "enterprise"}},
2221
+ "flag_keys_filter": None,
2215
2222
  }
2216
2223
  self.assertEqual(result, expected)
2217
2224
 
@@ -2223,6 +2230,7 @@ class TestClient(unittest.TestCase):
2223
2230
  "only_evaluate_locally": None,
2224
2231
  "person_properties": {"user_id": "123"},
2225
2232
  "group_properties": None,
2233
+ "flag_keys_filter": None,
2226
2234
  }
2227
2235
  self.assertEqual(result, expected)
2228
2236
 
@@ -2233,6 +2241,7 @@ class TestClient(unittest.TestCase):
2233
2241
  "only_evaluate_locally": None,
2234
2242
  "person_properties": None,
2235
2243
  "group_properties": None,
2244
+ "flag_keys_filter": None,
2236
2245
  }
2237
2246
  self.assertEqual(result, expected)
2238
2247
 
@@ -2249,6 +2258,53 @@ class TestClient(unittest.TestCase):
2249
2258
  client._parse_send_feature_flags(None)
2250
2259
  self.assertIn("Invalid type for send_feature_flags", str(cm.exception))
2251
2260
 
2261
+ @mock.patch("posthog.client.flags")
2262
+ def test_capture_with_send_feature_flags_flag_keys_filter(self, patch_flags):
2263
+ """Test that SendFeatureFlagsOptions with flag_keys_filter only evaluates specified flags"""
2264
+ # When flag_keys_to_evaluate is provided, the API should only return the requested flags
2265
+ patch_flags.return_value = {
2266
+ "featureFlags": {
2267
+ "flag1": "value1",
2268
+ "flag3": "value3",
2269
+ }
2270
+ }
2271
+
2272
+ with mock.patch("posthog.client.batch_post") as mock_post:
2273
+ client = Client(
2274
+ FAKE_TEST_API_KEY,
2275
+ on_error=self.set_fail,
2276
+ personal_api_key=FAKE_TEST_API_KEY,
2277
+ sync_mode=True,
2278
+ )
2279
+
2280
+ send_options = {
2281
+ "flag_keys_filter": ["flag1", "flag3"],
2282
+ "person_properties": {"subscription": "pro"},
2283
+ }
2284
+
2285
+ msg_uuid = client.capture(
2286
+ "test event", distinct_id="distinct_id", send_feature_flags=send_options
2287
+ )
2288
+
2289
+ self.assertIsNotNone(msg_uuid)
2290
+ self.assertFalse(self.failed)
2291
+
2292
+ # Verify flags() was called with flag_keys_to_evaluate
2293
+ patch_flags.assert_called_once()
2294
+ call_args = patch_flags.call_args[1]
2295
+ self.assertEqual(call_args["flag_keys_to_evaluate"], ["flag1", "flag3"])
2296
+ self.assertEqual(call_args["person_properties"], {"subscription": "pro"})
2297
+
2298
+ # Check the message includes only the filtered flags
2299
+ mock_post.assert_called_once()
2300
+ batch_data = mock_post.call_args[1]["batch"]
2301
+ msg = batch_data[0]
2302
+
2303
+ self.assertEqual(msg["properties"]["$feature/flag1"], "value1")
2304
+ self.assertEqual(msg["properties"]["$feature/flag3"], "value3")
2305
+ # flag2 should not be included since it wasn't requested
2306
+ self.assertNotIn("$feature/flag2", msg["properties"])
2307
+
2252
2308
  @mock.patch("posthog.client.batch_post")
2253
2309
  def test_get_feature_flag_result_with_empty_string_payload(self, patch_batch_post):
2254
2310
  """Test that get_feature_flag_result returns a FeatureFlagResult when payload is empty string"""