Commit 7abcabfa authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[backend][asset] Implement declaration read/write as property

parent e54b8429
......@@ -24,6 +24,7 @@
###############################################################################
import importlib
import simplejson as json
import beat.core
......@@ -207,6 +208,22 @@ class Asset:
storage = self.type.storage(self.prefix, self.name)
return storage.json.path
@property
def declaration(self):
"""Returns the JSON content loaded from the file"""
with open(self.declaration_path, "rt") as json_file:
return json.load(json_file)
@declaration.setter
def declaration(self, declaration):
with open(self.declaration_path, "wt") as json_file:
json_file.write(
json.dumps(
declaration, sort_keys=True, indent=4, cls=utils.NumpyJSONEncoder
)
)
@property
def documentation_path(self):
"""Returns the full path to the documentation file"""
......
......@@ -26,6 +26,7 @@
import os
import pytest
import shutil
import simplejson as json
import tempfile
from ..backend.asset import Asset
......@@ -194,3 +195,22 @@ class TestAsset:
asset = Asset(tmp_prefix, asset_type, asset_name)
result = asset.delete()
assert result
def test_declaration_property(self, test_prefix, asset_type):
asset_name = self.existing_asset_name_map[asset_type]
asset = Asset(test_prefix, asset_type, asset_name)
declaration = asset.declaration
with open(asset.declaration_path, "rt") as json_file:
file_content = json.load(json_file)
assert declaration == file_content
if asset_type is not AssetType.DATAFORMAT:
declaration["description"] = "New description"
else:
declaration["#description"] = "New description"
asset.declaration = declaration
with open(asset.declaration_path, "rt") as json_file:
file_content = json.load(json_file)
assert declaration == file_content
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