Skip to content

Commit 69fd16a

Browse files
authored
MPT-13327 Add catalog authorizations (#40)
2 parents 6006c7b + eea4c30 commit 69fd16a

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from mpt_api_client.http import AsyncService, Service
2+
from mpt_api_client.http.mixins import (
3+
AsyncCreateMixin,
4+
AsyncDeleteMixin,
5+
AsyncUpdateMixin,
6+
CreateMixin,
7+
DeleteMixin,
8+
UpdateMixin,
9+
)
10+
from mpt_api_client.models import Model
11+
12+
13+
class Authorization(Model):
14+
"""Authorization resource."""
15+
16+
17+
class AuthorizationsServiceConfig:
18+
"""Authorizations service configuration."""
19+
20+
_endpoint = "/public/v1/catalog/authorizations"
21+
_model_class = Authorization
22+
_collection_key = "data"
23+
24+
25+
class AuthorizationsService(
26+
CreateMixin[Authorization],
27+
DeleteMixin,
28+
UpdateMixin[Authorization],
29+
Service[Authorization],
30+
AuthorizationsServiceConfig,
31+
):
32+
"""Authorizations service."""
33+
34+
35+
class AsyncAuthorizationsService(
36+
AsyncCreateMixin[Authorization],
37+
AsyncDeleteMixin,
38+
AsyncUpdateMixin[Authorization],
39+
AsyncService[Authorization],
40+
AuthorizationsServiceConfig,
41+
):
42+
"""Authorizations service."""

mpt_api_client/resources/catalog/catalog.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
from mpt_api_client.http import AsyncHTTPClient, HTTPClient
2+
from mpt_api_client.resources.catalog.authorizations import (
3+
AsyncAuthorizationsService,
4+
AuthorizationsService,
5+
)
26
from mpt_api_client.resources.catalog.items import AsyncItemsService, ItemsService
37
from mpt_api_client.resources.catalog.products import AsyncProductsService, ProductsService
48

@@ -9,6 +13,11 @@ class Catalog:
913
def __init__(self, *, http_client: HTTPClient):
1014
self.http_client = http_client
1115

16+
@property
17+
def authorizations(self) -> AuthorizationsService:
18+
"""Authorizations service."""
19+
return AuthorizationsService(http_client=self.http_client)
20+
1221
@property
1322
def products(self) -> ProductsService:
1423
"""Products service."""
@@ -26,6 +35,11 @@ class AsyncCatalog:
2635
def __init__(self, *, http_client: AsyncHTTPClient):
2736
self.http_client = http_client
2837

38+
@property
39+
def authorizations(self) -> AsyncAuthorizationsService:
40+
"""Authorizations service."""
41+
return AsyncAuthorizationsService(http_client=self.http_client)
42+
2943
@property
3044
def products(self) -> AsyncProductsService:
3145
"""Products service."""

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ extend-ignore =
3333

3434
per-file-ignores =
3535
mpt_api_client/rql/query_builder.py: WPS110 WPS115 WPS210 WPS214
36+
mpt_api_client/resources/catalog/authorizations.py: WPS215
3637
mpt_api_client/resources/catalog/products.py: WPS204 WPS214 WPS215
3738
mpt_api_client/resources/catalog/items.py: WPS215
3839
mpt_api_client/resources/catalog/products_item_groups.py: WPS215
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import pytest
2+
3+
from mpt_api_client.resources.catalog.authorizations import (
4+
AsyncAuthorizationsService,
5+
AuthorizationsService,
6+
)
7+
8+
9+
@pytest.fixture
10+
def authorizations_service(http_client):
11+
return AuthorizationsService(http_client=http_client)
12+
13+
14+
@pytest.fixture
15+
def async_authorizations_service(async_http_client):
16+
return AsyncAuthorizationsService(http_client=async_http_client)
17+
18+
19+
@pytest.mark.parametrize("method", ["get", "create", "update", "delete"])
20+
def test_mixins_present(authorizations_service, method):
21+
assert hasattr(authorizations_service, method)
22+
23+
24+
@pytest.mark.parametrize("method", ["get", "create", "update", "delete"])
25+
def test_async_mixins_present(async_authorizations_service, method):
26+
assert hasattr(async_authorizations_service, method)

tests/resources/catalog/test_catalog.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import pytest
22

3+
from mpt_api_client.resources.catalog.authorizations import (
4+
AsyncAuthorizationsService,
5+
AuthorizationsService,
6+
)
37
from mpt_api_client.resources.catalog.catalog import AsyncCatalog, Catalog
48
from mpt_api_client.resources.catalog.items import AsyncItemsService, ItemsService
59
from mpt_api_client.resources.catalog.products import AsyncProductsService, ProductsService
@@ -18,6 +22,7 @@ def async_catalog(async_http_client):
1822
@pytest.mark.parametrize(
1923
("property_name", "expected_service_class"),
2024
[
25+
("authorizations", AuthorizationsService),
2126
("products", ProductsService),
2227
("items", ItemsService),
2328
],
@@ -33,6 +38,7 @@ def test_catalog_properties(catalog, property_name, expected_service_class):
3338
@pytest.mark.parametrize(
3439
("property_name", "expected_service_class"),
3540
[
41+
("authorizations", AsyncAuthorizationsService),
3642
("products", AsyncProductsService),
3743
("items", AsyncItemsService),
3844
],

0 commit comments

Comments
 (0)