fix cdek client

This commit is contained in:
Раис Юсупалиев
2026-03-08 23:35:04 +03:00
parent f799f2ba03
commit 2d68aff34d
7 changed files with 105 additions and 8 deletions
+31 -1
View File
@@ -9,7 +9,10 @@ from app.controllers.v1.delivery import get_aggregator_service
from app.main import create_app
from app.schemas.request import DeliveryEntity, DeliveryRequest
from app.schemas.response import DeliveryPrice
from app.services.aggregator import AggregatorServiceError
from app.services.aggregator import (
AggregatorServiceError,
InvalidDeliveryRequestError,
)
class StubAggregatorService:
@@ -229,6 +232,33 @@ def test_post_delivery_price_maps_service_exception_to_503() -> None:
}
def test_post_delivery_price_maps_invalid_request_to_400() -> None:
service = StubAggregatorService(
response=[],
error=InvalidDeliveryRequestError("city not found"),
)
app = create_app()
_install_service_override(app, service)
async def run_request() -> httpx.Response:
transport = httpx.ASGITransport(app=app, raise_app_exceptions=False)
async with httpx.AsyncClient(
transport=transport,
base_url="http://testserver",
) as client:
return await client.post("/api/v1/delivery/price", json=_valid_payload())
response = asyncio.run(run_request())
assert response.status_code == 400
assert response.json() == {
"detail": {
"code": "invalid_delivery_request",
"message": "Delivery request contains unknown or unsupported location.",
}
}
def test_delivery_price_endpoint_accepts_only_post_method() -> None:
service = StubAggregatorService(response=[])
app = create_app()