from app.logger import log def compare_stream_data(go_data, insights_data, entity_name): log.info(f"Comparing stream data between GO and Insights for {entity_name}") for key, go_value in go_data.items(): insights_value = insights_data.get(key) if insights_value is not None: assert go_value == insights_value, f"Mismatch for {entity_name} {key}: GO={go_value}, Insights={insights_value}" else: log.warning(f"No matching {entity_name} {key} found in Insights data") def test_songs_tab(graphql): variables_go = { "orderDir": "desc", "countries": [], "globalParticipantIds": [], "orderBy": "streams_7_days", "labelIds": [], "subaccountIds": [], "distributors": "theorchard,awal,sme", "offset": 0, "limit": 25 } variables_insights = { "limit": 50, "offset": 0, "orderBy": "streams_7_days", "orderDir": "desc", "countries": [], "distributors": "theorchard,sme,awal", "globalParticipantIds": [], "isEmployee": True, "labelIds": [], "storeIds": [], "subaccountIds": [] } response_go = graphql.fetch_data('TopGlobalSoundRecordings', variables_go) response_insights = graphql.fetch_data('TopGlobalSoundRecordingsWithTikTokV2Query', variables_insights) log.info(f"Response from GO: {response_go}") log.info(f"Response from Insights: {response_insights}") go_7_days_stream_data = \ {i['isrc']: i['analytics']['streams']['growthPeriods'][1]['value'] for i in response_go['topGlobalSoundRecordings']} insights_7_days_stream_data = \ {i['isrc']: i['analytics']['streams']['growthPeriods'][1]['value'] for i in response_insights['topGlobalSoundRecordingsTiktok']} compare_stream_data(go_7_days_stream_data, insights_7_days_stream_data, 'ISRC') def test_artists_tab(graphql): variables_go = { "orderBy": "streams_7_days", "countries": [], "labelIds": [], "globalParticipantIds": [], "subaccountIds": [], "distributors": "theorchard,awal,sme", "orderDir": "DESC", "offset": 0, "limit": 25 } variables_insights = { "limit": 50, "offset": 0, "orderBy": "streams_7_days", "orderDir": "desc", "countries": [], "globalParticipantIds": [], "isEmployee": True, "labelIds": [], "subaccountIds": [], "distributors": "theorchard,sme,awal" } response_go = graphql.fetch_data('TopParticipants', variables_go) response_insights = graphql.fetch_data('TopGlobalParticipantsResultsQuery', variables_insights) log.info(f"Response from GO: {response_go}") log.info(f"Response from Insights: {response_insights}") go_7_days_stream_data = \ {i['id']: i['analytics']['growthPeriods'][1]['value'] for i in response_go['topGlobalParticipantsResults']['participants']} insights_7_days_stream_data = \ {i['id']: i['analytics']['growthPeriods'][1]['value'] for i in response_insights['topGlobalParticipantsResults']['participants']} compare_stream_data(go_7_days_stream_data, insights_7_days_stream_data, 'ID') def test_products_tab(graphql): variables_go = { "orderBy": "streams_7_days", "countries": [], "labelIds": [], "globalParticipantIds": [], "subaccountIds": [], "orderDir": "DESC", "distributors": "theorchard,awal,sme", "offset": 0, "limit": 25 } variables_insights = { "limit": 50, "offset": 0, "orderBy": "streams_7_days", "orderDir": "desc", "countries": [], "globalParticipantIds": [], "isEmployee": True, "labelIds": [], "multiProduct": False, "subaccountIds": [], "distributors": "theorchard,sme,awal" } response_go = graphql.fetch_data('TopProducts', variables_go) response_insights = graphql.fetch_data('TopProductResultsQuery', variables_insights) log.info(f"Response from GO: {response_go}") log.info(f"Response from Insights: {response_insights}") go_7_days_stream_data = \ {i['productId']: i['analytics']['streams']['growthPeriods'][1]['value'] for i in response_go['topProductResults']['products']} insights_7_days_stream_data = \ {i['productId']: i['analytics']['streams']['growthPeriods'][1]['value'] for i in response_insights['topProductResults']['products']} compare_stream_data(go_7_days_stream_data, insights_7_days_stream_data, 'productID')