Files
wehub-resource-sync 91e75e620b
CI: cua-driver distro-compat matrix / debian:12 (glibc 2.36) (push) Has been cancelled
CI: SPDX Headers / Check SPDX headers (warn-only) (push) Has been cancelled
CD: Docs MCP Server / build (linux/amd64) (push) Has been cancelled
CD: Docs MCP Server / build (linux/arm64) (push) Has been cancelled
CD: Docs MCP Server / merge (push) Has been cancelled
CI: cua-driver distro-compat matrix / Resolve release version (push) Has been cancelled
CI: cua-driver distro-compat matrix / fedora:41 (glibc 2.40) (push) Has been cancelled
CI: cua-driver distro-compat matrix / rockylinux:9 (glibc 2.34) (push) Has been cancelled
CI: cua-driver distro-compat matrix / ubuntu:22.04 (glibc 2.35) (push) Has been cancelled
CI: cua-driver distro-compat matrix / ubuntu:24.04 (glibc 2.39) (push) Has been cancelled
CI: cua-driver distro-compat matrix / Distro compat summary (push) Has been cancelled
CI: Rust Linux unit / Rust Linux unit and compile (push) Has been cancelled
CI: Rust Windows unit / Rust Windows unit and compile (push) Has been cancelled
CI: Nix Linux Rust source / Nix / compositor build (push) Has been cancelled
CI: Nix Linux Rust source / Nix / driver package (push) Has been cancelled
CI: Nix Linux Rust source / Nix / Rust unit tests (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:03:19 +08:00

64 lines
1.9 KiB
Python

"""
Required environment variables:
- CUA_API_KEY: API key for Cua cloud provider
"""
import os
import sys
from pathlib import Path
import pytest
# Load environment variables from .env file
project_root = Path(__file__).parent.parent
env_file = project_root / ".env"
print(f"Loading environment from: {env_file}")
from dotenv import load_dotenv
load_dotenv(env_file)
# Add paths to sys.path if needed
pythonpath = os.environ.get("PYTHONPATH", "")
for path in pythonpath.split(":"):
if path and path not in sys.path:
sys.path.insert(0, path) # Insert at beginning to prioritize
print(f"Added to sys.path: {path}")
from cua_core.telemetry import (
destroy_telemetry_client,
is_telemetry_enabled,
record_event,
)
class TestTelemetry:
def setup_method(self):
"""Reset environment variables before each test"""
os.environ.pop("CUA_TELEMETRY", None)
os.environ.pop("CUA_TELEMETRY_ENABLED", None)
destroy_telemetry_client()
def test_telemetry_disabled_when_cua_telemetry_is_off(self):
"""Should return false when CUA_TELEMETRY is off"""
os.environ["CUA_TELEMETRY"] = "off"
assert is_telemetry_enabled() is False
def test_telemetry_enabled_when_cua_telemetry_not_set(self):
"""Should return true when CUA_TELEMETRY is not set"""
assert is_telemetry_enabled() is True
def test_telemetry_disabled_when_cua_telemetry_enabled_is_0(self):
"""Should return false if CUA_TELEMETRY_ENABLED is 0"""
os.environ["CUA_TELEMETRY_ENABLED"] = "0"
assert is_telemetry_enabled() is False
def test_send_test_event_to_posthog(self):
"""Should send a test event to PostHog"""
# This should not raise an exception
record_event("test_telemetry", {"message": "Hello, world!"})
if __name__ == "__main__":
# Run tests directly
pytest.main([__file__, "-v"])