import time import pytest from app.data import ISRCS from app.src.tests.insights.tests_common import markets_to_test, \ start_date, end_date from app.utils import get_insights_market, generate_excel_file, calculate_diff_percent QUERY = 'GlobalSoundRecordingSummaryQuery' apollo_endpoint = "/dsp-api/consumer_analytics/v1/track-per-country?isrc={0}&start_date={1}&end_date={2}&vendor=spotify&streams_only=false&combine_isrc=true&market={3}" @pytest.mark.parametrize("market", markets_to_test) def test_globalSoundRecordingSummaryQuery(market, graphql, api_apollo): (insights_values, apollo_streams, diff) = [], [], [] for isrc in ISRCS: variables = {"isrc": isrc, "type": "SOS_V2", "startDate": start_date, "endDate": end_date, "countries": get_insights_market(market), "distributors": ["THEORCHARD", "SME", "AWAL"], "storeIds": [286], "streamSources": []} response_insights = graphql.fetch_data(QUERY, variables) insights_items = response_insights['globalSoundRecordingByIsrc']['analytics']['summary']['items'] insights_item_value = sum(item['value'] for item in insights_items) insights_values.append(insights_item_value) response_apollo = api_apollo.get( apollo_endpoint.format(isrc, start_date, end_date, market)) if response_apollo: apollo_data = response_apollo[0]['data'] apollo_streams_item = sum(item['streams'] for item in apollo_data) else: apollo_streams_item = 0 apollo_streams.append(apollo_streams_item) diff.append(calculate_diff_percent(apollo_streams_item, insights_item_value)) time.sleep(0.5) data_dict = { "isrc": ISRCS, "apollo_streams": apollo_streams, "insights_streams": insights_values, "change": diff, } generate_excel_file(data_dict, QUERY, [start_date, end_date, market])