from unittest.mock import patch import pytest from analytics.logic.stores import get_stores class TestStores: """Return response from get_stores.""" def test_get_stores( mock_get_feeds_with_outages_v2_payload, ): with patch( "analytics.logic.stores.get_feeds_with_outages_v2", return_value={ "feed_statuses": [ { "distributor": "sme", "feed_name": "Spotify Streams", "feed_id": 1, "store_id": 286, "store_high_water_mark": "2024-09-09", "streaming_stores_high_watermark": "2024-09-09", "missing_dates_before_store_high_watermark": [], "has_streams_outage": False, }, { "distributor": "theorchard", "feed_name": "Spotify Streams", "feed_id": 1, "store_id": 286, "store_high_water_mark": "2024-09-09", "streaming_stores_high_watermark": "2024-09-09", "missing_dates_before_store_high_watermark": [], "has_streams_outage": False, }, { "distributor": "sme", "feed_name": "Napster (Rhapsody)", "feed_id": 11, "store_id": 4, "store_high_water_mark": "2024-09-08", "streaming_stores_high_watermark": "2024-09-09", "missing_dates_before_store_high_watermark": [], "has_streams_outage": True, "error": {"types": ["streams"], "code": "unreliable"}, }, { "distributor": "theorchard", "feed_name": "Napster (Rhapsody)", "feed_id": 11, "store_id": 4, "store_high_water_mark": "2024-09-08", "streaming_stores_high_watermark": "2024-09-09", "missing_dates_before_store_high_watermark": [], "has_streams_outage": False, }, ] }, ) as get_feeds_with_outages_v2: stores = get_stores([4, 286]) assert get_feeds_with_outages_v2.call_count == 1 assert len(stores) == 2 assert stores == [ { "distributors": ["sme", "theorchard"], "errors": [ { "distributor": "sme", "error": {"code": "unreliable", "types": ["streams"]}, "feed_id": 11, "feed_name": "Napster (Rhapsody)", } ], "store_id": 4, "store_name": "Napster", }, { "distributors": ["sme", "theorchard"], "errors": [], "store_id": 286, "store_name": "Spotify", }, ]