API - mock staticmap for all tests

This commit is contained in:
Sam 2021-07-14 20:04:27 +02:00
parent be4dc6fe8e
commit bd7783ca96

View File

@ -1,9 +1,26 @@
import datetime
from io import BytesIO
from typing import Generator
from unittest.mock import Mock, patch
import pytest
from PIL import Image
from fittrackee import db
from fittrackee.workouts.models import Sport, Workout, WorkoutSegment
from fittrackee.workouts.utils import StaticMap
byte_io = BytesIO()
Image.new('RGB', (256, 256)).save(byte_io, 'PNG')
byte_image = byte_io.getvalue()
@pytest.fixture(scope='session', autouse=True)
def static_map_get_mock() -> Generator:
# to avoid unnecessary requests calls through staticmap
m = Mock(return_value=(200, byte_image))
with patch.object(StaticMap, 'get', m) as _fixture:
yield _fixture
@pytest.fixture()