fix country code

This commit is contained in:
Раис Юсупалиев
2026-03-09 15:24:10 +03:00
parent 2d68aff34d
commit da301d4bc4
8 changed files with 155 additions and 45 deletions
+24 -10
View File
@@ -58,16 +58,19 @@ class StubCache:
self._storage[key] = value
def _make_request() -> DeliveryRequest:
return DeliveryRequest(
entity=DeliveryEntity.INDIVIDUAL,
from_city="Moscow",
to_city="Kazan",
weight_kg=1.234,
length_cm=30.0,
width_cm=20.0,
height_cm=10.0,
)
def _make_request(**overrides: object) -> DeliveryRequest:
payload: dict[str, object] = {
"entity": DeliveryEntity.INDIVIDUAL,
"from_city": "Moscow",
"to_city": "Kazan",
"country_code": None,
"weight_kg": 1.234,
"length_cm": 30.0,
"width_cm": 20.0,
"height_cm": 10.0,
}
payload.update(overrides)
return DeliveryRequest(**payload)
def _make_price(provider: str, price: str) -> DeliveryPrice:
@@ -96,6 +99,17 @@ def test_get_all_prices_full_success_returns_sorted_and_updates_cache() -> None:
assert [ttl for _, _, ttl in cache.set_calls] == [111, 222]
def test_get_all_prices_normalizes_and_forwards_country_code_to_providers() -> None:
provider = StubProvider(name="cdek", response=_make_price("cdek", "150.00"))
service = AggregatorService([provider], cache=StubCache())
result = asyncio.run(service.get_all_prices(_make_request(country_code=" kz ")))
assert [price.provider for price in result] == ["cdek"]
assert len(provider.calls) == 1
assert provider.calls[0].country_code == "KZ"
def test_get_all_prices_partial_failure_excludes_failed_provider() -> None:
provider_ok = StubProvider(name="ok", response=_make_price("ok", "150.00"))
provider_failed = StubProvider(name="failed", error=RuntimeError("provider unavailable"))