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

[AssetType[backend][assetmodel] Add support for creating new versions to AssetType

**WARNING** not all asset types have version support.
This will fail accordingly.
parent 554ab087
......@@ -108,6 +108,11 @@ class AssetType(Enum):
return self not in [self.UNKNOWN, self.EXPERIMENT]
def validate(self, data):
"""Runs the schema validation and returns whether an asset is valid
:param data str: asset content
"""
if self == self.UNKNOWN:
raise RuntimeError("Trying to validate unknown type")
return validate(self.name.lower(), data)
......@@ -124,6 +129,20 @@ class AssetType(Enum):
success = common.create(prefix, self.name.lower(), [name])
return success == 0
def create_new_version(self, prefix, name):
"""Create a new version of the asset
:param prefix str: Path to the prefix
:param name str: name of the asset
"""
if self == self.UNKNOWN:
raise RuntimeError(
"Trying to create a new version of an asset of unknown type"
)
success = common.new_version(prefix, self.name.lower(), name)
return success == 0
class AssetModel(QStringListModel):
"""The asset model present a list of available asset from a given type"""
......
......@@ -115,6 +115,19 @@ class TestAssetType:
AssetType.UNKNOWN: None,
}
existing_asset_name_map = {
AssetType.ALGORITHM: "autonomous/add/1",
AssetType.DATABASE: "simple/1",
AssetType.DATAFORMAT: "user/complexes/1",
AssetType.EXPERIMENT: "user/user/double/1/double",
AssetType.LIBRARY: "user/sum/1",
AssetType.PLOTTER: "user/scatter/1",
AssetType.PLOTTERPARAMETER: "plot/config/1",
AssetType.PROTOCOLTEMPLATE: "double/1",
AssetType.TOOLCHAIN: "user/double/1",
AssetType.UNKNOWN: None,
}
def test_unknown_validation(self):
with pytest.raises(RuntimeError):
AssetType.UNKNOWN.validate({})
......@@ -140,3 +153,13 @@ class TestAssetType:
asset_name = self.asset_name_map[uncreatable_asset_type]
with pytest.raises(RuntimeError):
uncreatable_asset_type.create_new(test_prefix, asset_name)
def test_create_new_version(self, test_prefix, creatable_asset_type):
asset_name = self.existing_asset_name_map[creatable_asset_type]
result = creatable_asset_type.create_new_version(test_prefix, asset_name)
assert result
def test_create_new_version_failure(self, test_prefix, uncreatable_asset_type):
asset_name = self.existing_asset_name_map[uncreatable_asset_type]
with pytest.raises(RuntimeError):
uncreatable_asset_type.create_new_version(test_prefix, asset_name)
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