Files
dvc/tests/unit/command/test_imp_url.py
T
Ruslan Kuprieiev 94fe86afe8 tests: import-url: rewrite and move error msg test (#2262)
This one was failing randomly.

Signed-off-by: Ruslan Kuprieiev <[email protected]>
2019-07-14 03:09:08 +03:00

38 lines
1.2 KiB
Python

import logging
from dvc.cli import parse_args
from dvc.exceptions import DvcException
from dvc.command.imp_url import CmdImportUrl
def test_import_url(mocker, dvc_repo):
cli_args = parse_args(
["import-url", "src", "out", "--resume", "--file", "file"]
)
assert cli_args.func == CmdImportUrl
cmd = cli_args.func(cli_args)
m = mocker.patch.object(cmd.repo, "imp_url", autospec=True)
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