tests: analytics.find_or_create_user_id

This commit is contained in:
Mr. Outis
2019-11-26 13:40:11 -06:00
parent 34d3004779
commit 5261ed7148
3 changed files with 13 additions and 1 deletions
+1 -1
View File
@@ -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)
+1
View File
@@ -0,0 +1 @@
+11
View File
@@ -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