020 update city code resolving

This commit is contained in:
Раис Юсупалиев
2026-03-21 10:03:46 +03:00
parent c4175121a0
commit 163f379a65
14 changed files with 45939 additions and 271 deletions
+9 -13
View File
@@ -7,7 +7,7 @@ from app.domain.price import (
normalize_delivery_request,
sort_prices_by_price,
)
from app.schemas.request import DeliveryEntity, DeliveryRequest, ParcelType
from app.schemas.request import DeliveryCalculationRequest, DeliveryEntity, ParcelType
from app.schemas.response import DeliveryPrice
@@ -24,19 +24,18 @@ def _make_price(**overrides) -> DeliveryPrice:
return DeliveryPrice.model_construct(**payload)
def _make_request(**overrides) -> DeliveryRequest:
def _make_request(**overrides) -> DeliveryCalculationRequest:
payload = {
"entity": DeliveryEntity.INDIVIDUAL,
"from_city": " Moscow ",
"to_city": " Saint Petersburg ",
"country_code": " ru ",
"from_city": 1,
"to_city": 2,
"weight_kg": 1.235,
"length_cm": 10.04,
"width_cm": 20.05,
"height_cm": 30.06,
}
payload.update(overrides)
return DeliveryRequest(**payload)
return DeliveryCalculationRequest(**payload)
def test_normalize_delivery_request_applies_rules_without_side_effects() -> None:
@@ -45,20 +44,18 @@ def test_normalize_delivery_request_applies_rules_without_side_effects() -> None
normalized = normalize_delivery_request(request, weight_round_scale=2)
assert normalized is not request
assert normalized.from_city == "Moscow"
assert normalized.to_city == "Saint Petersburg"
assert normalized.country_code == "RU"
assert normalized.from_city == 1
assert normalized.to_city == 2
assert normalized.weight_kg == Decimal("1.24")
assert normalized.length_cm == Decimal("10.0")
assert normalized.width_cm == Decimal("20.1")
assert normalized.height_cm == Decimal("30.1")
assert request.from_city == " Moscow "
assert request.country_code == " ru "
assert request.from_city == 1
assert request.to_city == 2
def test_normalize_delivery_request_handles_normalization_boundaries() -> None:
request = _make_request(
country_code=" ",
weight_kg=0.0001,
length_cm=0.01,
width_cm=0.04,
@@ -73,7 +70,6 @@ def test_normalize_delivery_request_handles_normalization_boundaries() -> None:
assert low_scale.width_cm == Decimal("0.1")
assert low_scale.height_cm == Decimal("0.2")
assert high_scale.weight_kg == Decimal("0.01")
assert low_scale.country_code is None
def test_filter_valid_prices_handles_empty_input() -> None: