@@ -40,7 +40,9 @@ def map_cse_calc_response_for_tariff_code(
|
|||||||
delivery_type, _, urgency = tariff_code.partition("|")
|
delivery_type, _, urgency = tariff_code.partition("|")
|
||||||
for tariff in _iter_tariffs(root):
|
for tariff in _iter_tariffs(root):
|
||||||
if _tariff_urgency(tariff) == urgency:
|
if _tariff_urgency(tariff) == urgency:
|
||||||
return _map_tariff(tariff, delivery_type, delivery_type_label)
|
price = _map_tariff(tariff, delivery_type, delivery_type_label)
|
||||||
|
if price is not None:
|
||||||
|
return price
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@@ -62,6 +64,9 @@ def _map_tariff(
|
|||||||
delivery_type: str,
|
delivery_type: str,
|
||||||
delivery_type_label: str,
|
delivery_type_label: str,
|
||||||
) -> DeliveryPrice | None:
|
) -> DeliveryPrice | None:
|
||||||
|
if _is_additional_service_tariff(tariff):
|
||||||
|
return None
|
||||||
|
|
||||||
urgency = _tariff_urgency(tariff)
|
urgency = _tariff_urgency(tariff)
|
||||||
if not urgency:
|
if not urgency:
|
||||||
return None
|
return None
|
||||||
@@ -111,6 +116,13 @@ def _map_tariff(
|
|||||||
raise CSEMappingError("CSE tariff fields have invalid values.") from exc
|
raise CSEMappingError("CSE tariff fields have invalid values.") from exc
|
||||||
|
|
||||||
|
|
||||||
|
def _is_additional_service_tariff(tariff: Element) -> bool:
|
||||||
|
value = tariff.field_value("AdditionalService")
|
||||||
|
if value is None:
|
||||||
|
return False
|
||||||
|
return value.strip().lower() == "true"
|
||||||
|
|
||||||
|
|
||||||
def _to_int(value: str | None) -> int | None:
|
def _to_int(value: str | None) -> int | None:
|
||||||
if value is None or value == "":
|
if value is None or value == "":
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -126,6 +126,46 @@ _FORM_RESPONSE = """<?xml version="1.0" encoding="UTF-8"?>
|
|||||||
</soap:Body>
|
</soap:Body>
|
||||||
</soap:Envelope>"""
|
</soap:Envelope>"""
|
||||||
|
|
||||||
|
_CALC_RESPONSE_WITH_ADDITIONAL_SERVICE_FIRST = """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
|
||||||
|
<soap:Body>
|
||||||
|
<m:CalcResponse xmlns:m="http://www.cargo3.ru">
|
||||||
|
<m:return>
|
||||||
|
<m:Key>Calc</m:Key>
|
||||||
|
<m:List>
|
||||||
|
<m:Key>Destination</m:Key>
|
||||||
|
<m:List>
|
||||||
|
<m:Key>Tariff</m:Key>
|
||||||
|
<m:Value>additional-service-guid</m:Value>
|
||||||
|
<m:Fields><m:Key>Total</m:Key><m:Value>100.00</m:Value></m:Fields>
|
||||||
|
<m:Fields><m:Key>CurrencyName</m:Key><m:Value>RUR</m:Value></m:Fields>
|
||||||
|
<m:Fields>
|
||||||
|
<m:Key>Service</m:Key><m:Value>Доп. услуга</m:Value>
|
||||||
|
</m:Fields>
|
||||||
|
<m:Fields><m:Key>Urgency</m:Key><m:Value>urg-exp</m:Value></m:Fields>
|
||||||
|
<m:Fields>
|
||||||
|
<m:Key>AdditionalService</m:Key><m:Value>true</m:Value>
|
||||||
|
</m:Fields>
|
||||||
|
</m:List>
|
||||||
|
<m:List>
|
||||||
|
<m:Key>Tariff</m:Key>
|
||||||
|
<m:Value>delivery-guid</m:Value>
|
||||||
|
<m:Fields><m:Key>Total</m:Key><m:Value>793.00</m:Value></m:Fields>
|
||||||
|
<m:Fields><m:Key>CurrencyName</m:Key><m:Value>RUR</m:Value></m:Fields>
|
||||||
|
<m:Fields><m:Key>Service</m:Key><m:Value>Экспресс</m:Value></m:Fields>
|
||||||
|
<m:Fields><m:Key>Urgency</m:Key><m:Value>urg-exp</m:Value></m:Fields>
|
||||||
|
<m:Fields>
|
||||||
|
<m:Key>AdditionalService</m:Key><m:Value>false</m:Value>
|
||||||
|
</m:Fields>
|
||||||
|
<m:Fields><m:Key>MinPeriod</m:Key><m:Value>1</m:Value></m:Fields>
|
||||||
|
<m:Fields><m:Key>MaxPeriod</m:Key><m:Value>2</m:Value></m:Fields>
|
||||||
|
</m:List>
|
||||||
|
</m:List>
|
||||||
|
</m:return>
|
||||||
|
</m:CalcResponse>
|
||||||
|
</soap:Body>
|
||||||
|
</soap:Envelope>"""
|
||||||
|
|
||||||
_ERROR_RESPONSE = """<?xml version="1.0" encoding="UTF-8"?>
|
_ERROR_RESPONSE = """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
|
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
|
||||||
<soap:Body>
|
<soap:Body>
|
||||||
@@ -296,6 +336,50 @@ def test_provider_get_payment_price_selects_matching_tariff() -> None:
|
|||||||
assert price.price == Decimal("2000.00")
|
assert price.price == Decimal("2000.00")
|
||||||
|
|
||||||
|
|
||||||
|
def test_provider_get_payment_price_ignores_matching_additional_service() -> None:
|
||||||
|
response = httpx.Response(200, text=_CALC_RESPONSE_WITH_ADDITIONAL_SERVICE_FIRST)
|
||||||
|
client, _ = _build_client([response])
|
||||||
|
provider = CSEProvider(client)
|
||||||
|
request = make_init_payment_request(
|
||||||
|
systemData={
|
||||||
|
"tariff": {
|
||||||
|
"provider": "cse",
|
||||||
|
"serviceName": "Экспресс",
|
||||||
|
"price": 79300,
|
||||||
|
"deliveryDaysMin": 1,
|
||||||
|
"deliveryDaysMax": 2,
|
||||||
|
"tariffCode": "ДоставкаДоДверей|urg-exp",
|
||||||
|
},
|
||||||
|
"parcelType": "parcel",
|
||||||
|
"weight": "1.0",
|
||||||
|
"dimensions": {"length": "10", "width": "10", "height": "10"},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
price = asyncio.run(provider.get_payment_price(request))
|
||||||
|
|
||||||
|
assert price is not None
|
||||||
|
assert price.tariff_code == "ДоставкаДоДверей|urg-exp"
|
||||||
|
assert price.price == Decimal("793.00")
|
||||||
|
|
||||||
|
|
||||||
|
def test_provider_get_prices_excludes_additional_service_tariffs() -> None:
|
||||||
|
client, _ = _build_client(
|
||||||
|
[
|
||||||
|
httpx.Response(200, text=_DELIVERY_TYPES_RESPONSE),
|
||||||
|
httpx.Response(200, text=_CALC_RESPONSE_WITH_ADDITIONAL_SERVICE_FIRST),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
provider = CSEProvider(client)
|
||||||
|
|
||||||
|
prices = asyncio.run(provider.get_prices(_calc_request()))
|
||||||
|
|
||||||
|
assert [price.price for price in prices] == [Decimal("793.00")]
|
||||||
|
assert [price.service_name for price in prices] == [
|
||||||
|
"Экспресс — Дверь-Дверь"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def test_provider_register_order_returns_document_number() -> None:
|
def test_provider_register_order_returns_document_number() -> None:
|
||||||
response = httpx.Response(200, text=_SAVE_RESPONSE)
|
response = httpx.Response(200, text=_SAVE_RESPONSE)
|
||||||
client, http_client = _build_client([response])
|
client, http_client = _build_client([response])
|
||||||
|
|||||||
Reference in New Issue
Block a user