Commit 1d10ce54 authored by Samuel GAIST's avatar Samuel GAIST Committed by Samuel GAIST
Browse files

[widgets][assetwidget] Don't load invalid asset

Fixes #232
parent 28a6b07b
Pipeline #31546 passed with stage
in 23 minutes and 20 seconds
......@@ -306,3 +306,26 @@ class TestAssetWidget:
asset_widget.deleteAsset(asset.declaration_path)
assert asset_widget.current_editor.asset_type == AssetType.UNKNOWN
assert not os.path.exists(asset.declaration_path)
def test_load_empty_json(
self,
qtbot,
monkeypatch,
test_prefix,
beat_context,
asset_type,
asset_type_prefix_entry_map,
):
asset_widget = AssetWidget()
qtbot.addWidget(asset_widget)
asset_widget.set_context(beat_context)
asset_name = asset_type_prefix_entry_map[asset_type][0]
monkeypatch.setattr(QMessageBox, "critical", lambda *args: QMessageBox.Ok)
asset = Asset(test_prefix, asset_type, asset_name)
with open(asset.declaration_path, "wt") as declaration_file:
declaration_file.write("")
asset = Asset(test_prefix, asset_type, asset_name)
asset_widget.loadAsset(asset)
......@@ -355,12 +355,20 @@ class AssetWidget(QWidget):
self.maybe_save()
self.current_asset = asset
self.__clear_watcher()
self.watcher.addPath(self.current_asset.declaration_path)
self.__update_content()
is_valid, errors = asset.is_valid()
if not is_valid:
QMessageBox.critical(
self,
self.tr("Invalid asset"),
self.tr(f"The asset you are trying to load is invalid\n{errors}"),
)
else:
self.watcher.addPath(asset.declaration_path)
self.current_asset = asset
self.__update_content()
@pyqtSlot()
def saveJson(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