import pytest from app.utils import assert_close_enough def get_trend_variables(isrc): return { "isrc": isrc, "distributors": "theorchard,awal,sme", "orderBy": "streams7Days", "topSize": 5, "daysBack": -28, "countries": [], "topCountrySize": 10, "topStoreSize": 10, "storeIds": [], } def get_sos_variables(isrc, store_ids): return { "isrc": isrc, "storeIds": store_ids, "countries": [] } def get_trend_by_store_variables(isrc): return { "isrc": isrc, "distributors": "theorchard,awal,sme", "orderBy": "streams7Days", "topSize": 5, "daysBack": -28, "storeIds": [453], "countries": [], "topCountrySize": 10, "topStoreSize": 10, } def test_1d_streams_consistency(graphql, record): isrc = record["isrc"] expected_value = record['analytics']['streams']['growthPeriods'][0]['value'] response = graphql.fetch_data("GetGlobalSoundRecordingStreamingTrendGO", get_trend_variables(isrc)) analytics = response["globalSoundRecordingByIsrc"]["analytics"] for dimension in ["Sos", "Country", "Store"]: dim_data = analytics[f"aggregatedStreamsBy{dimension}"]["byDimension"]["total"] actual_value = dim_data["streams1Day"] assert_close_enough(expected_value, actual_value, f"Song:{isrc}", dimension, "streams1Day") def test_1d_growth_percentage_consistency(graphql, record): isrc = record["isrc"] expected_growth = record['analytics']['streams']['growthPeriods'][0]['growthPercentage'] response = graphql.fetch_data("GetGlobalSoundRecordingStreamingTrendGO", get_trend_variables(isrc)) analytics = response["globalSoundRecordingByIsrc"]["analytics"] for dimension in ["Sos", "Country", "Store"]: dim_data = analytics[f"aggregatedStreamsBy{dimension}"]["byDimension"]["total"] actual_growth = dim_data["streamsGrowthPeriods"][0]["streamsGrowthPercentage"] assert_close_enough(expected_growth, actual_growth, f"Song:{isrc}", dimension, "streamsGrowthPercentage") def test_7d_streams_consistency(graphql, record): isrc = record["isrc"] expected_value = record['analytics']['streams']['growthPeriods'][1]['value'] response = graphql.fetch_data("GetGlobalSoundRecordingStreamingTrendGO", get_trend_variables(isrc)) analytics = response["globalSoundRecordingByIsrc"]["analytics"] for dimension in ["Sos", "Country", "Store"]: dim_data = analytics[f"aggregatedStreamsBy{dimension}"]["byDimension"]["total"] actual_value = dim_data["streams7Days"] assert_close_enough(expected_value, actual_value, f"Song:{isrc}", dimension, "streams7Days") def test_7d_growth_percentage_consistency(graphql, record): isrc = record["isrc"] expected_growth = record['analytics']['streams']['growthPeriods'][1]['growthPercentage'] response = graphql.fetch_data("GetGlobalSoundRecordingStreamingTrendGO", get_trend_variables(isrc)) analytics = response["globalSoundRecordingByIsrc"]["analytics"] for dimension in ["Sos", "Country", "Store"]: dim_data = analytics[f"aggregatedStreamsBy{dimension}"]["byDimension"]["total"] actual_growth = dim_data["streamsGrowthPeriods"][1]["streamsGrowthPercentage"] assert_close_enough(expected_growth, actual_growth, f"Song:{isrc}", dimension, "streamsGrowthPercentage") def test_all_time_streams_consistency(graphql, record): isrc = record["isrc"] original_value = record["analytics"]["streams"]["aggregate"]["allTime"] response = graphql.fetch_data("GetGlobalSoundRecordingStreamingTrendGO", get_trend_variables(isrc)) analytics = response["globalSoundRecordingByIsrc"]["analytics"] for dimension in ["Sos", "Country", "Store"]: actual_all_time = analytics[f"aggregatedStreamsBy{dimension}"]["byDimension"]["total"]["streamsAllTime"] assert_close_enough(original_value, actual_all_time, f"Song:{isrc}", dimension, "streamsAllTime")