import logging import allure import pytest from assertpy import assert_that from ui_automation_framework.utils import AppConfig, CoreConfig from ui_automation_framework.utils import logger as cl from ui_automation_framework.utils.assert_utils import AssertUtils from app.src.api.facade import ApiClient from app.src.api.models.auth_model import AuthData log = cl.Logger(logging.DEBUG) markets = AppConfig.get("top_markets") api = ApiClient() api.authorize(AuthData(CoreConfig.NOTIFICATIONS_EMAIL, CoreConfig.NOTIFICATIONS_PASSWORD)) assertUtil = AssertUtils() @pytest.mark.parametrize("market", markets) @allure.story("AG-4700") @allure.severity(allure.severity_level.NORMAL) @allure.title("Verify matching between portal and go for the starred tracks data") @allure.description("Match track name, artist name and streams from /apollo-api/v1/starred-tracks/detailed/") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-4149") def test_starred_tracks_match(market): portal_track_name = [] portal_artist_name = [] portal_streams = [] go_track_name = [] go_artist_name = [] go_streams = [] total = api.apollo.get_starred_tracks_detailed("amazon,apple,spotify", market, 0, 20)["body"]["count"] api_data_with_uris = api.apollo.get_starred_tracks()["body"] for item in api_data_with_uris: assert item["uri"] != "undefined", "Wrong uri for a starred track" for offset in range(0, int(total), 20): portal = api.apollo.get_starred_tracks_detailed("amazon,apple,spotify", market, offset, 20, "true") for item in portal["body"]["items"]: portal_track_name.append(item["extra_data"]["name"]) portal_streams.append(item["streams"]) for artist in item["extra_data"]["artists"]: portal_artist_name.append(artist["name"]) for offset in range(0, int(total), 20): go = api.apollo.get_starred_tracks_detailed("amazon,apple,spotify", market, offset, 20) for item in go["body"]["items"]: go_track_name.append(item["extra_data"]["name"]) go_streams.append(item["streams"]) for artist in item["extra_data"]["artists"]: go_artist_name.append(artist["name"]) assert go_track_name == portal_track_name, "Verification failed for track names" assert go_artist_name == portal_artist_name, "Verification failed for artists names" assert go_streams == portal_streams, "Verification failed for streams" @allure.severity(allure.severity_level.NORMAL) @allure.title("Starred tracks sorting") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-11672") def test_starred_tracks_sorting(): starred_tracks = api.apollo.get_starred_tracks_detailed(vendors="amazon,apple,spotify", offset=0, limit=2000)["body"]["items"] streams_and_names = [(track["streams"], track["extra_data"]["name"]) for track in starred_tracks] sorted_tracks = sorted(streams_and_names, key=lambda x: (-x[0], x[1].lower())) assert_that(streams_and_names).is_equal_to(sorted_tracks)