34 lines
932 B
Python
34 lines
932 B
Python
from decimal import Decimal
|
|
|
|
import pytest
|
|
|
|
from app.adapters.delivery_providers.cdek.mapper import CDEKMappingError, map_cdek_response
|
|
|
|
|
|
def test_map_cdek_response_maps_first_tariff_to_unified_model() -> None:
|
|
payload = {
|
|
"tariff_codes": [
|
|
{
|
|
"tariff_name": "Express",
|
|
"delivery_sum": "1234.50",
|
|
"currency": "rub",
|
|
"period_min": 2,
|
|
"period_max": 4,
|
|
}
|
|
]
|
|
}
|
|
|
|
result = map_cdek_response(payload)
|
|
|
|
assert result.provider == "cdek"
|
|
assert result.service_name == "Express"
|
|
assert result.price == Decimal("1234.50")
|
|
assert result.currency == "RUB"
|
|
assert result.delivery_days_min == 2
|
|
assert result.delivery_days_max == 4
|
|
|
|
|
|
def test_map_cdek_response_raises_for_missing_tariff_codes() -> None:
|
|
with pytest.raises(CDEKMappingError):
|
|
map_cdek_response({"tariff_codes": []})
|