Commit 599a6e89 authored by Christine MARCEL's avatar Christine MARCEL Committed by Samuel GAIST
Browse files

[widgets][assetwidget] Add confirmation dialog when deleting asset

Fixes #242
parent 2891474b
......@@ -335,6 +335,55 @@ class TestAssetWidget:
assert asset_widget.current_asset == asset
assert os.path.exists(asset.declaration_path)
@pytest.mark.parametrize(
"messagebox_answer", [QMessageBox.Yes, QMessageBox.No], ids=["Yes", "No"]
)
def test_delete_other_asset(
self,
qtbot,
monkeypatch,
test_prefix,
beat_context,
asset_type,
asset_type_prefix_entry_map,
messagebox_answer,
):
asset_widget = AssetWidget()
qtbot.addWidget(asset_widget)
asset_widget.set_context(beat_context)
monkeypatch.setattr(QMessageBox, "question", lambda *args: messagebox_answer)
asset_model = AssetModel()
asset_model.setLatestOnlyEnabled(False)
asset_model.asset_type = asset_type
asset_model.prefix_path = test_prefix
asset_list = asset_model.stringList()
assert len(asset_list) >= 2
# Using lasts assets in the list because of dataformats basetypes
asset_name_to_edit = asset_list[-1]
asset_name_to_delete = asset_list[-2]
asset_to_edit = Asset(test_prefix, asset_type, asset_name_to_edit)
asset_to_delete = Asset(test_prefix, asset_type, asset_name_to_delete)
with qtbot.waitSignal(asset_widget.currentAssetChanged):
asset_widget.loadAsset(asset_to_edit)
assert asset_widget.current_editor.asset_type != AssetType.UNKNOWN
asset_widget.deleteAsset(asset_to_delete.declaration_path)
if messagebox_answer == QMessageBox.Yes:
assert asset_widget.current_editor.asset_type != AssetType.UNKNOWN
assert os.path.exists(asset_to_edit.declaration_path)
assert not os.path.exists(asset_to_delete.declaration_path)
else:
assert asset_widget.current_editor.asset_type != AssetType.UNKNOWN
assert asset_widget.current_asset == asset_to_edit
assert os.path.exists(asset_to_edit.declaration_path)
assert os.path.exists(asset_to_delete.declaration_path)
def test_load_empty_json(
self,
qtbot,
......
......@@ -328,7 +328,7 @@ class AssetWidget(QWidget):
"""
if self.current_asset and self.current_asset.declaration_path == file_path:
"""Check before deletion"""
# Check before deletion
answer = QMessageBox.question(
self,
self.tr("Deletion requested"),
......@@ -345,6 +345,16 @@ class AssetWidget(QWidget):
self.current_asset.delete()
self.current_asset = None
else:
# Check before deletion
answer = QMessageBox.question(
self,
self.tr("Deletion requested"),
self.tr(
"You are about to delete an asset\n\nAre you sure you want to do that ?"
),
)
if answer == QMessageBox.No:
return
asset = Asset.from_path(self.prefix_root_path, file_path)
asset.delete()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment