Improve testing of connection/download/checksum exceptions

This adds a new test that recreates #546
This commit is contained in:
Dave Dalcino
2022-08-11 21:40:39 -07:00
parent 2b390e53c5
commit 0650ac9283

View File

@@ -873,16 +873,18 @@ def test_show_list_empty(monkeypatch, capsys):
assert format(error.value) == "No tools available for this request."
def test_show_list_bad_connection(monkeypatch, capsys):
for exception_class, error_msg in (
(ArchiveConnectionError, "Failure to connect to some url"),
(ArchiveDownloadError, "Failure to download some xml file"),
):
def mock(self):
@pytest.mark.parametrize(
"exception_class, error_msg, source",
(
(ArchiveConnectionError, "Failure to connect to some url", "aqt.metadata.getUrl"),
(ArchiveDownloadError, "Failure to download some xml file", "aqt.metadata.getUrl"),
),
)
def test_show_list_bad_connection(monkeypatch, capsys, exception_class, error_msg, source):
def mock(*args, **kwargs):
raise exception_class(error_msg)
monkeypatch.setattr(MetadataFactory, "getList", mock)
monkeypatch.setattr(source, mock)
meta = MetadataFactory(mac_wasm, spec=SimpleSpec("<5.9"))
with pytest.raises(exception_class) as error:
show_list(meta)
@@ -895,6 +897,33 @@ def test_show_list_bad_connection(monkeypatch, capsys):
)
@pytest.mark.parametrize(
"exception_class, error_msg, source", ((ArchiveConnectionError, "Failure to connect", "aqt.helper.getUrl"),)
)
def test_show_list_bad_connection(monkeypatch, capsys, exception_class, error_msg, source):
def mock(*args, **kwargs):
raise exception_class(error_msg)
monkeypatch.setattr(source, mock)
cli = Cli()
cli.run("list-qt linux desktop --arch 6.4.0".split())
out, err = capsys.readouterr()
sys.stdout.write(out)
sys.stderr.write(err)
assert (
err == "ERROR : Failed to download checksum for the file 'Updates.xml' from mirrors "
"'['https://download.qt.io']\n"
"==============================Suggested follow-up:==============================\n"
"* Check your internet connection\n"
"* Consider modifying `requests.max_retries_to_retrieve_hash` in settings.ini\n"
"* Consider modifying `mirrors.trusted_mirrors` in settings.ini "
"(see https://aqtinstall.readthedocs.io/en/stable/configuration.html#configuration)\n"
"* Please use 'aqt list-qt linux desktop' to show versions of Qt available.\n"
)
def fetch_expected_tooldata(json_filename: str) -> ToolData:
text = (Path(__file__).parent / "data" / json_filename).read_text("utf-8")
raw_tooldata: List[List[str]] = json.loads(text)["long_listing"]