API - support tile server w/ subdomains for static map generation
This commit is contained in:
2
fittrackee/tests/fixtures/fixtures_app.py
vendored
2
fittrackee/tests/fixtures/fixtures_app.py
vendored
@ -81,6 +81,8 @@ def app(monkeypatch: pytest.MonkeyPatch) -> Generator:
|
||||
monkeypatch.setenv('WEATHER_API_KEY', '')
|
||||
if os.getenv('TILE_SERVER_URL'):
|
||||
monkeypatch.delenv('TILE_SERVER_URL')
|
||||
if os.getenv('STATICMAP_SUBDOMAINS'):
|
||||
monkeypatch.delenv('STATICMAP_SUBDOMAINS')
|
||||
if os.getenv('MAP_ATTRIBUTION'):
|
||||
monkeypatch.delenv('MAP_ATTRIBUTION')
|
||||
if os.getenv('DEFAULT_STATICMAP'):
|
||||
|
63
fittrackee/tests/workouts/test_utils/test_maps.py
Normal file
63
fittrackee/tests/workouts/test_utils/test_maps.py
Normal file
@ -0,0 +1,63 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from fittrackee.workouts.utils.maps import get_static_map_tile_server_url
|
||||
|
||||
|
||||
class TestGetStaticMapTileServerUrl:
|
||||
@pytest.mark.parametrize(
|
||||
'input_tile_server_url,input_tile_server_subdomains,'
|
||||
'expected_tile_server_url',
|
||||
[
|
||||
(
|
||||
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
None,
|
||||
'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
),
|
||||
(
|
||||
'https://{s}.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',
|
||||
None,
|
||||
'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',
|
||||
),
|
||||
],
|
||||
)
|
||||
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
|
||||
)
|
||||
|
||||
def test_it_returns_tile_server_url_with_random_submain_when_multiple_provided( # noqa
|
||||
self,
|
||||
) -> None:
|
||||
tile_config = {
|
||||
'URL': 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
'STATICMAP_SUBDOMAINS': 'a,b,c',
|
||||
}
|
||||
|
||||
with patch('random.choice', return_value='b'):
|
||||
assert (
|
||||
get_static_map_tile_server_url(tile_config)
|
||||
== 'https://b.tile.openstreetmap.org/{z}/{x}/{y}.png'
|
||||
)
|
Reference in New Issue
Block a user