Commit 4bd0bdfd authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[backend][assetmodel] Add validate function to AssetType

This will allow to more easily execute validation.
parent ed9ab54f
......@@ -32,6 +32,8 @@ from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import pyqtProperty
from PyQt5.QtCore import QStringListModel
from beat.core.schema import validate
from ..utils import dataformat_basetypes
......@@ -94,6 +96,11 @@ class AssetType(Enum):
else:
raise RuntimeError("Unknown asset path {}".format(path))
def validate(self, data):
if self == self.UNKNOWN:
raise RuntimeError("Trying to validate unknown type")
return validate(self.name.lower(), data)
class AssetModel(QStringListModel):
"""The asset model present a list of available asset from a given type"""
......
......@@ -23,6 +23,8 @@
# #
###############################################################################
import pytest
from ..backend.assetmodel import AssetModel, AssetType
from ..utils import dataformat_basetypes
......@@ -65,3 +67,12 @@ class TestAssetModel:
for item in asset_list:
assert len(item.split("/")) == 5
class TestAssetType:
"""Test the asset type enum"""
def test_unknown_validation(self):
unknown = AssetType.UNKNOWN
with pytest.raises(RuntimeError):
unknown.validate({})
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