Commit 9b1bb86d authored by Samuel GAIST's avatar Samuel GAIST Committed by Samuel GAIST
Browse files

[backend][asset] Add is_valid method

This allows to verify whether the data behind the
asset is valid.
parent 056d3563
......@@ -250,7 +250,14 @@ class Asset:
return self.type.delete(self.prefix, self.name)
def storage(self):
try:
return self.type.storage(self.prefix, self.name)
except json.errors.JSONDecodeError as e:
raise RuntimeError(f"Invalid asset content: {e}")
"""Returns the storage object for this asset"""
return self.type.storage(self.prefix, self.name)
def is_valid(self):
"""Returns whether the declaration of this asset is valid and the list
of error associated.
"""
_, error_list = self.type.validate(self.declaration_path)
return len(error_list) == 0, error_list
......@@ -212,3 +212,22 @@ class TestAsset:
asset = Asset(test_prefix, asset_type, asset_name)
storage = asset.storage()
assert isinstance(storage, asset_type.storage)
def test_is_valid(self, test_prefix, asset_type):
asset_name = existing_asset_name_map[asset_type]
asset = Asset(test_prefix, asset_type, asset_name)
valid, errors = asset.is_valid()
assert valid
assert not errors
def test_is_invalid(self, test_prefix, asset_type):
asset_name = existing_asset_name_map[asset_type]
asset = Asset(test_prefix, asset_type, asset_name)
with open(asset.declaration_path, "wt") as json_file:
json_file.write("")
valid, errors = asset.is_valid()
assert not valid
assert errors
Supports Markdown
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