Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
automatically created test user
- tests: clear persistent upload jobs before and after each GUI test,
so that new main windows do not upload jobs of previous tests again
- tests: let name resolution fail immediately in
`test_gui_start_with_bad_server` (took 20 minutes on Windows)
1.1.3
- enh: use `HTTPAdapter` with `urlib3`'s `Retry` to handle connection issues
- enh: use `requests.Session` when caching is disabled
Expand Down
23 changes: 23 additions & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import contextlib
import datetime
import functools
import json
import os
import pathlib
import shutil
import socket
import tempfile
from unittest import mock
import uuid
import warnings

Expand All @@ -25,6 +28,26 @@
tpath = pathlib.Path(__file__).parent / "data" / "text_file.txt"


@contextlib.contextmanager
def fail_name_resolution(host_part):
"""Let name resolution of hosts containing `host_part` fail immediately

On the Windows GitHub Actions runners, resolving the non-existent host
"WRONG-dcor-dev.mpl.mpg.de" took about half a minute per lookup, which
made `test_gui_start_with_bad_server` take 20 minutes.
"""
getaddrinfo = socket.getaddrinfo

def getaddrinfo_fail(host, *args, **kwargs):
if host_part in str(host).lower():
raise socket.gaierror(socket.EAI_NONAME,
"Name or service not known")
return getaddrinfo(host, *args, **kwargs)

with mock.patch("socket.getaddrinfo", side_effect=getaddrinfo_fail):
yield


def get_api():
api = CKANAPI(server=SERVER, api_key=get_api_key(), ssl_verify=True)
return api
Expand Down
23 changes: 12 additions & 11 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,18 @@ def test_gui_start_with_bad_server(qtbot):
settings = QtCore.QSettings()
settings.setValue("auth/server", "WRONG-dcor-dev.mpl.mpg.de")
try:
mw = DCORAid()
qtbot.addWidget(mw)
QtWidgets.QApplication.setActiveWindow(mw)
QtWidgets.QApplication.processEvents(
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 200)
# just make sure that DCOR-Aid thinks it is offline
assert not mw.ui.panel_upload.isEnabled()
assert not mw.ui.panel_download.isEnabled()
mw.close()
QtWidgets.QApplication.processEvents(
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 200)
with common.fail_name_resolution("wrong-dcor-dev"):
mw = DCORAid()
qtbot.addWidget(mw)
QtWidgets.QApplication.setActiveWindow(mw)
QtWidgets.QApplication.processEvents(
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 200)
# just make sure that DCOR-Aid thinks it is offline
assert not mw.ui.panel_upload.isEnabled()
assert not mw.ui.panel_download.isEnabled()
mw.close()
QtWidgets.QApplication.processEvents(
QtCore.QEventLoop.ProcessEventsFlag.AllEvents, 200)
finally:
# reset to testing defaults
settings.setValue("auth/server", common.SERVER)
Expand Down
Loading