import pytest from unittest import mock from server.client.clients.vendor_api import VendorApiClient from tests.helpers import read_json_from_file @pytest.fixture def mocked_spotify_playlists_vendor(): with mock.patch.object(VendorApiClient, "get_playlists") as mocked_vendor_response: mocked_vendor_response.side_effect = get_spotify_playlists_data yield mocked_vendor_response async def get_spotify_playlists_data(*args, **kwargs): playlists_data = read_json_from_file("clients/vendor_api/spotify_playlists") param_ids = kwargs.get("ids", []) vendor_map = {data["id"]: data for data in playlists_data if data.get("id")} result = [] not_found_error = { 'code': 'spotify_error', 'detail': 'Not Found', 'original': { 'service': 'spotify', 'status_code': 404, 'response': { 'error': { 'status': 404, 'message': 'Not found.' } } } } for _id in param_ids: result.append(vendor_map.get(_id, not_found_error)) return result