Skip to content

Commit 2105634

Browse files
committed
release
1 parent adc2b3f commit 2105634

File tree

8 files changed

+54
-26
lines changed

8 files changed

+54
-26
lines changed

metablock/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from .spaces import Block, Service, Space, SpaceExtension
66
from .user import User
77

8-
__version__ = "0.6.0"
8+
__version__ = "0.6.1"
99

1010
__all__ = [
1111
"Metablock",

metablock/components.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ def name(self) -> str:
110110
def url(self) -> str:
111111
return "%s/%s" % (self.root.url, self.id)
112112

113-
async def execute(self, url: str | URL, **params: Any) -> Any:
114-
return await self.cli.execute(url, **params)
113+
async def execute(self, url: str | URL, **kwargs: Any) -> Any:
114+
return await self.cli.execute(url, **kwargs)
115115

116116
def nice(self) -> str:
117117
return json.dumps(self.data, indent=4)
@@ -188,19 +188,20 @@ async def paginate(self, **params: Any) -> AsyncIterator[MetablockEntity]:
188188
for d in data["data"]:
189189
yield self.wrap(d)
190190

191-
async def get_list(self, **params: Any) -> list[MetablockEntity]:
191+
async def get_list(self, **kwargs: Any) -> list[MetablockEntity]:
192192
url = self.list_create_url()
193+
kwargs.setdefault("wrap", self.wrap_list)
193194
return cast(
194195
list[MetablockEntity],
195-
await self.execute(url, params=as_params(**params), wrap=self.wrap_list),
196+
await self.execute(url, **kwargs),
196197
)
197198

198-
async def get_full_list(self, **params: Any) -> list[MetablockEntity]:
199-
return [d async for d in self.paginate(**params)]
199+
async def get_full_list(self, **kwargs: Any) -> list[MetablockEntity]:
200+
return [d async for d in self.paginate(**kwargs)]
200201

201202
async def get(self, id_: str, **kwargs: Any) -> MetablockEntity: # type: ignore
202203
url = f"{self.url}/{id_}"
203-
kwargs.update(wrap=self.wrap)
204+
kwargs.setdefault("wrap", self.wrap)
204205
return cast(MetablockEntity, await self.execute(url, **kwargs))
205206

206207
async def has(self, id_: str, **kwargs: Any) -> bool:

metablock/extensions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List
1+
from typing import Any
22

33
from .components import CrudComponent, MetablockEntity
44
from .spaces import BlockPlugin
@@ -19,8 +19,8 @@ class Extensions(CrudComponent):
1919
class Plugin(MetablockEntity):
2020
"""Object representing an Plugin"""
2121

22-
async def blocks(self) -> List[BlockPlugin]:
23-
return await self.get(f"{self.url}/services")
22+
async def blocks(self, **kwargs: Any) -> list[BlockPlugin]:
23+
return await self.get(f"{self.url}/services", **kwargs)
2424

2525

2626
class Plugins(CrudComponent):

metablock/user.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,29 @@ class User(MetablockEntity):
1111
def url(self) -> str:
1212
return f"{self.root.url}/user"
1313

14-
async def orgs(self) -> list[Org]:
14+
async def orgs(self, **kwargs: Any) -> list[Org]:
1515
"""List user organizations"""
1616
orgs = Orgs(self.root)
17-
return await self.cli.get(
18-
f"{self.url}/orgs", wrap=lambda dl: [Org(orgs, d) for d in dl]
19-
)
17+
kwargs.setdefault("wrap", lambda dl: [Org(orgs, d) for d in dl])
18+
return await self.cli.get(f"{self.url}/orgs", **kwargs)
2019

2120
async def get_permissions(self, **kwargs: Any) -> list[dict]:
2221
"""List user permissions"""
2322
return await self.cli.get(f"{self.url}/permissions", **kwargs)
2423

25-
async def tokens(self) -> list[dict]:
26-
return await self.cli.get(f"{self.url}/tokens")
24+
async def tokens(self, **kwargs: Any) -> list[dict]:
25+
return await self.cli.get(f"{self.url}/tokens", **kwargs)
2726

28-
async def create_token(self) -> dict:
29-
return await self.cli.post(f"{self.url}/tokens")
27+
async def create_token(self, **kwargs: Any) -> dict:
28+
return await self.cli.post(f"{self.url}/tokens", **kwargs)
3029

31-
async def delete_token(self, token_id: str) -> dict:
32-
return await self.cli.delete(f"{self.url}/tokens/{token_id}")
30+
async def delete_token(self, token_id: str, **kwargs: Any) -> dict:
31+
return await self.cli.delete(f"{self.url}/tokens/{token_id}", **kwargs)
3332

34-
async def check_password(self, password: str) -> bool:
33+
async def check_password(self, password: str, **kwargs: Any) -> bool:
3534
try:
3635
return await self.root.post(
37-
f"{self.url}/password", json=dict(password=password)
36+
f"{self.url}/password", json=dict(password=password), **kwargs
3837
)
3938
except MetablockResponseError as exc:
4039
if exc.status == 401:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "metablock"
3-
version = "0.6.0"
3+
version = "0.6.1"
44
description = "Metablock cloud python client"
55
authors = ["Luca <luca@quantmind.com>"]
66
license = "BSD"

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@ def event_loop():
1818
async def cli():
1919
async with Metablock() as cli:
2020
yield cli
21+
22+
23+
@pytest.fixture
24+
def invalid_headers(cli):
25+
return {cli.auth_key_name: "invalid"}

tests/test_cli.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from metablock import Metablock
1+
import pytest
2+
from metablock import Metablock, MetablockResponseError
23

34

45
def test_cli(cli: Metablock):
@@ -9,6 +10,21 @@ def test_cli(cli: Metablock):
910
async def test_user(cli: Metablock):
1011
user = await cli.get_user()
1112
assert user.id
13+
orgs = await user.orgs()
14+
assert orgs
15+
16+
17+
async def test_user_403(cli: Metablock, invalid_headers: dict):
18+
with pytest.raises(MetablockResponseError) as exc:
19+
await cli.get_user(headers=invalid_headers)
20+
assert exc.value.status == 403
21+
22+
23+
async def test_orgs_403(cli: Metablock, invalid_headers: dict):
24+
user = await cli.get_user()
25+
with pytest.raises(MetablockResponseError) as exc:
26+
await user.orgs(headers=invalid_headers)
27+
assert exc.value.status == 403
1228

1329

1430
async def test_space(cli: Metablock):

tests/test_spaces.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
from metablock import Metablock
1+
import pytest
2+
from metablock import Metablock, MetablockResponseError
23

34

45
async def test_list_spaces(cli: Metablock) -> None:
56
spaces = await cli.spaces.get_list()
67
assert spaces
8+
9+
10+
async def test_get_space_403(cli: Metablock, invalid_headers: dict) -> None:
11+
with pytest.raises(MetablockResponseError) as exc:
12+
await cli.spaces.get_list(headers=invalid_headers)
13+
assert exc.value.status == 403

0 commit comments

Comments
 (0)