mirror of
https://github.com/trycua/computer.git
synced 2026-04-30 12:11:35 -05:00
Add tests for disabling telemetry
This commit is contained in:
+26
-4
@@ -23,11 +23,33 @@ for path in pythonpath.split(":"):
|
||||
sys.path.insert(0, path) # Insert at beginning to prioritize
|
||||
print(f"Added to sys.path: {path}")
|
||||
|
||||
from core.telemetry import record_event
|
||||
from core.telemetry import record_event, is_telemetry_enabled
|
||||
|
||||
@pytest.mark.asyncio(loop_scope="session")
|
||||
async def test_telemetry():
|
||||
record_event("test_telemetry", {"message": "Hello, world!"})
|
||||
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user