Commit f4acc75b authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[backend][assetmodel] Add declaration_path to AssetType

This allows for an easier way to get a the path to an
asset declaration file
parent f663362b
......@@ -155,6 +155,10 @@ class AssetType(Enum):
success = common.delete_local(prefix, self.name.lower(), [name])
return success == 0
def declaration_path(self, prefix, name):
asset_folder = os.path.join(prefix, self.path)
return os.path.join(asset_folder, "{}.json".format(name))
class AssetModel(QStringListModel):
"""The asset model present a list of available asset from a given type"""
......@@ -319,7 +323,7 @@ class AssetModel(QStringListModel):
:param asset_name str: fully qualified asset name
"""
asset_path = os.path.join(self.asset_folder, "{}.json".format(asset_name))
asset_path = self.asset_type.declaration_path(self.prefix_path, asset_name)
if not os.path.exists(asset_path):
raise RuntimeError("Invalid asset {}".format(asset_name))
return asset_path
......@@ -70,9 +70,6 @@ def asset_type_prefix_entry_map():
class TestAssetWidget:
"""Test that the AssetWidget works correctly"""
def get_asset_path(self, prefix, asset_type, asset_name):
return os.path.join(prefix, asset_type.path, asset_name + ".json")
def test_matching_editor(
self, qtbot, test_prefix, beat_context, asset_type_prefix_entry_map
):
......@@ -86,9 +83,7 @@ class TestAssetWidget:
asset_type,
(asset_name, editor_type),
) in asset_type_prefix_entry_map.items():
asset_widget.load_json(
self.get_asset_path(test_prefix, asset_type, asset_name)
)
asset_widget.load_json(asset_type.declaration_path(test_prefix, asset_name))
assert isinstance(asset_widget.current_editor, editor_type)
def test_dirty(
......@@ -107,9 +102,7 @@ class TestAssetWidget:
asset_type,
(asset_name, editor_type),
) in asset_type_prefix_entry_map.items():
asset_widget.load_json(
self.get_asset_path(test_prefix, asset_type, asset_name)
)
asset_widget.load_json(asset_type.declaration_path(test_prefix, asset_name))
assert not asset_widget.current_editor.isDirty()
with qtbot.waitSignal(asset_widget.json_widget.textChanged):
......@@ -140,7 +133,7 @@ class TestAssetWidget:
asset_type,
(asset_name, editor_type),
) in asset_type_prefix_entry_map.items():
asset_path = self.get_asset_path(test_prefix, asset_type, asset_name)
asset_path = asset_type.declaration_path(test_prefix, asset_name)
asset_widget.load_json(asset_path)
with qtbot.waitSignal(asset_widget.json_widget.textChanged):
......@@ -298,7 +291,7 @@ class TestAssetWidget:
monkeypatch.setattr(QMessageBox, "question", lambda *args: QMessageBox.Yes)
asset_path = self.get_asset_path(test_prefix, asset_type, asset_name)
asset_path = asset_type.declaration_path(test_prefix, asset_name)
asset_widget.load_json(asset_path)
assert asset_widget.current_editor.asset_type != AssetType.UNKNOWN
asset_widget.deleteAsset(asset_path)
......
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