import allure import pytest from ui_automation_framework.utils import AppConfig from app.src.api.facade import ApiClient from app.src.helpers.api_data_provider import ApiDataProvider api = ApiClient() api.authorize() delphi_api = ApiClient() delphi_api.authorize(env="DELPHI") data_provider = ApiDataProvider(api) markets = AppConfig.get("top_markets") data = data_provider.get_sony_tracks_isrcs(market="us", ignore_response_attaching=True) tracks_count_from_top_charts = 20 isrcs = data[0][:tracks_count_from_top_charts] @pytest.mark.parametrize("isrc", isrcs) # TODO: think about this parametrization @pytest.mark.parametrize("market", markets[:2]) @allure.story("https://data-analytics.atlassian.net/browse/AG-6826") @allure.title("Amazon Streams Overview API") @allure.description("Match Amazon Streams Overview API with Delphi source") def test_streams_overview(isrc, market): date = api.dsp.get_latest_date_go(isrc, vendors="amazon") try: streams_data = delphi_api.delphi.get_streams(isrc=isrc, start_date=date, end_date=date, country_code=market)[0]["amazon_streams_info"]["selection_source_type"] except (IndexError, TypeError): streams_data = None resp_graph = api.dsp.get_dsp_api_detailed_graph_streams( "isrc={}".format(isrc), "start_date={}".format(date), "end_date={}".format(date), "market={}".format(market), "vendor=amazon", )[ "body" ]["coordinates"][ 0 ]["y"] if streams_data is None and resp_graph is None: pytest.skip("There is no data to compare. Possible side effect on the Delphi side please rerun this test in 20 minutes") assert streams_data["album"] == resp_graph["album"] assert ( streams_data["amf_station"] + streams_data["amf_station_seed"] + streams_data["custom_mix"] + streams_data["error"] + streams_data["prime_station"] + streams_data["prime_station_seed"] + streams_data["similarity"] + streams_data["similarity_station"] + streams_data["station"] + streams_data["undefined"] + streams_data["unknown"] + streams_data["unl_station_seed"] + streams_data["unlimited_station"] + streams_data["unlimited_station_se"] == resp_graph["station"] ) assert streams_data["artist"] == resp_graph["artist"] assert streams_data["search"] == resp_graph["search"] assert streams_data["auto_playlist"] + streams_data["genre"] + streams_data["recently_added"] + streams_data["recently_played"] + streams_data["user_playlist"] == resp_graph["user_playlist"] assert streams_data["gno_prime_playlist"] + streams_data["gno_unl_playlist"] + streams_data["golden_playlist"] + streams_data["prime_playlist"] + streams_data["shared_playlist"] + streams_data["unlimited_playlist"] + streams_data["personalize_playlist"] == resp_graph["playlist"] assert streams_data["songs"] + streams_data["track"] == resp_graph["songs"]