From 94fe86afe8564648c41e30cdf7d4fa122b0b7ac7 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Sun, 14 Jul 2019 03:09:08 +0300 Subject: [PATCH] tests: import-url: rewrite and move error msg test (#2262) This one was failing randomly. Signed-off-by: Ruslan Kuprieiev --- tests/func/test_import_url.py | 21 --------------------- tests/unit/command/test_imp_url.py | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/func/test_import_url.py b/tests/func/test_import_url.py index c9fd66bcf..6c45d4c92 100644 --- a/tests/func/test_import_url.py +++ b/tests/func/test_import_url.py @@ -3,11 +3,9 @@ import dvc from dvc.utils.compat import str import os -import logging from uuid import uuid4 from dvc.utils.compat import urljoin -from dvc.exceptions import DvcException from dvc.main import main from mock import patch, mock_open, call from tests.basic_env import TestDvc @@ -45,25 +43,6 @@ class TestDefaultOutput(TestDvc): self.assertEqual(fd.read(), "content") -class TestFailedImportMessage(TestDvc): - @patch("dvc.repo.imp_url.imp_url", side_effect=DvcException("message")) - def test(self, _): - page_address = "http://somesite.com/file_name" - - self._caplog.clear() - - with self._caplog.at_level(logging.ERROR, logger="dvc"): - main(["import-url", page_address]) - - expected_error = ( - "failed to import http://somesite.com/file_name." - " You could also try downloading it manually and" - " adding it with `dvc add` command." - ) - - assert expected_error in self._caplog.text - - class TestInterruptedDownload(TestDvc): @property def remote(self): diff --git a/tests/unit/command/test_imp_url.py b/tests/unit/command/test_imp_url.py index c7d4e2e48..2e11ff520 100644 --- a/tests/unit/command/test_imp_url.py +++ b/tests/unit/command/test_imp_url.py @@ -1,4 +1,7 @@ +import logging + from dvc.cli import parse_args +from dvc.exceptions import DvcException from dvc.command.imp_url import CmdImportUrl @@ -14,3 +17,21 @@ def test_import_url(mocker, dvc_repo): assert cmd.run() == 0 m.assert_called_once_with("src", out="out", resume=True, fname="file") + + +def test_failed_import_url(mocker, caplog, dvc_repo): + cli_args = parse_args(["import-url", "http://somesite.com/file_name"]) + assert cli_args.func == CmdImportUrl + + cmd = cli_args.func(cli_args) + with mocker.patch.object( + cmd.repo, "imp_url", side_effect=DvcException("error") + ): + with caplog.at_level(logging.ERROR, logger="dvc"): + assert cmd.run() == 1 + expected_error = ( + "failed to import http://somesite.com/file_name. " + "You could also try downloading it manually and " + "adding it with `dvc add` command." + ) + assert expected_error in caplog.text