Skip to content

Commit

Permalink
fix: check whether circle is writable (#64) and minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Oct 14, 2022
1 parent 9bdd4f8 commit 2836e58
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions dcoraid/api/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def dataset_create(dataset_dict, api, resources=None,
if resources is None:
resources = []
# Make sure we can access the desired circle.
usr_circles = [c["name"] for c in api.get("organization_list_for_user")]
usr_circles = [c["name"] for c in api.get("organization_list_for_user",
permission="create_dataset")]
tgt_circle = dataset_dict.get("owner_org")
if tgt_circle is None:
raise APIConflictError(
Expand All @@ -68,8 +69,7 @@ def dataset_create(dataset_dict, api, resources=None,
else:
raise APINotFoundError(
f"The circle '{tgt_circle}' does not exist or the user "
f"{api.user_name} is not a member thereof. Cannot upload "
f"dataset.")
f"{api.user_name} is not allowed to upload datasets to it.")
# Create the dataset.
dataset_dict = copy.deepcopy(dataset_dict)
dataset_dict["state"] = "draft"
Expand Down
2 changes: 1 addition & 1 deletion dcoraid/gui/upload/circle_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def request_circle(parent_widget):
circle_texts = [c["title"] if c["title"] else c["name"] for c in circs]
text, ok_pressed = QtWidgets.QInputDialog.getItem(
parent_widget,
"Choose circe",
"Please choose a circle",
"You have upload-permissions to multiple circles. Please\n"
"choose the one where you wish to upload your datasets to.",
circle_texts,
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import atexit
import os.path as os_path
import pathlib
import shutil
Expand Down Expand Up @@ -41,7 +42,7 @@ def cleanup_dcoraid_tasks():


def pytest_configure(config):
"""This is ran before all tests"""
"""This is run before all tests"""
# disable update checking
QtCore.QCoreApplication.setOrganizationName("DCOR")
QtCore.QCoreApplication.setOrganizationDomain("dcor.mpl.mpg.de")
Expand All @@ -58,6 +59,7 @@ def pytest_configure(config):
cleanup_dcoraid_tasks()
# set global temp directory
tempfile.tempdir = TMPDIR
atexit.register(shutil.rmtree, TMPDIR, ignore_errors=True)


def pytest_unconfigure(config):
Expand All @@ -74,8 +76,6 @@ def pytest_unconfigure(config):
settings.sync()
# cleanup
cleanup_dcoraid_tasks()
# clear global temp directory
shutil.rmtree(TMPDIR, ignore_errors=True)


def pytest_sessionstart(session):
Expand Down
42 changes: 21 additions & 21 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,27 +273,6 @@ def test_gui_upload_task_bad_dataset_id_yes(mw, qtbot):
mw.panel_upload.jobs.daemon_compress.join()


def test_gui_upload_task_missing_circle(mw, qtbot):
"""When the organization is missing, DCOR-Aid should ask for it"""
task_id = str(uuid.uuid4())
dataset_dict = common.make_dataset_dict(hint="task_upload_no_org_")
dataset_dict.pop("owner_org")
tpath = common.make_upload_task(task_id=task_id,
dataset_dict=dataset_dict)
QtWidgets.QApplication.processEvents(QtCore.QEventLoop.AllEvents, 300)
with mock.patch.object(
QtWidgets.QFileDialog, "getOpenFileNames",
return_value=([tpath], None)), \
mock.patch.object(QtWidgets.QInputDialog, "getItem",
return_value=(common.CIRCLE, True)), \
mock.patch.object(QMessageBox, "information", return_value=None):
act = QtWidgets.QAction("some unimportant text")
act.setData("single")
mw.panel_upload.on_upload_task(action=act)
uj = mw.panel_upload.jobs[-1]
assert uj.task_id == task_id


def test_gui_upload_task_missing_circle_multiple(mw, qtbot):
"""DCOR-Aid should only ask *once* for the circle (not for every task)"""
task_id1 = str(uuid.uuid4())
Expand Down Expand Up @@ -358,3 +337,24 @@ def test_gui_upload_private(mw, qtbot):
dataset_dict = api.get(api_call="package_show", id=dataset_id)
assert dataset_dict["private"]
assert isinstance(dataset_dict["private"], bool)


def test_gui_upload_task_missing_circle(mw, qtbot):
"""When the organization is missing, DCOR-Aid should ask for it"""
task_id = str(uuid.uuid4())
dataset_dict = common.make_dataset_dict(hint="task_upload_no_org_")
dataset_dict.pop("owner_org")
tpath = common.make_upload_task(task_id=task_id,
dataset_dict=dataset_dict)
QtWidgets.QApplication.processEvents(QtCore.QEventLoop.AllEvents, 300)
with mock.patch.object(
QtWidgets.QFileDialog, "getOpenFileNames",
return_value=([tpath], None)), \
mock.patch.object(QtWidgets.QInputDialog, "getItem",
return_value=(common.CIRCLE, True)), \
mock.patch.object(QMessageBox, "information", return_value=None):
act = QtWidgets.QAction("some unimportant text")
act.setData("single")
mw.panel_upload.on_upload_task(action=act)
uj = mw.panel_upload.jobs[-1]
assert uj.task_id == task_id

0 comments on commit 2836e58

Please sign in to comment.