Commit 66c1bcaf authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[backend][assetmodel] Moved dataformat base types discovery in own function

Updated tests
parent 2e231f2e
......@@ -24,8 +24,6 @@
###############################################################################
import os
import simplejson as json
import pkg_resources
from enum import Enum, unique
......@@ -34,6 +32,8 @@ from PyQt5.QtCore import pyqtSlot
from PyQt5.QtCore import pyqtProperty
from PyQt5.QtCore import QStringListModel
from ..utils import dataformat_basetypes
@unique
class AssetType(Enum):
......@@ -160,14 +160,7 @@ class AssetModel(QStringListModel):
latest_assets_list = sorted(latest_assets_list)
if self.asset_type == AssetType.DATAFORMAT:
# Load basetypes
common_data = pkg_resources.resource_string(
"beat.core", "schema/common/1.json"
)
common_data = json.loads(common_data)
basetypes = common_data["definitions"]["basetype"]["enum"]
print(basetypes)
latest_assets_list = basetypes + latest_assets_list
latest_assets_list = dataformat_basetypes() + latest_assets_list
self.setStringList(latest_assets_list)
......
......@@ -24,6 +24,7 @@
###############################################################################
from ..backend.assetmodel import AssetModel, AssetType
from ..utils import dataformat_basetypes
class TestAssetModel:
......@@ -43,8 +44,9 @@ class TestAssetModel:
assert blocker.all_signals_and_args[1].args[0] == test_prefix
asset_list = model.stringList()
basetypes = dataformat_basetypes()
for item in asset_list:
assert len(item.split("/")) == 3
assert len(item.split("/")) == 3 or item in basetypes
def test_experiment_model_load(self, qtbot, test_prefix):
model = AssetModel()
......
......@@ -32,6 +32,8 @@ Helper methods and utilities
import os
import sys
import logging
import simplejson as json
import pkg_resources
import jinja2
......@@ -252,3 +254,11 @@ def frozen(cls):
cls.__init__ = init_decorator(cls.__init__)
return cls
def dataformat_basetypes():
"""Returns the list of base types that can be used for dataformat"""
common_data = pkg_resources.resource_string("beat.core", "schema/common/1.json")
common_data = json.loads(common_data)
return common_data["definitions"]["basetype"]["enum"]
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