Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
beat
beat.editor
Commits
ed1ab044
Commit
ed1ab044
authored
May 09, 2019
by
Samuel GAIST
Browse files
[backend][assetmodel] Add deletion support to AssetType
parent
10bffb21
Changes
2
Hide whitespace changes
Inline
Side-by-side
beat/editor/backend/assetmodel.py
View file @
ed1ab044
...
...
@@ -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"""
...
...
beat/editor/test/test_models.py
View file @
ed1ab044
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment