Commit 8487d65c authored by Samuel GAIST's avatar Samuel GAIST Committed by Samuel GAIST
Browse files

[test][assetwidget] Refactor delete tests for same and other asset type

parent 599a6e89
Pipeline #32256 passed with stage
in 31 minutes and 42 seconds
......@@ -25,6 +25,7 @@
import os
import pytest
import random
from PyQt5 import QtCore
......@@ -335,10 +336,47 @@ class TestAssetWidget:
assert asset_widget.current_asset == asset
assert os.path.exists(asset.declaration_path)
def __check_deletion(
self, qtbot, beat_context, asset_to_edit, asset_to_delete, messagebox_answer
):
asset_widget = AssetWidget()
qtbot.addWidget(asset_widget)
asset_widget.set_context(beat_context)
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 __get_asset_name_list(self, test_prefix, asset_type):
asset_model = AssetModel()
asset_model.setLatestOnlyEnabled(False)
asset_model.asset_type = asset_type
asset_model.prefix_path = test_prefix
asset_list = [
asset_name
for asset_name in asset_model.stringList()
if "error" not in asset_name
]
assert len(asset_list) >= 2
return asset_list
@pytest.mark.parametrize(
"messagebox_answer", [QMessageBox.Yes, QMessageBox.No], ids=["Yes", "No"]
)
def test_delete_other_asset(
def test_delete_same_asset_type(
self,
qtbot,
monkeypatch,
......@@ -348,41 +386,72 @@ class TestAssetWidget:
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()
asset_name_list = self.__get_asset_name_list(test_prefix, asset_type)
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]
if asset_type == AssetType.DATAFORMAT:
# Using lasts assets in the list because of dataformats basetypes
asset_name_to_edit = asset_name_list[-1]
asset_name_to_delete = asset_name_list[-2]
else:
asset_name_to_edit = asset_name_list[0]
asset_name_to_delete = asset_name_list[1]
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
self.__check_deletion(
qtbot, beat_context, asset_to_edit, asset_to_delete, messagebox_answer
)
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)
@pytest.mark.parametrize(
"messagebox_answer", [QMessageBox.Yes, QMessageBox.No], ids=["Yes", "No"]
)
def test_delete_other_asset_type(
self,
qtbot,
monkeypatch,
test_prefix,
beat_context,
asset_type,
asset_type_prefix_entry_map,
messagebox_answer,
):
monkeypatch.setattr(QMessageBox, "question", lambda *args: messagebox_answer)
asset_name_list = self.__get_asset_name_list(test_prefix, asset_type)
index = 0
if asset_type == AssetType.DATAFORMAT:
# Using lasts assets in the list because of dataformats basetypes
index = -1
asset_name_to_edit = asset_name_list[index]
asset_to_delete_type = random.choice(
[
asset
for asset in AssetType
if asset not in [asset_type, AssetType.UNKNOWN]
]
)
asset_to_delete_name_list = self.__get_asset_name_list(
test_prefix, asset_to_delete_type
)
index = 0
if asset_to_delete_type == AssetType.DATAFORMAT:
# Using lasts assets in the list because of dataformats basetypes
index = -1
asset_name_to_delete = asset_to_delete_name_list[index]
asset_to_edit = Asset(test_prefix, asset_type, asset_name_to_edit)
asset_to_delete = Asset(test_prefix, asset_to_delete_type, asset_name_to_delete)
self.__check_deletion(
qtbot, beat_context, asset_to_edit, asset_to_delete, messagebox_answer
)
def test_load_empty_json(
self,
......
Markdown is supported
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