API - use same tile server as Client to generate staticmap - fix #83
This commit is contained in:
parent
bd7783ca96
commit
3ead237e5c
@ -1,5 +1,5 @@
|
||||
import json
|
||||
from typing import Tuple
|
||||
from typing import Any, Tuple
|
||||
|
||||
from flask import Flask
|
||||
from flask.testing import FlaskClient
|
||||
@ -23,3 +23,13 @@ class ApiTestCaseMixin:
|
||||
)
|
||||
auth_token = json.loads(resp_login.data.decode())['auth_token']
|
||||
return client, auth_token
|
||||
|
||||
|
||||
class CallArgsMixin:
|
||||
@staticmethod
|
||||
def get_args(call_args: Any) -> Any:
|
||||
if len(call_args) == 2:
|
||||
args, _ = call_args
|
||||
else:
|
||||
_, args, _ = call_args
|
||||
return args
|
||||
|
@ -1,4 +1,3 @@
|
||||
from typing import Any
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from flask import Flask
|
||||
@ -6,6 +5,7 @@ from flask import Flask
|
||||
from fittrackee import email_service
|
||||
from fittrackee.emails.email import EmailMessage
|
||||
|
||||
from ..api_test_case import CallArgsMixin
|
||||
from .template_results.password_reset_request import expected_en_text_body
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ class TestEmailMessage:
|
||||
assert 'Hello !' in message_string
|
||||
|
||||
|
||||
class TestEmailSending:
|
||||
class TestEmailSending(CallArgsMixin):
|
||||
|
||||
email_data = {
|
||||
'expiration_delay': '3 seconds',
|
||||
@ -42,14 +42,6 @@ class TestEmailSending:
|
||||
'browser_name': 'Firefox',
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def get_args(call_args: Any) -> Any:
|
||||
if len(call_args) == 2:
|
||||
args, _ = call_args
|
||||
else:
|
||||
_, args, _ = call_args
|
||||
return args
|
||||
|
||||
def assert_smtp(self, smtp: Mock) -> None:
|
||||
assert smtp.sendmail.call_count == 1
|
||||
call_args = self.get_args(smtp.sendmail.call_args)
|
||||
|
@ -4,6 +4,7 @@ import re
|
||||
from datetime import datetime
|
||||
from io import BytesIO
|
||||
from typing import Dict
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
from flask import Flask
|
||||
@ -12,7 +13,7 @@ from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from fittrackee.workouts.utils_id import decode_short_id
|
||||
|
||||
from ..api_test_case import ApiTestCaseMixin
|
||||
from ..api_test_case import ApiTestCaseMixin, CallArgsMixin
|
||||
|
||||
|
||||
def assert_workout_data_with_gpx(data: Dict) -> None:
|
||||
@ -205,7 +206,7 @@ def assert_workout_data_wo_gpx(data: Dict) -> None:
|
||||
assert records[3]['value'] == 10.0
|
||||
|
||||
|
||||
class TestPostWorkoutWithGpx(ApiTestCaseMixin):
|
||||
class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
|
||||
def test_it_adds_an_workout_with_gpx_file(
|
||||
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
|
||||
) -> None:
|
||||
@ -330,6 +331,35 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin):
|
||||
assert len(data['data']['workouts']) == 1
|
||||
assert data['data']['workouts'][0]['notes'] == input_notes
|
||||
|
||||
def test_it_calls_configured_tile_server_for_static_map(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
gpx_file: str,
|
||||
static_map_get_mock: Mock,
|
||||
) -> None:
|
||||
client, auth_token = self.get_test_client_and_auth_token(app)
|
||||
client.post(
|
||||
'/api/workouts',
|
||||
data=dict(
|
||||
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||||
data='{"sport_id": 1}',
|
||||
),
|
||||
headers=dict(
|
||||
content_type='multipart/form-data',
|
||||
Authorization=f'Bearer {auth_token}',
|
||||
),
|
||||
)
|
||||
|
||||
call_args = self.get_args(static_map_get_mock.call_args)
|
||||
assert (
|
||||
app.config['TILE_SERVER']['URL']
|
||||
.replace('{s}.', '')
|
||||
.replace('/{z}/{x}/{y}.png', '')
|
||||
in call_args[0]
|
||||
)
|
||||
|
||||
def test_it_returns_500_if_gpx_file_has_not_tracks(
|
||||
self,
|
||||
app: Flask,
|
||||
|
@ -265,7 +265,14 @@ def generate_map(map_filepath: str, map_data: List) -> None:
|
||||
"""
|
||||
Generate and save map image from map data
|
||||
"""
|
||||
m = StaticMap(400, 225, 10)
|
||||
m = StaticMap(
|
||||
400,
|
||||
225,
|
||||
10,
|
||||
url_template=current_app.config['TILE_SERVER']['URL'].replace(
|
||||
'{s}.', ''
|
||||
),
|
||||
)
|
||||
line = Line(map_data, '#3388FF', 4)
|
||||
m.add_line(line)
|
||||
image = m.render()
|
||||
|
Loading…
Reference in New Issue
Block a user