
* add eradicate rules for commented out code * remove output change * fix pyi messed up indent * fix pyi again * fix layout docstring * fix pyi_generator to remove commented out props from docs * fix pyi_generator and regenerate some pyi * fix double strip * update all pyi * try to fix stuff in pyi_gen * whatever * remove that maybe? i don't know * fix that shit? * fix more shit, idk * better not see you ever again, extra line
50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
import pytest
|
|
from packaging.version import parse as parse_python_version
|
|
|
|
from reflex.utils import telemetry
|
|
|
|
|
|
def test_telemetry():
|
|
"""Test that telemetry is sent correctly."""
|
|
# Check that the user OS is one of the supported operating systems.
|
|
user_os = telemetry.get_os()
|
|
assert user_os is not None
|
|
assert user_os in ["Linux", "Darwin", "Java", "Windows"]
|
|
|
|
# Check that the CPU count and memory are greater than 0.
|
|
assert telemetry.get_cpu_count() > 0
|
|
|
|
# Check that the available memory is greater than 0
|
|
assert telemetry.get_memory() > 0
|
|
|
|
# Check that the Reflex version is not None.
|
|
assert telemetry.get_reflex_version() is not None
|
|
|
|
# Check that the Python version is greater than 3.7.
|
|
python_version = telemetry.get_python_version()
|
|
assert python_version is not None
|
|
assert parse_python_version(python_version) >= parse_python_version("3.7")
|
|
|
|
|
|
def test_disable():
|
|
"""Test that disabling telemetry works."""
|
|
assert not telemetry._send("test", telemetry_enabled=False)
|
|
|
|
|
|
@pytest.mark.parametrize("event", ["init", "reinit", "run-dev", "run-prod", "export"])
|
|
def test_send(mocker, event):
|
|
httpx_post_mock = mocker.patch("httpx.post")
|
|
|
|
# Mock the read_text method of Path
|
|
pathlib_path_read_text_mock = mocker.patch(
|
|
"pathlib.Path.read_text",
|
|
return_value='{"project_hash": "78285505863498957834586115958872998605"}',
|
|
)
|
|
|
|
mocker.patch("platform.platform", return_value="Mocked Platform")
|
|
|
|
telemetry._send(event, telemetry_enabled=True)
|
|
httpx_post_mock.assert_called_once()
|
|
|
|
assert pathlib_path_read_text_mock.call_count == 2
|