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
2 changes: 1 addition & 1 deletion mpt_api_client/http/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(
*,
base_url: str | None = None,
api_token: str | None = None,
timeout: float = 5.0,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a ticket to revert this back here:

https://softwareone.atlassian.net/browse/MPT-16150

timeout: float = 10.0,
retries: int = 5,
):
api_token = api_token or os.getenv("MPT_TOKEN")
Expand Down
2 changes: 1 addition & 1 deletion mpt_api_client/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(
*,
base_url: str | None = None,
api_token: str | None = None,
timeout: float = 5.0,
timeout: float = 10.0,
retries: int = 5,
):
api_token = api_token or os.getenv("MPT_TOKEN")
Expand Down
16 changes: 16 additions & 0 deletions mpt_api_client/resources/catalog/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
AsyncItemGroupsService,
ItemGroupsService,
)
from mpt_api_client.resources.catalog.products_items import (
AsyncProductItemService,
ProductItemService,
)
from mpt_api_client.resources.catalog.products_media import (
AsyncMediaService,
MediaService,
Expand Down Expand Up @@ -72,6 +76,12 @@ class ProductsService(
):
"""Products service."""

def items(self, product_id: str) -> ProductItemService: # noqa: WPS110
"""Return product items service."""
return ProductItemService(
http_client=self.http_client, endpoint_params={"product_id": product_id}
)

def item_groups(self, product_id: str) -> ItemGroupsService:
"""Return item_groups service."""
return ItemGroupsService(
Expand Down Expand Up @@ -129,6 +139,12 @@ class AsyncProductsService(
):
"""Products service."""

def items(self, product_id: str) -> AsyncProductItemService: # noqa: WPS110
"""Return product items service."""
return AsyncProductItemService(
http_client=self.http_client, endpoint_params={"product_id": product_id}
)

def item_groups(self, product_id: str) -> AsyncItemGroupsService:
"""Return item_groups service."""
return AsyncItemGroupsService(
Expand Down
34 changes: 34 additions & 0 deletions mpt_api_client/resources/catalog/products_items.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from mpt_api_client.http import AsyncService, Service
from mpt_api_client.http.mixins import (
AsyncCollectionMixin,
AsyncGetMixin,
CollectionMixin,
GetMixin,
)
from mpt_api_client.resources.catalog.items import Item


class ProductItemServiceConfig:
"""Product Item service configuration."""

_endpoint = "/public/v1/catalog/products/{product_id}/items"
_model_class = Item
_collection_key = "data"


class ProductItemService(
GetMixin[Item],
CollectionMixin[Item],
Service[Item],
ProductItemServiceConfig,
):
"""Product Item service."""


class AsyncProductItemService(
AsyncGetMixin[Item],
AsyncCollectionMixin[Item],
AsyncService[Item],
ProductItemServiceConfig,
):
"""Product Item service."""
4 changes: 2 additions & 2 deletions tests/unit/http/test_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_async_http_initialization(mocker):
"Authorization": "Bearer test-token",
"Accept": "application/json",
},
timeout=5.0,
timeout=10.0,
transport=mocker.ANY,
)

Expand All @@ -53,7 +53,7 @@ def test_async_env_initialization(monkeypatch, mocker):
"Authorization": f"Bearer {API_TOKEN}",
"Accept": "application/json",
},
timeout=5.0,
timeout=10.0,
transport=mocker.ANY,
)

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/http/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_http_initialization(mocker):
"User-Agent": "swo-marketplace-client/1.0",
"Authorization": "Bearer test-token",
},
timeout=5.0,
timeout=10.0,
transport=mocker.ANY,
)

Expand All @@ -41,7 +41,7 @@ def test_env_initialization(monkeypatch, mocker):
"User-Agent": "swo-marketplace-client/1.0",
"Authorization": f"Bearer {API_TOKEN}",
},
timeout=5.0,
timeout=10.0,
transport=mocker.ANY,
)

Expand Down
6 changes: 6 additions & 0 deletions tests/unit/resources/catalog/test_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
AsyncItemGroupsService,
ItemGroupsService,
)
from mpt_api_client.resources.catalog.products_items import (
AsyncProductItemService,
ProductItemService,
)
from mpt_api_client.resources.catalog.products_media import (
AsyncMediaService,
MediaService,
Expand Down Expand Up @@ -66,6 +70,7 @@ def test_async_mixins_present(async_products_service, method):
@pytest.mark.parametrize(
("service_method", "expected_service_class"),
[
("items", ProductItemService),
("item_groups", ItemGroupsService),
("parameter_groups", ParameterGroupsService),
("media", MediaService),
Expand All @@ -85,6 +90,7 @@ def test_property_services(products_service, service_method, expected_service_cl
@pytest.mark.parametrize(
("service_method", "expected_service_class"),
[
("items", AsyncProductItemService),
("item_groups", AsyncItemGroupsService),
("parameter_groups", AsyncParameterGroupsService),
("media", AsyncMediaService),
Expand Down
44 changes: 44 additions & 0 deletions tests/unit/resources/catalog/test_products_items.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import pytest

from mpt_api_client.resources.catalog.products_items import (
AsyncProductItemService,
ProductItemService,
)


@pytest.fixture
def product_items_service(http_client):
return ProductItemService(http_client=http_client, endpoint_params={"product_id": "PRD-001"})


@pytest.fixture
def async_product_items_service(async_http_client):
return AsyncProductItemService(
http_client=async_http_client, endpoint_params={"product_id": "PRD-001"}
)


def test_endpoint(product_items_service):
result = product_items_service.path == "/public/v1/catalog/products/PRD-001/items"

assert result is True


def test_async_endpoint(async_product_items_service):
result = async_product_items_service.path == "/public/v1/catalog/products/PRD-001/items"

assert result is True


@pytest.mark.parametrize("method", ["get", "iterate"])
def test_methods_present(product_items_service, method):
result = hasattr(product_items_service, method)

assert result is True


@pytest.mark.parametrize("method", ["get", "iterate"])
def test_async_methods_present(async_product_items_service, method):
result = hasattr(async_product_items_service, method)

assert result is True