Добавлен tomtom
This commit is contained in:
@@ -17,6 +17,38 @@ from app.services.aggregator import (
|
||||
|
||||
_DADATA_COUNTRIES = ("RU", "BY", "KZ")
|
||||
_YANDEX_COUNTRIES = ("AM", "AZ", "KG", "MD", "TJ", "TM", "UZ")
|
||||
_TOMTOM_COUNTRIES = (
|
||||
"AL",
|
||||
"AT",
|
||||
"BE",
|
||||
"BG",
|
||||
"CH",
|
||||
"CZ",
|
||||
"DE",
|
||||
"DK",
|
||||
"EE",
|
||||
"ES",
|
||||
"FI",
|
||||
"FR",
|
||||
"GB",
|
||||
"GR",
|
||||
"HR",
|
||||
"HU",
|
||||
"IE",
|
||||
"IT",
|
||||
"LT",
|
||||
"LV",
|
||||
"NL",
|
||||
"NO",
|
||||
"PL",
|
||||
"PT",
|
||||
"RO",
|
||||
"RS",
|
||||
"SE",
|
||||
"SI",
|
||||
"SK",
|
||||
"UA",
|
||||
)
|
||||
|
||||
|
||||
class StubAddressSuggestionProvider:
|
||||
@@ -74,6 +106,7 @@ def _make_country_mapping() -> dict[str, str]:
|
||||
country_code: "yandex_geosuggest"
|
||||
for country_code in _YANDEX_COUNTRIES
|
||||
},
|
||||
**{country_code: "tomtom" for country_code in _TOMTOM_COUNTRIES},
|
||||
}
|
||||
|
||||
|
||||
@@ -97,9 +130,13 @@ def test_suggest_addresses_routes_dadata_countries_to_dadata(
|
||||
"yandex_geosuggest",
|
||||
response=[_make_suggestion("Yerevan, Tumanyan 1")],
|
||||
)
|
||||
tomtom = StubAddressSuggestionProvider(
|
||||
"tomtom",
|
||||
response=[_make_suggestion("Alexanderplatz 1, 10178 Berlin")],
|
||||
)
|
||||
service = AggregatorService(
|
||||
providers=[],
|
||||
address_suggestion_providers=[dadata, yandex_geosuggest],
|
||||
address_suggestion_providers=[dadata, yandex_geosuggest, tomtom],
|
||||
address_suggestion_country_to_provider=_make_country_mapping(),
|
||||
)
|
||||
request = _make_request(
|
||||
@@ -121,6 +158,7 @@ def test_suggest_addresses_routes_dadata_countries_to_dadata(
|
||||
]
|
||||
assert dadata.calls == [request]
|
||||
assert yandex_geosuggest.calls == []
|
||||
assert tomtom.calls == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize("country_code", _YANDEX_COUNTRIES)
|
||||
@@ -135,9 +173,13 @@ def test_suggest_addresses_routes_cis_countries_to_yandex_geosuggest(
|
||||
"yandex_geosuggest",
|
||||
response=[_make_suggestion("Yerevan, Tumanyan 1")],
|
||||
)
|
||||
tomtom = StubAddressSuggestionProvider(
|
||||
"tomtom",
|
||||
response=[_make_suggestion("Alexanderplatz 1, 10178 Berlin")],
|
||||
)
|
||||
service = AggregatorService(
|
||||
providers=[],
|
||||
address_suggestion_providers=[dadata, yandex_geosuggest],
|
||||
address_suggestion_providers=[dadata, yandex_geosuggest, tomtom],
|
||||
address_suggestion_country_to_provider=_make_country_mapping(),
|
||||
)
|
||||
request = _make_request(country_code=country_code, city="Yerevan", query="Tumanyan")
|
||||
@@ -147,6 +189,57 @@ def test_suggest_addresses_routes_cis_countries_to_yandex_geosuggest(
|
||||
assert result == [AddressSuggestion(address="Yerevan, Tumanyan 1")]
|
||||
assert dadata.calls == []
|
||||
assert yandex_geosuggest.calls == [request]
|
||||
assert tomtom.calls == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize("country_code", _TOMTOM_COUNTRIES)
|
||||
def test_suggest_addresses_routes_european_countries_to_tomtom(
|
||||
country_code: str,
|
||||
) -> None:
|
||||
dadata = StubAddressSuggestionProvider(
|
||||
"dadata",
|
||||
response=[_make_suggestion("Moscow, Lenina 1")],
|
||||
)
|
||||
yandex_geosuggest = StubAddressSuggestionProvider(
|
||||
"yandex_geosuggest",
|
||||
response=[_make_suggestion("Yerevan, Tumanyan 1")],
|
||||
)
|
||||
tomtom = StubAddressSuggestionProvider(
|
||||
"tomtom",
|
||||
response=[
|
||||
_make_suggestion(
|
||||
"Alexanderplatz 1, 10178 Berlin",
|
||||
street="Alexanderplatz",
|
||||
house="1",
|
||||
postal_code="10178",
|
||||
)
|
||||
],
|
||||
)
|
||||
service = AggregatorService(
|
||||
providers=[],
|
||||
address_suggestion_providers=[dadata, yandex_geosuggest, tomtom],
|
||||
address_suggestion_country_to_provider=_make_country_mapping(),
|
||||
)
|
||||
request = _make_request(
|
||||
country_code=country_code,
|
||||
city="Berlin",
|
||||
query="Alexanderplatz 1",
|
||||
)
|
||||
|
||||
result = asyncio.run(service.suggest_addresses(request))
|
||||
|
||||
assert result == [
|
||||
AddressSuggestion(
|
||||
address="Alexanderplatz 1, 10178 Berlin",
|
||||
street="Alexanderplatz",
|
||||
house="1",
|
||||
flat=None,
|
||||
postal_code="10178",
|
||||
)
|
||||
]
|
||||
assert dadata.calls == []
|
||||
assert yandex_geosuggest.calls == []
|
||||
assert tomtom.calls == [request]
|
||||
|
||||
|
||||
def test_suggest_addresses_raises_for_unsupported_country() -> None:
|
||||
|
||||
Reference in New Issue
Block a user