from datetime import date from app.utils import assert_close_enough def get_artist_trend_variables(gp_id): return { "id": gp_id, "days": -2, "startDate": date.today().strftime("%Y-%m-%d"), "orderBy": "streams7Days", "topSize": 5, "daysBack": -28, "countries": [], "topCountrySize": 10, "topStoreSize": 10 } def test_artist_1d_streams_consistency(graphql, participant): """ Validate 1-day stream values for top artists between catalog response and detailed trend analytics. """ gp_id = participant["id"] expected_value = participant["analytics"]["growthPeriods"][0]["value"] trend_response = graphql.fetch_data("ParticipantStreamingTrends", get_artist_trend_variables(gp_id)) analytics = trend_response["globalParticipantByGpId"][0]["analytics"] for dimension in ["Sos", "Country", "Store"]: dim_total = analytics[f"aggregatedStreamsBy{dimension}"]["byDimension"]["total"] actual_value = dim_total["streams1Day"] assert_close_enough(expected_value, actual_value, f"Artist:{gp_id}", dimension, "streams1Day") def test_artist_1d_growth_percentage_consistency(graphql, participant): """ Validate 1-day growth % for top artists between catalog response and detailed trend analytics. """ gp_id = participant["id"] expected_growth = participant["analytics"]["growthPeriods"][0]["growthPercentage"] trend_response = graphql.fetch_data("ParticipantStreamingTrends", get_artist_trend_variables(gp_id)) analytics = trend_response["globalParticipantByGpId"][0]["analytics"] for dimension in ["Sos", "Country", "Store"]: dim_total = analytics[f"aggregatedStreamsBy{dimension}"]["byDimension"]["total"] actual_growth = dim_total["streamsGrowthPeriods"][0]["streamsGrowthPercentage"] assert_close_enough(expected_growth, actual_growth, f"Artist:{gp_id}", dimension, "growthPercentage") def test_artist_7d_streams_consistency(graphql, participant): """ Validate 7-day stream values for top artists between catalog response and detailed trend analytics. """ gp_id = participant["id"] expected_value = participant["analytics"]["growthPeriods"][1]["value"] trend_response = graphql.fetch_data("ParticipantStreamingTrends", get_artist_trend_variables(gp_id)) analytics = trend_response["globalParticipantByGpId"][0]["analytics"] for dimension in ["Sos", "Country", "Store"]: dim_total = analytics[f"aggregatedStreamsBy{dimension}"]["byDimension"]["total"] actual_value = dim_total["streams7Days"] assert_close_enough(expected_value, actual_value, f"Artist:{gp_id}", dimension, "streams7Days") def test_artist_7d_growth_percentage_consistency(graphql, participant): """ Validate 7-day growth % for top artists between catalog response and detailed trend analytics. """ gp_id = participant["id"] expected_growth = participant["analytics"]["growthPeriods"][1]["growthPercentage"] trend_response = graphql.fetch_data("ParticipantStreamingTrends", get_artist_trend_variables(gp_id)) analytics = trend_response["globalParticipantByGpId"][0]["analytics"] for dimension in ["Sos", "Country", "Store"]: dim_total = analytics[f"aggregatedStreamsBy{dimension}"]["byDimension"]["total"] actual_growth = dim_total["streamsGrowthPeriods"][1]["streamsGrowthPercentage"] assert_close_enough(expected_growth, actual_growth, f"Artist:{gp_id}", dimension, "growthPercentage") def test_artist_all_time_streams_consistency(graphql, participant): """ Validate consistency of artists' all-time stream totals across: - Catalog (TopParticipants) - Trends (ParticipantStreamingTrends) - Metadata (GlobalParticipantMetadata) """ gp_id = participant["id"] expected_value = participant["analytics"]["streamsAllTime"] trend_response = graphql.fetch_data("ParticipantStreamingTrends", get_artist_trend_variables(gp_id)) trend_analytics = trend_response["globalParticipantByGpId"][0]["analytics"] for dimension in ["Sos", "Country", "Store"]: dim_total = trend_analytics[f"aggregatedStreamsBy{dimension}"]["byDimension"]["total"] actual_value = dim_total["streamsAllTime"] assert_close_enough(expected_value, actual_value, gp_id, dimension, "streamsAllTime") metadata_response = graphql.fetch_data("GlobalParticipantMetadata", {"id": gp_id}) metadata_value = metadata_response["globalParticipantByGpId"][0]["analytics"]["streamsAllTime"] assert_close_enough(expected_value, metadata_value, f"Artist:{gp_id}", "Metadata", "streamsAllTime")