-
Notifications
You must be signed in to change notification settings - Fork 0
[MPT-16142] Added commerce assets endpoints #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
robcsegal
merged 1 commit into
main
from
MPT-16142-add-missing-assets-endpoints-to-commerce
Dec 4, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| from mpt_api_client.http import AsyncService, Service | ||
| from mpt_api_client.http.mixins import ( | ||
| AsyncCollectionMixin, | ||
| AsyncCreateMixin, | ||
| AsyncGetMixin, | ||
| AsyncUpdateMixin, | ||
| CollectionMixin, | ||
| CreateMixin, | ||
| GetMixin, | ||
| UpdateMixin, | ||
| ) | ||
| from mpt_api_client.models import Model | ||
| from mpt_api_client.models.model import ResourceData | ||
|
|
||
|
|
||
| class Asset(Model): | ||
| """Asset resource.""" | ||
|
|
||
|
|
||
| class AssetTemplate(Model): | ||
| """Asset template resource.""" | ||
|
|
||
|
|
||
| class AssetsServiceConfig: | ||
| """Assets service config.""" | ||
|
|
||
| _endpoint = "/public/v1/commerce/assets" | ||
| _model_class = Asset | ||
| _collection_key = "data" | ||
|
|
||
|
|
||
| class AssetsService( | ||
| CreateMixin[Asset], | ||
| UpdateMixin[Asset], | ||
| GetMixin[Asset], | ||
| CollectionMixin[Asset], | ||
| Service[Asset], | ||
| AssetsServiceConfig, | ||
| ): | ||
| """Assets service.""" | ||
|
|
||
| def terminate(self, asset_id: str, resource_data: ResourceData | None = None) -> Asset: | ||
| """Terminate the given Asset id. | ||
|
|
||
| Args: | ||
| asset_id: Asset ID. | ||
| resource_data: Resource data will be updated | ||
| """ | ||
| response = self._resource_do_request(asset_id, "POST", "terminate", json=resource_data) | ||
| return self._model_class.from_response(response) | ||
|
|
||
| def render(self, asset_id: str) -> AssetTemplate: | ||
| """Renders the template for the given Asset id. | ||
|
|
||
| Args: | ||
| asset_id: Asset ID. | ||
|
|
||
| Returns: | ||
| Render asset template json. | ||
| """ | ||
| response = self._resource_do_request(asset_id, action="render") | ||
|
|
||
| return AssetTemplate.from_response(response) | ||
|
|
||
|
|
||
| class AsyncAssetsService( | ||
| AsyncCreateMixin[Asset], | ||
| AsyncUpdateMixin[Asset], | ||
| AsyncGetMixin[Asset], | ||
| AsyncCollectionMixin[Asset], | ||
| AsyncService[Asset], | ||
| AssetsServiceConfig, | ||
| ): | ||
| """Asynchronous Assets service.""" | ||
|
|
||
| async def terminate(self, asset_id: str, resource_data: ResourceData | None = None) -> Asset: | ||
| """Terminate the given Asset id. | ||
|
|
||
| Args: | ||
| asset_id: Asset ID. | ||
| resource_data: Resource data will be updated | ||
| """ | ||
| response = await self._resource_do_request( | ||
| asset_id, "POST", "terminate", json=resource_data | ||
| ) | ||
|
|
||
| return self._model_class.from_response(response) | ||
|
|
||
| async def render(self, asset_id: str) -> AssetTemplate: | ||
| """Renders the template for the given Asset id. | ||
|
|
||
| Args: | ||
| asset_id: Asset ID. | ||
|
|
||
| Returns: | ||
| Render asset template json. | ||
| """ | ||
| response = await self._resource_do_request(asset_id, action="render") | ||
|
|
||
| return AssetTemplate.from_response(response) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import httpx | ||
| import pytest | ||
| import respx | ||
|
|
||
| from mpt_api_client.constants import APPLICATION_JSON | ||
| from mpt_api_client.resources.commerce.assets import AssetsService, AsyncAssetsService | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def assets_service(http_client): | ||
| return AssetsService(http_client=http_client) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def async_assets_service(async_http_client): | ||
| return AsyncAssetsService(http_client=async_http_client) | ||
|
|
||
|
|
||
| async def test_async_render(async_assets_service): | ||
| render_response = {"id": "ASSET-123", "title": "Sample Asset"} | ||
| with respx.mock: | ||
| respx.get("https://api.example.com/public/v1/commerce/assets/ASSET-123/render").mock( | ||
| return_value=httpx.Response( | ||
| status_code=200, | ||
| headers={"content-type": APPLICATION_JSON}, | ||
| json=render_response, | ||
| ) | ||
| ) | ||
|
|
||
| result = await async_assets_service.render("ASSET-123") | ||
|
|
||
| assert result is not None | ||
|
|
||
|
|
||
| def test_render(assets_service): | ||
| render_response = {"id": "ASSET-123", "title": "Sample Asset"} | ||
| with respx.mock: | ||
| mock_route = respx.get( | ||
| "https://api.example.com/public/v1/commerce/assets/ASSET-123/render" | ||
| ).mock( | ||
| return_value=httpx.Response( | ||
| status_code=200, | ||
| headers={"content-type": APPLICATION_JSON}, | ||
| json=render_response, | ||
| ) | ||
| ) | ||
|
|
||
| result = assets_service.render("ASSET-123") | ||
|
|
||
| assert mock_route.called | ||
| assert mock_route.call_count == 1 | ||
| assert result is not None | ||
|
|
||
|
|
||
| def test_terminate(assets_service): | ||
| response_data = {"id": "ASSET-123", "status": "terminated"} | ||
| with respx.mock: | ||
| mock_route = respx.post( | ||
| "https://api.example.com/public/v1/commerce/assets/ASSET-123/terminate" | ||
| ).mock( | ||
| return_value=httpx.Response( | ||
| status_code=200, | ||
| headers={"content-type": APPLICATION_JSON}, | ||
| json=response_data, | ||
| ) | ||
| ) | ||
|
|
||
| result = assets_service.terminate("ASSET-123") | ||
|
|
||
| assert mock_route.called | ||
| assert mock_route.call_count == 1 | ||
| assert result is not None | ||
|
|
||
|
|
||
| async def test_async_terminate(async_assets_service): | ||
| response_data = {"id": "ASSET-123", "status": "terminated"} | ||
| with respx.mock: | ||
| mock_route = respx.post( | ||
| "https://api.example.com/public/v1/commerce/assets/ASSET-123/terminate" | ||
| ).mock( | ||
| return_value=httpx.Response( | ||
| status_code=200, | ||
| headers={"content-type": APPLICATION_JSON}, | ||
| json=response_data, | ||
| ) | ||
| ) | ||
|
|
||
| result = await async_assets_service.terminate("ASSET-123") | ||
|
|
||
| assert mock_route.called | ||
| assert mock_route.call_count == 1 | ||
| assert result is not None | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("method", ["create", "update", "get", "render", "terminate"]) | ||
| def test_assets_service_methods(assets_service, method): | ||
| result = hasattr(assets_service, method) | ||
|
|
||
| assert result is True | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("method", ["create", "update", "get", "render", "terminate"]) | ||
| def test_async_assets_service_methods(async_assets_service, method): | ||
| result = hasattr(async_assets_service, method) | ||
|
|
||
| assert result is True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.