API - fix tests

This commit is contained in:
Sam 2023-09-14 09:19:49 +02:00
parent 9989a8d54d
commit abedd03d05

View File

@ -11,16 +11,7 @@ class TestGetStaticMapTileServerUrl:
'input_tile_server_subdomains,' 'input_tile_server_subdomains,'
'expected_tile_server_url', 'expected_tile_server_url',
[ [
( # tile server without subdomain
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
'',
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
),
(
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
'a',
'https://a.tile.openstreetmap.org/{z}/{x}/{y}.png',
),
( (
'https://tile.openstreetmap.org/{z}/{x}/{y}.png', 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
'', '',
@ -31,6 +22,21 @@ class TestGetStaticMapTileServerUrl:
'a', 'a',
'https://tile.openstreetmap.org/{z}/{x}/{y}.png', 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
), ),
# tile server with subdomain
(
'https://{s}.tile-cyclosm.openstreetmap.fr/cyclosm/'
'{z}/{x}/{y}.png',
'a',
'https://a.tile-cyclosm.openstreetmap.fr/cyclosm/'
'{z}/{x}/{y}.png',
),
(
'https://{s}.tile-cyclosm.openstreetmap.fr/cyclosm/'
'{z}/{x}/{y}.png',
'',
'https://tile-cyclosm.openstreetmap.fr/cyclosm/'
'{z}/{x}/{y}.png',
),
], ],
) )
def test_it_returns_tile_server_url( def test_it_returns_tile_server_url(
@ -52,12 +58,15 @@ class TestGetStaticMapTileServerUrl:
def test_it_returns_tile_server_url_with_random_subdomain(self) -> None: def test_it_returns_tile_server_url_with_random_subdomain(self) -> None:
"""in case multiple subdomains are provided""" """in case multiple subdomains are provided"""
tile_config = { tile_config = {
'URL': 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', 'URL': (
'https://{s}.tile-cyclosm.openstreetmap.fr/cyclosm/'
'{z}/{x}/{y}.png'
),
'STATICMAP_SUBDOMAINS': 'a,b,c', 'STATICMAP_SUBDOMAINS': 'a,b,c',
} }
with patch('random.choice', return_value='b'): with patch('random.choice', return_value='b'):
assert ( assert get_static_map_tile_server_url(tile_config) == (
get_static_map_tile_server_url(tile_config) 'https://b.tile-cyclosm.openstreetmap.fr/cyclosm/'
== 'https://b.tile.openstreetmap.org/{z}/{x}/{y}.png' '{z}/{x}/{y}.png'
) )