Commit 056d3563 authored by Samuel GAIST's avatar Samuel GAIST Committed by Samuel GAIST
Browse files

[backend][asset] Factor out storage creation in own method

parent 3becc696
......@@ -205,8 +205,7 @@ class Asset:
if self.type == AssetType.UNKNOWN:
raise RuntimeError("Trying to get declaration of unknown type")
storage = self.type.storage(self.prefix, self.name)
return storage.json.path
return self.storage().json.path
@property
def declaration(self):
......@@ -231,8 +230,7 @@ class Asset:
if self.type == AssetType.UNKNOWN:
raise RuntimeError("Trying to get documentation of unknown type")
storage = self.type.storage(self.prefix, self.name)
return storage.doc.path
return self.storage().doc.path
@property
def code_path(self):
......@@ -244,10 +242,15 @@ class Asset:
if not self.type.has_code():
return None
storage = self.type.storage(self.prefix, self.name)
return storage.code.path
return self.storage().code.path
def delete(self):
"""Deletes the asset pointed to by this object"""
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}")
......@@ -206,3 +206,9 @@ class TestAsset:
with open(asset.declaration_path, "rt") as json_file:
file_content = json.load(json_file)
assert declaration == file_content
def test_storage(self, test_prefix, asset_type):
asset_name = existing_asset_name_map[asset_type]
asset = Asset(test_prefix, asset_type, asset_name)
storage = asset.storage()
assert isinstance(storage, asset_type.storage)
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