From bd7783ca960495155cc01bf90488d1533a5be3ec Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 14 Jul 2021 20:04:27 +0200 Subject: [PATCH] API - mock staticmap for all tests --- fittrackee/tests/fixtures/fixtures_workouts.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fittrackee/tests/fixtures/fixtures_workouts.py b/fittrackee/tests/fixtures/fixtures_workouts.py index d7fe8fea..094d6f7d 100644 --- a/fittrackee/tests/fixtures/fixtures_workouts.py +++ b/fittrackee/tests/fixtures/fixtures_workouts.py @@ -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()