mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
tests: analytics.find_or_create_user_id
This commit is contained in:
+1
-1
@@ -119,7 +119,7 @@ def find_or_create_user_id():
|
||||
try:
|
||||
with Lock(lockfile):
|
||||
try:
|
||||
user_id = json.load(fname.read_text())["user_id"]
|
||||
user_id = json.loads(fname.read_text())["user_id"]
|
||||
except (FileNotFoundError, json.JSONDecodeError, AttributeError):
|
||||
user_id = str(uuid.uuid4())
|
||||
makedirs(fname.parent, exist_ok=True)
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import pytest
|
||||
import mock
|
||||
|
||||
from dvc import analytics
|
||||
|
||||
@@ -22,3 +23,13 @@ def test_is_enabled(dvc_repo, config, result, monkeypatch):
|
||||
monkeypatch.delenv("DVC_TEST")
|
||||
|
||||
assert result == analytics.is_enabled()
|
||||
|
||||
|
||||
def test_find_or_create_user_id(tmp_path):
|
||||
with mock.patch(
|
||||
"dvc.config.Config.get_global_config_dir", return_value=tmp_path
|
||||
):
|
||||
created = analytics.find_or_create_user_id()
|
||||
found = analytics.find_or_create_user_id()
|
||||
|
||||
assert created == found
|
||||
|
||||
Reference in New Issue
Block a user