mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 05:14:40 +01:00
OP-3682 - updated AddonSource
This commit is contained in:
parent
8a21fdfcf2
commit
0fb1b9be93
2 changed files with 35 additions and 6 deletions
|
|
@ -32,21 +32,50 @@ class MultiPlatformPath(object):
|
|||
@attr.s
|
||||
class AddonSource(object):
|
||||
type = attr.ib()
|
||||
url = attr.ib(default=None)
|
||||
|
||||
|
||||
@attr.s
|
||||
class LocalAddonSource(AddonSource):
|
||||
path = attr.ib(default=attr.Factory(MultiPlatformPath))
|
||||
|
||||
|
||||
@attr.s
|
||||
class WebAddonSource(AddonSource):
|
||||
url = attr.ib(default=None)
|
||||
|
||||
|
||||
@attr.s
|
||||
class AddonInfo(object):
|
||||
"""Object matching json payload from Server"""
|
||||
name = attr.ib()
|
||||
version = attr.ib()
|
||||
sources = attr.ib(default=attr.Factory(list), type=AddonSource)
|
||||
sources = attr.ib(default=attr.Factory(list))
|
||||
hash = attr.ib(default=None)
|
||||
description = attr.ib(default=None)
|
||||
license = attr.ib(default=None)
|
||||
authors = attr.ib(default=None)
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data):
|
||||
sources = []
|
||||
for source in data.get("sources", []):
|
||||
if source.get("type") == UrlType.FILESYSTEM.value:
|
||||
source_addon = LocalAddonSource(type=source["type"],
|
||||
path=source["path"])
|
||||
if source.get("type") == UrlType.HTTP.value:
|
||||
source_addon = WebAddonSource(type=source["type"],
|
||||
url=source["url"])
|
||||
|
||||
sources.append(source_addon)
|
||||
|
||||
return cls(name=data.get("name"),
|
||||
version=data.get("version"),
|
||||
hash=data.get("hash"),
|
||||
description=data.get("description"),
|
||||
sources=sources,
|
||||
license=data.get("license"),
|
||||
authors=data.get("authors"))
|
||||
|
||||
|
||||
class AddonDownloader:
|
||||
log = logging.getLogger(__name__)
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ def test_get_downloader(printer, addon_downloader):
|
|||
def test_addon_info(printer, sample_addon_info):
|
||||
valid_minimum = {"name": "openpype_slack", "version": "1.0.0"}
|
||||
|
||||
assert AddonInfo(**valid_minimum), "Missing required fields"
|
||||
assert AddonInfo.from_dict(valid_minimum), "Missing required fields"
|
||||
assert AddonInfo(name=valid_minimum["name"],
|
||||
version=valid_minimum["version"]), \
|
||||
"Missing required fields"
|
||||
|
|
@ -84,7 +84,7 @@ def test_addon_info(printer, sample_addon_info):
|
|||
# TODO should be probably implemented
|
||||
assert AddonInfo(valid_minimum), "Wrong argument format"
|
||||
|
||||
addon = AddonInfo(**sample_addon_info)
|
||||
addon = AddonInfo.from_dict(sample_addon_info)
|
||||
assert addon, "Should be created"
|
||||
assert addon.name == "openpype_slack", "Incorrect name"
|
||||
assert addon.version == "1.0.0", "Incorrect version"
|
||||
|
|
@ -95,10 +95,10 @@ def test_addon_info(printer, sample_addon_info):
|
|||
addon_as_dict = attr.asdict(addon)
|
||||
assert addon_as_dict["name"], "Dict approach should work"
|
||||
|
||||
with pytest.raises(AttributeError):
|
||||
with pytest.raises(TypeError):
|
||||
# TODO should be probably implemented as . not dict
|
||||
first_source = addon.sources[0]
|
||||
assert first_source.type == "http", "Not implemented"
|
||||
assert first_source["type"] == "http", "Not implemented"
|
||||
|
||||
|
||||
def test_update_addon_state(printer, sample_addon_info,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue