Merge pull request #1795 from ei-grad/fix-test-analytics

tests: fix for globally disabled analytics
This commit is contained in:
Ruslan Kuprieiev
2019-03-28 14:45:53 +02:00
committed by GitHub
2 changed files with 17 additions and 5 deletions
+9 -3
View File
@@ -201,6 +201,13 @@ class Analytics(object):
json.dump(self.info, fobj)
return fobj.name
@staticmethod
def _is_enabled_config(config):
from dvc.config import Config
core = config.config.get(Config.SECTION_CORE, {})
return core.get(Config.SECTION_CORE_ANALYTICS, True)
@staticmethod
def _is_enabled(cmd=None):
from dvc.config import Config
@@ -226,10 +233,9 @@ class Analytics(object):
config = cmd.config
assert config is not None
core = config.config.get(Config.SECTION_CORE, {})
enabled = core.get(Config.SECTION_CORE_ANALYTICS, True)
enabled = Analytics._is_enabled_config(config)
logger.debug(
"Analytics is {}abled.".format("en" if enabled else "dis")
"Analytics is {}.".format("enabled" if enabled else "disabled")
)
return enabled
+8 -2
View File
@@ -27,18 +27,24 @@ class TestAnalytics(TestDir):
self.assertNotEqual(a.info[a.PARAM_SYSTEM_INFO], {})
@mock.patch.object(os, "getenv", new=_clean_getenv)
@mock.patch(
"dvc.analytics.Analytics._is_enabled_config", return_value=True
)
@mock.patch("requests.post")
def test_send(self, mockpost):
def test_send(self, mockpost, _):
ret = main(["daemon", "analytics", Analytics().dump(), "-v"])
self.assertEqual(ret, 0)
self.assertTrue(mockpost.called)
@mock.patch.object(os, "getenv", new=_clean_getenv)
@mock.patch(
"dvc.analytics.Analytics._is_enabled_config", return_value=True
)
@mock.patch.object(
requests, "post", side_effect=requests.exceptions.RequestException()
)
def test_send_failed(self, mockpost):
def test_send_failed(self, mockpost, _):
ret = main(["daemon", "analytics", Analytics().dump(), "-v"])
self.assertEqual(ret, 0)