Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions mpt_api_client/resources/catalog/authorizations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from mpt_api_client.http import AsyncService, Service
from mpt_api_client.http.mixins import (
AsyncCreateMixin,
AsyncDeleteMixin,
AsyncUpdateMixin,
CreateMixin,
DeleteMixin,
UpdateMixin,
)
from mpt_api_client.models import Model


class Authorization(Model):
"""Authorization resource."""


class AuthorizationsServiceConfig:
"""Authorizations service configuration."""

_endpoint = "/public/v1/catalog/authorizations"
_model_class = Authorization
_collection_key = "data"


class AuthorizationsService(
CreateMixin[Authorization],
DeleteMixin,
UpdateMixin[Authorization],
Service[Authorization],
AuthorizationsServiceConfig,
):
"""Authorizations service."""


class AsyncAuthorizationsService(
AsyncCreateMixin[Authorization],
AsyncDeleteMixin,
AsyncUpdateMixin[Authorization],
AsyncService[Authorization],
AuthorizationsServiceConfig,
):
"""Authorizations service."""
14 changes: 14 additions & 0 deletions mpt_api_client/resources/catalog/catalog.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from mpt_api_client.http import AsyncHTTPClient, HTTPClient
from mpt_api_client.resources.catalog.authorizations import (
AsyncAuthorizationsService,
AuthorizationsService,
)
from mpt_api_client.resources.catalog.items import AsyncItemsService, ItemsService
from mpt_api_client.resources.catalog.products import AsyncProductsService, ProductsService

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

@property
def authorizations(self) -> AuthorizationsService:
"""Authorizations service."""
return AuthorizationsService(http_client=self.http_client)

@property
def products(self) -> ProductsService:
"""Products service."""
Expand All @@ -26,6 +35,11 @@ class AsyncCatalog:
def __init__(self, *, http_client: AsyncHTTPClient):
self.http_client = http_client

@property
def authorizations(self) -> AsyncAuthorizationsService:
"""Authorizations service."""
return AsyncAuthorizationsService(http_client=self.http_client)

@property
def products(self) -> AsyncProductsService:
"""Products service."""
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ extend-ignore =

per-file-ignores =
mpt_api_client/rql/query_builder.py: WPS110 WPS115 WPS210 WPS214
mpt_api_client/resources/catalog/authorizations.py: WPS215
mpt_api_client/resources/catalog/products.py: WPS204 WPS214 WPS215
mpt_api_client/resources/catalog/items.py: WPS215
mpt_api_client/resources/catalog/products_item_groups.py: WPS215
Expand Down
26 changes: 26 additions & 0 deletions tests/resources/catalog/test_authorizations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest

from mpt_api_client.resources.catalog.authorizations import (
AsyncAuthorizationsService,
AuthorizationsService,
)


@pytest.fixture
def authorizations_service(http_client):
return AuthorizationsService(http_client=http_client)


@pytest.fixture
def async_authorizations_service(async_http_client):
return AsyncAuthorizationsService(http_client=async_http_client)


@pytest.mark.parametrize("method", ["get", "create", "update", "delete"])
def test_mixins_present(authorizations_service, method):
assert hasattr(authorizations_service, method)


@pytest.mark.parametrize("method", ["get", "create", "update", "delete"])
def test_async_mixins_present(async_authorizations_service, method):
assert hasattr(async_authorizations_service, method)
6 changes: 6 additions & 0 deletions tests/resources/catalog/test_catalog.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import pytest

from mpt_api_client.resources.catalog.authorizations import (
AsyncAuthorizationsService,
AuthorizationsService,
)
from mpt_api_client.resources.catalog.catalog import AsyncCatalog, Catalog
from mpt_api_client.resources.catalog.items import AsyncItemsService, ItemsService
from mpt_api_client.resources.catalog.products import AsyncProductsService, ProductsService
Expand All @@ -18,6 +22,7 @@ def async_catalog(async_http_client):
@pytest.mark.parametrize(
("property_name", "expected_service_class"),
[
("authorizations", AuthorizationsService),
("products", ProductsService),
("items", ItemsService),
],
Expand All @@ -33,6 +38,7 @@ def test_catalog_properties(catalog, property_name, expected_service_class):
@pytest.mark.parametrize(
("property_name", "expected_service_class"),
[
("authorizations", AsyncAuthorizationsService),
("products", AsyncProductsService),
("items", AsyncItemsService),
],
Expand Down