Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions posthog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ def group_identify(
timestamp=None, # type: Optional[datetime.datetime]
uuid=None, # type: Optional[str]
disable_geoip=None, # type: Optional[bool]
distinct_id=None, # type: Optional[str]
):
# type: (...) -> Optional[str]
"""
Expand All @@ -403,6 +404,7 @@ def group_identify(
timestamp: Optional timestamp for the event
uuid: Optional UUID for the event
disable_geoip: Whether to disable GeoIP lookup
distinct_id: Optional distinct ID of the user performing the action

Examples:
```python
Expand All @@ -425,6 +427,7 @@ def group_identify(
timestamp=timestamp,
uuid=uuid,
disable_geoip=disable_geoip,
distinct_id=distinct_id,
)


Expand Down Expand Up @@ -611,6 +614,7 @@ def get_all_flags(
only_evaluate_locally=False, # type: bool
disable_geoip=None, # type: Optional[bool]
device_id=None, # type: Optional[str]
flag_keys_to_evaluate=None, # type: Optional[list[str]]
) -> Optional[dict[str, FeatureFlag]]:
"""
Get all flags for a given user.
Expand Down Expand Up @@ -644,6 +648,7 @@ def get_all_flags(
only_evaluate_locally=only_evaluate_locally,
disable_geoip=disable_geoip,
device_id=device_id,
flag_keys_to_evaluate=flag_keys_to_evaluate,
)


Expand Down Expand Up @@ -747,6 +752,7 @@ def get_all_flags_and_payloads(
only_evaluate_locally=False,
disable_geoip=None, # type: Optional[bool]
device_id=None, # type: Optional[str]
flag_keys_to_evaluate=None, # type: Optional[list[str]]
) -> FlagsAndPayloads:
return _proxy(
"get_all_flags_and_payloads",
Expand All @@ -757,6 +763,7 @@ def get_all_flags_and_payloads(
only_evaluate_locally=only_evaluate_locally,
disable_geoip=disable_geoip,
device_id=device_id,
flag_keys_to_evaluate=flag_keys_to_evaluate,
)


Expand Down
63 changes: 63 additions & 0 deletions posthog/test/test_module.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import unittest
from unittest import mock

import posthog
from posthog import Posthog


Expand Down Expand Up @@ -30,3 +32,64 @@ def test_alias(self):

def test_flush(self):
self.posthog.flush()


class TestModuleLevelWrappers(unittest.TestCase):
"""Test that module-level wrapper functions in posthog/__init__.py
correctly propagate all parameters to the Client methods."""

def setUp(self):
self.mock_client = mock.MagicMock()
self._original_client = posthog.default_client
posthog.default_client = self.mock_client

def tearDown(self):
posthog.default_client = self._original_client

def test_group_identify_propagates_distinct_id(self):
posthog.group_identify(
"company",
"company_123",
{"name": "Awesome Inc."},
distinct_id="user_456",
)
self.mock_client.group_identify.assert_called_once_with(
group_type="company",
group_key="company_123",
properties={"name": "Awesome Inc."},
timestamp=None,
uuid=None,
disable_geoip=None,
distinct_id="user_456",
)

def test_group_identify_distinct_id_defaults_to_none(self):
posthog.group_identify("company", "company_123")
call_kwargs = self.mock_client.group_identify.call_args[1]
self.assertIsNone(call_kwargs["distinct_id"])

def test_get_all_flags_propagates_flag_keys_to_evaluate(self):
posthog.get_all_flags(
"user_123",
flag_keys_to_evaluate=["flag-1", "flag-2"],
)
call_kwargs = self.mock_client.get_all_flags.call_args[1]
self.assertEqual(call_kwargs["flag_keys_to_evaluate"], ["flag-1", "flag-2"])

def test_get_all_flags_flag_keys_defaults_to_none(self):
posthog.get_all_flags("user_123")
call_kwargs = self.mock_client.get_all_flags.call_args[1]
self.assertIsNone(call_kwargs["flag_keys_to_evaluate"])

def test_get_all_flags_and_payloads_propagates_flag_keys_to_evaluate(self):
posthog.get_all_flags_and_payloads(
"user_123",
flag_keys_to_evaluate=["flag-1", "flag-2"],
)
call_kwargs = self.mock_client.get_all_flags_and_payloads.call_args[1]
self.assertEqual(call_kwargs["flag_keys_to_evaluate"], ["flag-1", "flag-2"])

def test_get_all_flags_and_payloads_flag_keys_defaults_to_none(self):
posthog.get_all_flags_and_payloads("user_123")
call_kwargs = self.mock_client.get_all_flags_and_payloads.call_args[1]
self.assertIsNone(call_kwargs["flag_keys_to_evaluate"])
Loading