This commit is contained in:
@@ -35,6 +35,7 @@ _CALC_RESPONSE = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<m:Fields><m:Key>Total</m:Key><m:Value>1114.92</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-std</m:Value></m:Fields>
|
||||
<m:Fields><m:Key>MinPeriod</m:Key><m:Value>3</m:Value></m:Fields>
|
||||
<m:Fields><m:Key>MaxPeriod</m:Key><m:Value>5</m:Value></m:Fields>
|
||||
</m:List>
|
||||
@@ -44,6 +45,7 @@ _CALC_RESPONSE = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<m:Fields><m:Key>Total</m:Key><m:Value>2000.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>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>
|
||||
@@ -83,6 +85,27 @@ _ERROR_RESPONSE = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
</soap:Body>
|
||||
</soap:Envelope>"""
|
||||
|
||||
_DELIVERY_TYPES_RESPONSE = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
|
||||
<soap:Body>
|
||||
<m:GetReferenceDataResponse xmlns:m="http://www.cargo3.ru">
|
||||
<m:return>
|
||||
<m:Key>deliverytype</m:Key>
|
||||
<m:List>
|
||||
<m:Key>NameOfdeliverytype</m:Key>
|
||||
<m:Value>ДоставкаДоДверей</m:Value>
|
||||
<m:Fields><m:Key>Information</m:Key><m:Value>Дверь-Дверь</m:Value></m:Fields>
|
||||
</m:List>
|
||||
<m:List>
|
||||
<m:Key>NameOfdeliverytype</m:Key>
|
||||
<m:Value>СкладДверь</m:Value>
|
||||
<m:Fields><m:Key>Information</m:Key><m:Value>Склад-Дверь</m:Value></m:Fields>
|
||||
</m:List>
|
||||
</m:return>
|
||||
</m:GetReferenceDataResponse>
|
||||
</soap:Body>
|
||||
</soap:Envelope>"""
|
||||
|
||||
|
||||
class SequenceHTTPClient:
|
||||
def __init__(self, results: list[Any]) -> None:
|
||||
@@ -109,7 +132,6 @@ def _params() -> CSEOrderRegistrationParams:
|
||||
payer="payer-1",
|
||||
payment_method="pm-1",
|
||||
shipping_method="sm-1",
|
||||
urgency="urgency-1",
|
||||
)
|
||||
|
||||
|
||||
@@ -166,19 +188,29 @@ def test_parse_calc_response_round_trip() -> None:
|
||||
|
||||
|
||||
def test_provider_get_prices_maps_all_tariffs() -> None:
|
||||
response = httpx.Response(200, text=_CALC_RESPONSE)
|
||||
client, _ = _build_client([response])
|
||||
client, http_client = _build_client(
|
||||
[
|
||||
httpx.Response(200, text=_DELIVERY_TYPES_RESPONSE),
|
||||
httpx.Response(200, text=_CALC_RESPONSE),
|
||||
]
|
||||
)
|
||||
provider = CSEProvider(client)
|
||||
|
||||
prices = asyncio.run(provider.get_prices(_calc_request()))
|
||||
|
||||
# PVZ-requiring scheme (Склад-Дверь) is excluded: only delivery types + one
|
||||
# Calc (for door-to-door) are requested.
|
||||
assert len(http_client.calls) == 2
|
||||
assert [price.provider for price in prices] == ["cse", "cse"]
|
||||
assert [price.tariff_code for price in prices] == ["tariff-guid-1", "tariff-guid-2"]
|
||||
assert [price.tariff_code for price in prices] == [
|
||||
"ДоставкаДоДверей|urg-std",
|
||||
"ДоставкаДоДверей|urg-exp",
|
||||
]
|
||||
assert prices[0].price == Decimal("1114.92")
|
||||
assert prices[0].currency == "RUB"
|
||||
assert prices[0].delivery_days_min == 3
|
||||
assert prices[0].delivery_days_max == 5
|
||||
assert prices[0].service_name == "Россия доставка"
|
||||
assert prices[0].service_name == "Россия доставка — Дверь-Дверь"
|
||||
|
||||
|
||||
def test_provider_get_payment_price_selects_matching_tariff() -> None:
|
||||
@@ -193,7 +225,7 @@ def test_provider_get_payment_price_selects_matching_tariff() -> None:
|
||||
"price": 200000,
|
||||
"deliveryDaysMin": 1,
|
||||
"deliveryDaysMax": 2,
|
||||
"tariffCode": "tariff-guid-2",
|
||||
"tariffCode": "ДоставкаДоДверей|urg-exp",
|
||||
},
|
||||
"parcelType": "parcel",
|
||||
"weight": "1.0",
|
||||
@@ -204,7 +236,7 @@ def test_provider_get_payment_price_selects_matching_tariff() -> None:
|
||||
price = asyncio.run(provider.get_payment_price(request))
|
||||
|
||||
assert price is not None
|
||||
assert price.tariff_code == "tariff-guid-2"
|
||||
assert price.tariff_code == "ДоставкаДоДверей|urg-exp"
|
||||
assert price.price == Decimal("2000.00")
|
||||
|
||||
|
||||
@@ -221,9 +253,38 @@ def test_provider_register_order_returns_document_number() -> None:
|
||||
assert http_client.calls[0]["url"] == "http://lk-test.cse.ru/1c/ws/web1c.1cws"
|
||||
|
||||
|
||||
def test_save_order_request_uses_selected_tariff_urgency() -> None:
|
||||
request = make_init_payment_request(
|
||||
systemData={
|
||||
"tariff": {
|
||||
"provider": "cse",
|
||||
"serviceName": "Экспресс",
|
||||
"price": 200000,
|
||||
"deliveryDaysMin": 1,
|
||||
"deliveryDaysMax": 2,
|
||||
"tariffCode": "ДоставкаДоДверей|urg-exp",
|
||||
},
|
||||
"parcelType": "parcel",
|
||||
"weight": "1.0",
|
||||
"dimensions": {"length": "10", "width": "10", "height": "10"},
|
||||
}
|
||||
)
|
||||
body = order_mapper.map_cse_save_order_request(request, "order-uuid-1", _params())
|
||||
order = body["data"].items[0]
|
||||
|
||||
assert order.field_value("Urgency") == "urg-exp"
|
||||
assert order.field_value("DeliveryOfCargo") == "ДоставкаДоДверей"
|
||||
assert order.field_value("Payer") == "payer-1"
|
||||
assert order.field_value("ShippingMethod") == "sm-1"
|
||||
|
||||
|
||||
def test_application_error_in_response_raises_request_error() -> None:
|
||||
response = httpx.Response(200, text=_ERROR_RESPONSE)
|
||||
client, _ = _build_client([response])
|
||||
client, _ = _build_client(
|
||||
[
|
||||
httpx.Response(200, text=_DELIVERY_TYPES_RESPONSE),
|
||||
httpx.Response(200, text=_ERROR_RESPONSE),
|
||||
]
|
||||
)
|
||||
provider = CSEProvider(client)
|
||||
|
||||
with pytest.raises(CSERequestError):
|
||||
|
||||
Reference in New Issue
Block a user