You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
swarms/tests/telemetry/test_posthog_utils.py

100 lines
3.7 KiB

# Generated by CodiumAI
import pytest
class TestCodeUnderTest:
# Posthog instance is created successfully
def test_posthog_instance_created_successfully(self):
from unittest.mock import MagicMock
# Mock the Posthog class
posthog_mock = MagicMock()
# Create an instance of the Posthog class
posthog_instance = posthog_mock(
project_api_key="phc_Gz6XxldNZIkzW7QnSTGr5HZ28OAYPIfpE7X5A3vUsfO",
host="https://app.posthog.com",
)
# Assert that the Posthog instance was created successfully
assert isinstance(posthog_instance, posthog_mock)
# Project API key and host are correctly set
def test_project_api_key_and_host_correctly_set(self):
from unittest.mock import MagicMock
# Mock the Posthog class
posthog_mock = MagicMock()
# Create an instance of the Posthog class
posthog_instance = posthog_mock(
project_api_key="phc_Gz6XxldNZIkzW7QnSTGr5HZ28OAYPIfpE7X5A3vUsfO",
host="https://app.posthog.com",
)
# Assert that the project API key and host are correctly set
assert posthog_instance.project_api_key == "phc_Gz6XxldNZIkzW7QnSTGr5HZ28OAYPIfpE7X5A3vUsfO"
assert posthog_instance.host == "https://app.posthog.com"
# Invalid project API key raises an error
def test_invalid_project_api_key_raises_error(self):
from unittest.mock import MagicMock
# Mock the Posthog class
posthog_mock = MagicMock()
# Create an instance of the Posthog class with an invalid project API key
with pytest.raises(Exception):
posthog_instance = posthog_mock(
project_api_key="invalid_api_key",
host="https://app.posthog.com",
)
# Invalid host raises an error
def test_invalid_host_raises_error(self):
from unittest.mock import MagicMock
# Mock the Posthog class
posthog_mock = MagicMock()
# Create an instance of the Posthog class with an invalid host
with pytest.raises(Exception):
posthog_instance = posthog_mock(
project_api_key="phc_Gz6XxldNZIkzW7QnSTGr5HZ28OAYPIfpE7X5A3vUsfO",
host="invalid_host",
)
# Posthog instance can be created with different project API keys and hosts
def test_posthog_instance_created_with_different_api_keys_and_hosts(self):
from unittest.mock import MagicMock
# Mock the Posthog class
posthog_mock = MagicMock()
# Create an instance of the Posthog class with different project API keys and hosts
posthog_instance_1 = posthog_mock(
project_api_key="phc_Gz6XxldNZIkzW7QnSTGr5HZ28OAYPIfpE7X5A3vUsfO",
host="https://app.posthog.com",
)
posthog_instance_2 = posthog_mock(
project_api_key="phc_1234567890",
host="https://example.com",
)
# Assert that the Posthog instances were created successfully
assert isinstance(posthog_instance_1, posthog_mock)
assert isinstance(posthog_instance_2, posthog_mock)
# Posthog instance can be created without specifying a project API key or host
def test_posthog_instance_created_without_api_key_or_host(self):
from unittest.mock import MagicMock
# Mock the Posthog class
posthog_mock = MagicMock()
# Create an instance of the Posthog class without specifying a project API key or host
posthog_instance = posthog_mock()
# Assert that the Posthog instance was created successfully
assert isinstance(posthog_instance, posthog_mock)