Commit 88561d0b authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[AssetType[backend][assetmodel] Add support for forking to AssetType

**WARNING** not all asset types can be forked.
This will fail accordingly.
parent e671d2e5
......@@ -107,6 +107,11 @@ class AssetType(Enum):
return self not in [self.UNKNOWN, self.EXPERIMENT]
def can_fork(self):
"""Returns whether a new asset can be forked"""
return self not in [self.UNKNOWN, self.DATABASE, self.PROTOCOLTEMPLATE]
def validate(self, data):
"""Runs the schema validation and returns whether an asset is valid
......@@ -143,6 +148,19 @@ class AssetType(Enum):
success = common.new_version(prefix,, name)
return success == 0
def fork(self, prefix, source, destination):
"""Fork an asset
:param prefix str: Path to the prefix
:param source str: name of the original asset
:param destination str: name of the new asset
if self == self.UNKNOWN:
raise RuntimeError("Trying to fork an asset of unknown type")
success = common.fork(prefix,, source, destination)
return success == 0
class AssetModel(QStringListModel):
"""The asset model present a list of available asset from a given type"""
......@@ -44,6 +44,16 @@ def uncreatable_asset_type(request):
return request.param
@pytest.fixture(params=[item for item in AssetType if item.can_fork()])
def forkable_asset_type(request):
return request.param
@pytest.fixture(params=[item for item in AssetType if not item.can_fork()])
def unforkable_asset_type(request):
return request.param
def create_model(qtbot, test_prefix, asset_type):
model = AssetModel()
......@@ -163,3 +173,17 @@ class TestAssetType:
asset_name = self.existing_asset_name_map[uncreatable_asset_type]
with pytest.raises(RuntimeError):
uncreatable_asset_type.create_new_version(test_prefix, asset_name)
def test_fork(self, test_prefix, forkable_asset_type):
source_asset_name = self.existing_asset_name_map[forkable_asset_type]
dest_asset_name = self.asset_name_map[forkable_asset_type]
result = forkable_asset_type.fork(
test_prefix, source_asset_name, dest_asset_name
assert result
def test_fork_failure(self, test_prefix, unforkable_asset_type):
source_asset_name = self.existing_asset_name_map[unforkable_asset_type]
dest_asset_name = self.asset_name_map[unforkable_asset_type]
with pytest.raises(RuntimeError):
unforkable_asset_type.fork(test_prefix, source_asset_name, dest_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