FitTrackee/fittrackee/tests/workouts/test_utils/test_maps.py

73 lines
2.3 KiB
Python
Raw Normal View History

from unittest.mock import patch
import pytest
from fittrackee.workouts.utils.maps import get_static_map_tile_server_url
class TestGetStaticMapTileServerUrl:
@pytest.mark.parametrize(
2022-07-13 13:10:46 +02:00
'input_tile_server_url,'
'input_tile_server_subdomains,'
'expected_tile_server_url',
[
2023-09-14 09:19:49 +02:00
# tile server without subdomain
(
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
2022-07-13 13:10:46 +02:00
'',
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
),
(
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
'a',
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
),
2023-09-14 09:19:49 +02:00
# tile server with subdomain
(
2023-09-14 09:19:49 +02:00
'https://{s}.tile-cyclosm.openstreetmap.fr/cyclosm/'
'{z}/{x}/{y}.png',
'a',
2023-09-14 09:19:49 +02:00
'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(
self,
input_tile_server_url: str,
input_tile_server_subdomains: str,
expected_tile_server_url: str,
) -> None:
tile_config = {
'URL': input_tile_server_url,
'STATICMAP_SUBDOMAINS': input_tile_server_subdomains,
}
assert (
get_static_map_tile_server_url(tile_config)
== expected_tile_server_url
)
2022-07-13 13:10:46 +02:00
def test_it_returns_tile_server_url_with_random_subdomain(self) -> None:
"""in case multiple subdomains are provided"""
tile_config = {
2023-09-14 09:19:49 +02:00
'URL': (
'https://{s}.tile-cyclosm.openstreetmap.fr/cyclosm/'
'{z}/{x}/{y}.png'
),
'STATICMAP_SUBDOMAINS': 'a,b,c',
}
with patch('random.choice', return_value='b'):
2023-09-14 09:19:49 +02:00
assert get_static_map_tile_server_url(tile_config) == (
'https://b.tile-cyclosm.openstreetmap.fr/cyclosm/'
'{z}/{x}/{y}.png'
)