Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
beat
beat.editor
Commits
8487d65c
Commit
8487d65c
authored
Jul 31, 2019
by
Samuel GAIST
Committed by
Samuel GAIST
Jul 31, 2019
Browse files
[test][assetwidget] Refactor delete tests for same and other asset type
parent
599a6e89
Pipeline
#32256
passed with stage
in 31 minutes and 42 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
beat/editor/test/test_assetwidget.py
View file @
8487d65c
...
...
@@ -25,6 +25,7 @@
import
os
import
pytest
import
random
from
PyQt5
import
QtCore
...
...
@@ -335,10 +336,47 @@ class TestAssetWidget:
assert
asset_widget
.
current_asset
==
asset
assert
os
.
path
.
exists
(
asset
.
declaration_path
)
def
__check_deletion
(
self
,
qtbot
,
beat_context
,
asset_to_edit
,
asset_to_delete
,
messagebox_answer
):
asset_widget
=
AssetWidget
()
qtbot
.
addWidget
(
asset_widget
)
asset_widget
.
set_context
(
beat_context
)
with
qtbot
.
waitSignal
(
asset_widget
.
currentAssetChanged
):
asset_widget
.
loadAsset
(
asset_to_edit
)
assert
asset_widget
.
current_editor
.
asset_type
!=
AssetType
.
UNKNOWN
asset_widget
.
deleteAsset
(
asset_to_delete
.
declaration_path
)
if
messagebox_answer
==
QMessageBox
.
Yes
:
assert
asset_widget
.
current_editor
.
asset_type
!=
AssetType
.
UNKNOWN
assert
os
.
path
.
exists
(
asset_to_edit
.
declaration_path
)
assert
not
os
.
path
.
exists
(
asset_to_delete
.
declaration_path
)
else
:
assert
asset_widget
.
current_editor
.
asset_type
!=
AssetType
.
UNKNOWN
assert
asset_widget
.
current_asset
==
asset_to_edit
assert
os
.
path
.
exists
(
asset_to_edit
.
declaration_path
)
assert
os
.
path
.
exists
(
asset_to_delete
.
declaration_path
)
def
__get_asset_name_list
(
self
,
test_prefix
,
asset_type
):
asset_model
=
AssetModel
()
asset_model
.
setLatestOnlyEnabled
(
False
)
asset_model
.
asset_type
=
asset_type
asset_model
.
prefix_path
=
test_prefix
asset_list
=
[
asset_name
for
asset_name
in
asset_model
.
stringList
()
if
"error"
not
in
asset_name
]
assert
len
(
asset_list
)
>=
2
return
asset_list
@
pytest
.
mark
.
parametrize
(
"messagebox_answer"
,
[
QMessageBox
.
Yes
,
QMessageBox
.
No
],
ids
=
[
"Yes"
,
"No"
]
)
def
test_delete_
other
_asset
(
def
test_delete_
same
_asset
_type
(
self
,
qtbot
,
monkeypatch
,
...
...
@@ -348,41 +386,72 @@ class TestAssetWidget:
asset_type_prefix_entry_map
,
messagebox_answer
,
):
asset_widget
=
AssetWidget
()
qtbot
.
addWidget
(
asset_widget
)
asset_widget
.
set_context
(
beat_context
)
monkeypatch
.
setattr
(
QMessageBox
,
"question"
,
lambda
*
args
:
messagebox_answer
)
asset_model
=
AssetModel
()
asset_model
.
setLatestOnlyEnabled
(
False
)
asset_model
.
asset_type
=
asset_type
asset_model
.
prefix_path
=
test_prefix
asset_list
=
asset_model
.
stringList
()
asset_name_list
=
self
.
__get_asset_name_list
(
test_prefix
,
asset_type
)
assert
len
(
asset_list
)
>=
2
# Using lasts assets in the list because of dataformats basetypes
asset_name_to_edit
=
asset_list
[
-
1
]
asset_name_to_delete
=
asset_list
[
-
2
]
if
asset_type
==
AssetType
.
DATAFORMAT
:
# Using lasts assets in the list because of dataformats basetypes
asset_name_to_edit
=
asset_name_list
[
-
1
]
asset_name_to_delete
=
asset_name_list
[
-
2
]
else
:
asset_name_to_edit
=
asset_name_list
[
0
]
asset_name_to_delete
=
asset_name_list
[
1
]
asset_to_edit
=
Asset
(
test_prefix
,
asset_type
,
asset_name_to_edit
)
asset_to_delete
=
Asset
(
test_prefix
,
asset_type
,
asset_name_to_delete
)
with
qtbot
.
waitSignal
(
asset_widget
.
currentAssetChanged
):
asset_widget
.
loadAsset
(
asset_to_edit
)
assert
asset_widget
.
current_editor
.
asset_type
!=
AssetType
.
UNKNOWN
self
.
__check_deletion
(
qtbot
,
beat_context
,
asset_to_edit
,
asset_to_delete
,
messagebox_answer
)
asset_widget
.
deleteAsset
(
asset_to_delete
.
declaration_path
)
if
messagebox_answer
==
QMessageBox
.
Yes
:
assert
asset_widget
.
current_editor
.
asset_type
!=
AssetType
.
UNKNOWN
assert
os
.
path
.
exists
(
asset_to_edit
.
declaration_path
)
assert
not
os
.
path
.
exists
(
asset_to_delete
.
declaration_path
)
else
:
assert
asset_widget
.
current_editor
.
asset_type
!=
AssetType
.
UNKNOWN
assert
asset_widget
.
current_asset
==
asset_to_edit
assert
os
.
path
.
exists
(
asset_to_edit
.
declaration_path
)
assert
os
.
path
.
exists
(
asset_to_delete
.
declaration_path
)
@
pytest
.
mark
.
parametrize
(
"messagebox_answer"
,
[
QMessageBox
.
Yes
,
QMessageBox
.
No
],
ids
=
[
"Yes"
,
"No"
]
)
def
test_delete_other_asset_type
(
self
,
qtbot
,
monkeypatch
,
test_prefix
,
beat_context
,
asset_type
,
asset_type_prefix_entry_map
,
messagebox_answer
,
):
monkeypatch
.
setattr
(
QMessageBox
,
"question"
,
lambda
*
args
:
messagebox_answer
)
asset_name_list
=
self
.
__get_asset_name_list
(
test_prefix
,
asset_type
)
index
=
0
if
asset_type
==
AssetType
.
DATAFORMAT
:
# Using lasts assets in the list because of dataformats basetypes
index
=
-
1
asset_name_to_edit
=
asset_name_list
[
index
]
asset_to_delete_type
=
random
.
choice
(
[
asset
for
asset
in
AssetType
if
asset
not
in
[
asset_type
,
AssetType
.
UNKNOWN
]
]
)
asset_to_delete_name_list
=
self
.
__get_asset_name_list
(
test_prefix
,
asset_to_delete_type
)
index
=
0
if
asset_to_delete_type
==
AssetType
.
DATAFORMAT
:
# Using lasts assets in the list because of dataformats basetypes
index
=
-
1
asset_name_to_delete
=
asset_to_delete_name_list
[
index
]
asset_to_edit
=
Asset
(
test_prefix
,
asset_type
,
asset_name_to_edit
)
asset_to_delete
=
Asset
(
test_prefix
,
asset_to_delete_type
,
asset_name_to_delete
)
self
.
__check_deletion
(
qtbot
,
beat_context
,
asset_to_edit
,
asset_to_delete
,
messagebox_answer
)
def
test_load_empty_json
(
self
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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