import logging import allure import pytest from ui_automation_framework.utils import AppConfig from ui_automation_framework.utils import logger as cl from app.src.api.facade import ApiClient from app.src.helpers.api_data_provider import ApiDataProvider log = cl.Logger(logging.DEBUG) api = ApiClient() api.authorize() data_provider = ApiDataProvider(api) data_spotify = data_provider.get_sony_tracks_isrcs("spotify", "us", ignore_response_attaching=True) tracks_count_from_top_charts = 20 isrcs = data_spotify[0][:tracks_count_from_top_charts] markets = AppConfig.get("top_markets") @pytest.mark.parametrize("market", markets) @allure.story("AG-7774") @allure.severity(allure.severity_level.NORMAL) @allure.title("Weekly streams vs. starred tracks") def test_starred_tracks_and_weekly_streams_match(market): top_isrcs = data_spotify[0][:tracks_count_from_top_charts] ids = data_spotify[1][:tracks_count_from_top_charts] try: for i in range(len(ids)): api.apollo.post_v1_starred_tracks_spotify(top_isrcs[i], ids[i]) starred_tracks_data = api.apollo.get_starred_tracks_detailed("amazon,apple,spotify", market, limit=40)["body"]["items"] starred_tracks_streams = {i["isrc"]: i["streams"] for i in starred_tracks_data} for isrc, streams in starred_tracks_streams.items(): weekly_data = api.dsp.get_weekly_streams_count(f"isrc={isrc}", f"market={market}")["body"]["market_streams"]["current_week"] assert streams == weekly_data, "Streams don't match" finally: for i in range(len(ids)): api.apollo.delete_v1_starred_tracks(isrcs[i]) @pytest.mark.parametrize("isrc", isrcs) @pytest.mark.parametrize("market", markets) @allure.story("AG-7774") @allure.severity(allure.severity_level.NORMAL) @allure.title("Stream graph vs. last day") def test_streams_graph_and_last_day(isrc, market): # Accrodingly to last date logic we show streams from the same day but a week ago dates = data_provider.get_track_start_end_dates(isrc, 7) graph_data_market = api.dsp.get_dsp_api_streams_graph(f"isrc={isrc}", f"market={market}", f"start_date={dates[0]}", f"end_date={dates[1]}", "per_vendors=true")["body"]["coordinates"] graph_data_global = api.dsp.get_dsp_api_streams_graph(f"isrc={isrc}", f"start_date={dates[0]}", f"end_date={dates[1]}", "per_vendors=true")["body"]["coordinates"] daily_weekly_data = api.dsp.get_daily_and_weekly_streams_count(f"isrc={isrc}", f"market={market}")["body"] if graph_data_global[0]["y"]: assert daily_weekly_data["global_streams"]["prev_day"] == graph_data_global[0]["y"], "Streams don't match for previous day" assert daily_weekly_data["global_streams"]["current_day"] == graph_data_global[-1]["y"], "Streams don't match for current date" if graph_data_market[0]["y"]: assert daily_weekly_data["market_streams"]["prev_day"] == graph_data_market[0]["y"], "Streams don't match for previous day" assert daily_weekly_data["market_streams"]["current_day"] == graph_data_market[-1]["y"], "Streams don't match for current date" @pytest.mark.parametrize("isrc", isrcs) @pytest.mark.parametrize("market", markets) @allure.story("AG-7774") @allure.severity(allure.severity_level.NORMAL) @allure.title("Stream graph vs. streams monitoring") def test_streams_graph_and_streams_monitoring(isrc, market): dates = data_provider.get_track_start_end_dates(isrc, 0) graph_data_market = api.dsp.get_dsp_api_streams_graph(f"isrc={isrc}", f"market={market}", f"start_date={dates[0]}", f"end_date={dates[1]}", "per_vendors=true")["body"] graph_data_global = api.dsp.get_dsp_api_streams_graph(f"isrc={isrc}", f"start_date={dates[0]}", f"end_date={dates[1]}", "per_vendors=true")["body"] stream_monitoring = api.dsp.get_dsp_api_streams_monitoring(f"isrc={isrc}", f"start_date={dates[0]}", f"end_date={dates[1]}")["body"] stream_monitoring_market = api.dsp.get_dsp_api_streams_monitoring(f"isrc={isrc}", f"start_date={dates[0]}", f"end_date={dates[1]}", f"market={market}")["body"] if stream_monitoring["spotify"]: assert stream_monitoring["spotify"]["lean_back"] + stream_monitoring["spotify"]["lean_forward"] == graph_data_global["vendors"]["spotify"][-1]["y"], "Streams don't match for current date" if stream_monitoring["apple"]: assert stream_monitoring["apple"]["lean_back"] + stream_monitoring["apple"]["lean_forward"] == graph_data_global["vendors"]["apple"][-1]["y"], "Streams don't match for current date" if stream_monitoring["amazon"]: assert stream_monitoring["amazon"]["lean_back"] + stream_monitoring["amazon"]["lean_forward"] == graph_data_global["vendors"]["amazon"][-1]["y"], "Streams don't match for current date" if stream_monitoring_market["spotify"]: assert stream_monitoring_market["spotify"]["lean_back"] + stream_monitoring_market["spotify"]["lean_forward"] == graph_data_market["vendors"]["spotify"][-1]["y"], "Streams don't match for current date" if stream_monitoring_market["apple"]: assert stream_monitoring_market["apple"]["lean_back"] + stream_monitoring_market["apple"]["lean_forward"] == graph_data_market["vendors"]["apple"][-1]["y"], "Streams don't match for current date" if stream_monitoring_market["amazon"]: assert stream_monitoring_market["amazon"]["lean_back"] + stream_monitoring_market["amazon"]["lean_forward"] == graph_data_market["vendors"]["amazon"][-1]["y"], "Streams don't match for current date" @pytest.mark.parametrize("isrc", isrcs) @pytest.mark.parametrize("market", markets) @allure.story("AG-7774") @allure.severity(allure.severity_level.NORMAL) @allure.title("Stream graph vs. detailed graph") def test_streams_graph_and_detailed_graph(isrc, market): dates = data_provider.get_track_start_end_dates(isrc, 1) graph_data_market = api.dsp.get_dsp_api_streams_graph(f"isrc={isrc}", f"market={market}", f"start_date={dates[0]}", f"end_date={dates[0]}", "per_vendors=true")["body"] graph_data_global = api.dsp.get_dsp_api_streams_graph(f"isrc={isrc}", f"start_date={dates[0]}", f"end_date={dates[0]}", "per_vendors=true")["body"] detailed_streams_global_spotify = api.dsp.get_dsp_api_detailed_graph_streams(f"isrc={isrc}", f"start_date={dates[0]}", f"end_date={dates[0]}", "market=global", "vendor=spotify")["body"]["coordinates"] detailed_streams_global_apple = api.dsp.get_dsp_api_detailed_graph_streams(f"isrc={isrc}", f"start_date={dates[0]}", f"end_date={dates[0]}", "market=global", "vendor=apple")["body"]["coordinates"] detailed_streams_global_amazon = api.dsp.get_dsp_api_detailed_graph_streams(f"isrc={isrc}", f"start_date={dates[0]}", f"end_date={dates[0]}", "market=global", "vendor=amazon")["body"]["coordinates"] detailed_streams_market_spotify = api.dsp.get_dsp_api_detailed_graph_streams(f"isrc={isrc}", f"start_date={dates[0]}", f"end_date={dates[0]}", f"market={market}", "vendor=spotify")["body"]["coordinates"] detailed_streams_market_apple = api.dsp.get_dsp_api_detailed_graph_streams(f"isrc={isrc}", f"start_date={dates[0]}", f"end_date={dates[0]}", f"market={market}", "vendor=apple")["body"]["coordinates"] detailed_streams_market_amazon = api.dsp.get_dsp_api_detailed_graph_streams(f"isrc={isrc}", f"start_date={dates[0]}", f"end_date={dates[0]}", f"market={market}", "vendor=amazon")["body"]["coordinates"] if detailed_streams_global_spotify[0]["y"]: assert detailed_streams_global_spotify[0]["y"]["total"] == graph_data_global["vendors"]["spotify"][-1]["y"], "Streams don't match for current date" if detailed_streams_global_apple[0]["y"]: assert detailed_streams_global_apple[0]["y"]["total"] == graph_data_global["vendors"]["apple"][-1]["y"], "Streams don't match for current date" if detailed_streams_global_amazon[0]["y"]: assert detailed_streams_global_amazon[0]["y"]["total"] == graph_data_global["vendors"]["amazon"][-1]["y"], "Streams don't match for current date" if detailed_streams_market_spotify[0]["y"]: assert detailed_streams_market_spotify[0]["y"]["total"] == graph_data_market["vendors"]["spotify"][-1]["y"], "Streams don't match for current date" if detailed_streams_market_apple[0]["y"]: assert detailed_streams_market_apple[0]["y"]["total"] == graph_data_market["vendors"]["apple"][-1]["y"], "Streams don't match for current date" if detailed_streams_market_amazon[0]["y"]: assert detailed_streams_market_amazon[0]["y"]["total"] == graph_data_market["vendors"]["amazon"][-1]["y"], "Streams don't match for current date" @pytest.mark.parametrize("isrc", isrcs) @pytest.mark.parametrize("market", markets) @allure.story("AG-7774") @allure.severity(allure.severity_level.NORMAL) @allure.title("Demographics vs. streams monitoring") def test_demographics_and_streams_monitoring(isrc, market): dates = data_provider.get_track_start_end_dates(isrc, 0) spotify_demographics = api.dsp.get_spotify_demographics_delphi(isrc, str(dates[0]), str(dates[1]), "global")["body"] apple_demographics = api.dsp.get_apple_demographics_delphi(isrc, str(dates[0]), str(dates[1]), "global")["body"] spotify_demographics_market = api.dsp.get_spotify_demographics_delphi(isrc, str(dates[0]), str(dates[1]), f"{market}")["body"] apple_demographics_market = api.dsp.get_apple_demographics_delphi(isrc, str(dates[0]), str(dates[1]), f"{market}")["body"] stream_monitoring = api.dsp.get_dsp_api_streams_monitoring(f"isrc={isrc}", f"start_date={dates[0]}", f"end_date={dates[1]}")["body"] stream_monitoring_market = api.dsp.get_dsp_api_streams_monitoring(f"isrc={isrc}", f"start_date={dates[0]}", f"end_date={dates[1]}", f"market={market}")["body"] if stream_monitoring["spotify"]: assert stream_monitoring["spotify"]["lean_back"] + stream_monitoring["spotify"]["lean_forward"] == spotify_demographics[0]["streams"], "Streams don't match for current date" if stream_monitoring["apple"]: assert stream_monitoring["apple"]["lean_back"] + stream_monitoring["apple"]["lean_forward"] == apple_demographics[0]["streams"], "Streams don't match for current date" if stream_monitoring_market["spotify"]: assert stream_monitoring_market["spotify"]["lean_back"] + stream_monitoring_market["spotify"]["lean_forward"] == spotify_demographics_market[0]["streams"], "Streams don't match for current date" if stream_monitoring_market["apple"]: assert stream_monitoring_market["apple"]["lean_back"] + stream_monitoring_market["apple"]["lean_forward"] == apple_demographics_market[0]["streams"], "Streams don't match for current date"