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

[backend][assetmodel] Add deletion support to AssetType

parent 10bffb21
......@@ -173,6 +173,18 @@ class AssetType(Enum):
success = common.fork(prefix, self.name.lower(), source, destination)
return success == 0
def delete(self, prefix, name):
"""Delete an asset
:param prefix str: Path to the prefix
:param name str: name of the asset to delete
"""
if self == self.UNKNOWN:
raise RuntimeError("Trying to delete an asset of unknown type")
success = common.delete_local(prefix, self.name.lower(), [name])
return success == 0
class AssetModel(QStringListModel):
"""The asset model present a list of available asset from a given type"""
......
......@@ -23,7 +23,10 @@
# #
###############################################################################
import os
import pytest
import tempfile
import shutil
from ..backend.assetmodel import AssetModel, AssetType
from ..utils import dataformat_basetypes
......@@ -149,6 +152,10 @@ class TestAssetType:
with pytest.raises(RuntimeError):
AssetType.UNKNOWN.fork("foo", "bar", "baz")
def test_unknown_delete(self):
with pytest.raises(RuntimeError):
AssetType.UNKNOWN.delete("foo", "bar")
def test_creation(self, test_prefix, creatable_asset_type):
asset_name = self.asset_name_map[creatable_asset_type]
result = creatable_asset_type.create_new(test_prefix, asset_name)
......@@ -182,3 +189,11 @@ class TestAssetType:
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)
def test_delete(self, test_prefix, asset_type):
with tempfile.TemporaryDirectory(suffix=".prefix") as prefix:
tmp_prefix = os.path.join(prefix, "prefix")
shutil.copytree(test_prefix, tmp_prefix)
asset_name = self.existing_asset_name_map[asset_type]
result = asset_type.delete(tmp_prefix, asset_name)
assert result
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