|
| 1 | +import httpx |
| 2 | +import pytest |
| 3 | +import respx |
| 4 | + |
| 5 | +from mpt_api_client.resources.commerce.orders_asset import ( |
| 6 | + AsyncOrdersAssetService, |
| 7 | + OrdersAssetService, |
| 8 | +) |
| 9 | + |
| 10 | + |
| 11 | +@pytest.fixture |
| 12 | +def asset_service(http_client): |
| 13 | + return OrdersAssetService(http_client=http_client, endpoint_params={"order_id": "ORD-123"}) |
| 14 | + |
| 15 | + |
| 16 | +@pytest.fixture |
| 17 | +def async_asset_service(async_http_client): |
| 18 | + return AsyncOrdersAssetService( |
| 19 | + http_client=async_http_client, endpoint_params={"order_id": "ORD-123"} |
| 20 | + ) |
| 21 | + |
| 22 | + |
| 23 | +@pytest.mark.parametrize("method", ["get", "create", "update", "delete", "render"]) |
| 24 | +def test_mixins_present(asset_service, method): |
| 25 | + result = hasattr(asset_service, method) |
| 26 | + |
| 27 | + assert result is True |
| 28 | + |
| 29 | + |
| 30 | +@pytest.mark.parametrize("method", ["get", "create", "update", "delete", "render"]) |
| 31 | +def test_async_mixins_present(async_asset_service, method): |
| 32 | + result = hasattr(async_asset_service, method) |
| 33 | + |
| 34 | + assert result is True |
| 35 | + |
| 36 | + |
| 37 | +def test_endpoint(asset_service): |
| 38 | + result = asset_service.path == "/public/v1/commerce/orders/ORD-123/assets" |
| 39 | + |
| 40 | + assert result is True |
| 41 | + |
| 42 | + |
| 43 | +def test_async_endpoint(async_asset_service): |
| 44 | + result = async_asset_service.path == "/public/v1/commerce/orders/ORD-123/assets" |
| 45 | + |
| 46 | + assert result is True |
| 47 | + |
| 48 | + |
| 49 | +def test_render(asset_service): |
| 50 | + template_content = "# Order Asset Template\n\nThis is a sample order asset template." |
| 51 | + with respx.mock: |
| 52 | + respx.get( |
| 53 | + "https://api.example.com/public/v1/commerce/orders/ORD-123/assets/ASSET-456/render" |
| 54 | + ).mock( |
| 55 | + return_value=httpx.Response( |
| 56 | + status_code=httpx.codes.OK, |
| 57 | + headers={"content-type": "text/markdown"}, |
| 58 | + content=template_content, |
| 59 | + ) |
| 60 | + ) |
| 61 | + |
| 62 | + result = asset_service.render("ASSET-456") |
| 63 | + |
| 64 | + assert result == template_content |
| 65 | + |
| 66 | + |
| 67 | +async def test_async_render(async_asset_service): |
| 68 | + template_content = "# Order Asset Template\n\nThis is a sample order asset template." |
| 69 | + with respx.mock: |
| 70 | + respx.get( |
| 71 | + "https://api.example.com/public/v1/commerce/orders/ORD-123/assets/ASSET-456/render" |
| 72 | + ).mock( |
| 73 | + return_value=httpx.Response( |
| 74 | + status_code=httpx.codes.OK, |
| 75 | + headers={"content-type": "text/markdown"}, |
| 76 | + content=template_content, |
| 77 | + ) |
| 78 | + ) |
| 79 | + |
| 80 | + result = await async_asset_service.render("ASSET-456") |
| 81 | + |
| 82 | + assert result == template_content |
0 commit comments