Skip to content
Snippets Groups Projects
Commit c5cff909 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[backend][assetmodel] Add json_path method to AssetModel

This method will return the full path to the json file for
a given asset name.
parent 67656662
No related branches found
No related tags found
1 merge request!71Implement ProtocolTemplateEditor
......@@ -247,3 +247,14 @@ class AssetModel(QStringListModel):
"""Returns the folder matching this model asset type"""
return os.path.join(self.prefix_path, AssetType.path(self.asset_type))
def json_path(self, asset_name):
"""Returns the full path to the json file matching the asset given
:param asset_name str: fully qualified asset name
"""
asset_path = os.path.join(self.asset_folder, "{}.json".format(asset_name))
if not os.path.exists(asset_path):
raise RuntimeError("Invalid asset {}".format(asset_name))
return asset_path
......@@ -34,21 +34,25 @@ def asset_type(request):
return request.param
class TestAssetModel:
"""Test that the mock editor works correctly"""
def create_model(qtbot, test_prefix, asset_type):
model = AssetModel()
def test_model_load(self, qtbot, test_prefix, asset_type):
model = AssetModel()
with qtbot.waitSignals(
[model.assetTypeChanged, model.prefixPathChanged]
) as blocker:
model.asset_type = asset_type
model.prefix_path = test_prefix
assert blocker.all_signals_and_args[0].args[0] == asset_type
assert blocker.all_signals_and_args[1].args[0] == test_prefix
return model
with qtbot.waitSignals(
[model.assetTypeChanged, model.prefixPathChanged]
) as blocker:
model.asset_type = asset_type
model.prefix_path = test_prefix
assert blocker.all_signals_and_args[0].args[0] == asset_type
assert blocker.all_signals_and_args[1].args[0] == test_prefix
class TestAssetModel:
"""Test that the mock editor works correctly"""
def test_model_load(self, qtbot, test_prefix, asset_type):
model = create_model(qtbot, test_prefix, asset_type)
asset_list = model.stringList()
assert len(asset_list) > 0
......@@ -66,6 +70,24 @@ class TestAssetModel:
for item in asset_list:
assert len(item.split("/")) == split_size
def test_json_path(self, qtbot, test_prefix, asset_type):
model = create_model(qtbot, test_prefix, asset_type)
asset_list = model.stringList()
assert len(asset_list) > 0
if asset_type == AssetType.DATAFORMAT:
basetypes = dataformat_basetypes()
asset_list = [item for item in asset_list if item not in basetypes]
for item in asset_list:
path = model.json_path(item)
assert path
def test_json_path_invalid_asset(self, qtbot, test_prefix, asset_type):
model = create_model(qtbot, test_prefix, asset_type)
with pytest.raises(RuntimeError):
model.json_path("invalid")
class TestAssetType:
"""Test the asset type enum"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment