Make anonymous telemetry optional #1765 (#1774)

This commit is contained in:
k10
2024-09-09 22:29:06 +05:30
committed by GitHub
parent f01e8a083e
commit 58f29d8781
3 changed files with 44 additions and 1 deletions

29
tests/test_telemetry.py Normal file
View File

@@ -0,0 +1,29 @@
import os
import pytest
from unittest.mock import patch
MEM0_TELEMETRY = os.environ.get("MEM0_TELEMETRY", "True")
if isinstance(MEM0_TELEMETRY, str):
MEM0_TELEMETRY = MEM0_TELEMETRY.lower() in ("true", "1", "yes")
def use_telemetry():
if os.getenv('MEM0_TELEMETRY', "true").lower() == "true":
return True
return False
@pytest.fixture(autouse=True)
def reset_env():
with patch.dict(os.environ, {}, clear=True):
yield
def test_telemetry_enabled():
with patch.dict(os.environ, {'MEM0_TELEMETRY': "true"}):
assert use_telemetry() is True
def test_telemetry_disabled():
with patch.dict(os.environ, {'MEM0_TELEMETRY': "false"}):
assert use_telemetry() is False
def test_telemetry_default_enabled():
assert use_telemetry() is True