Commit d0adcf6c authored by Samuel GAIST's avatar Samuel GAIST

[test][assetwidget] Test loading of "empty" JSON

Empty as in minimal "{}"

Algorithm are a special case since without api version
an additional question is asked therefore the test
provides that in the JSON
parent 7dc739b1
......@@ -481,7 +481,7 @@ class TestAssetWidget:
qtbot, beat_context, asset_to_edit, asset_to_delete, messagebox_answer
)
def test_load_empty_json(
def test_cancel_load_empty_json(
self,
qtbot,
monkeypatch,
......@@ -495,7 +495,9 @@ class TestAssetWidget:
asset_widget.set_context(beat_context)
asset_name = asset_type_prefix_entry_map[asset_type][0]
monkeypatch.setattr(QMessageBox, "critical", lambda *args: QMessageBox.Ok)
monkeypatch.setattr(
AssetWidget, "confirm_loading", lambda *args: QMessageBox.Cancel
)
asset = Asset(test_prefix, asset_type, asset_name)
with open(asset.declaration_path, "wt") as declaration_file:
......@@ -504,6 +506,36 @@ class TestAssetWidget:
with qtbot.assertNotEmitted(asset_widget.currentAssetChanged):
asset_widget.loadAsset(asset)
def test_allow_load_invalid_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(
AssetWidget, "confirm_loading", lambda *args: QMessageBox.Ignore
)
monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.Ok)
asset = Asset(test_prefix, asset_type, asset_name)
with open(asset.declaration_path, "wt") as declaration_file:
json_data = (
'{"api_version": 2}' if asset_type == AssetType.ALGORITHM else "{}"
)
declaration_file.write(json_data)
with qtbot.waitSignal(asset_widget.currentAssetChanged):
# import ipdb; ipdb.set_trace()
asset_widget.loadAsset(asset)
def test_change_on_disk(
self,
qtbot,
......
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