import logging import unittest from contextlib import suppress import allure import pytest from assertpy import assert_that from ui_automation_framework.utils import logger as cl from app.src.api.constants import APPLE from app.src.helpers.api_data_provider import ApiDataProvider from app.src.helpers.data_formaters import DataFormatter from app.src.helpers.test_data_helper import get_random_playlist from app.src.pages.login_page import LoginPage from app.src.pages.playlist_page import PlaylistPage from app.src.pages.search_page import SearchPage from app.src.pages.track_page import TrackPage @pytest.mark.usefixtures("set_up", "one_time_set_up", "authorized_api") class PlaylistPerformanceTest(unittest.TestCase): log = cl.Logger(logging.DEBUG) @pytest.fixture(autouse=True) def classSetup(self, authorized_api): self.api = authorized_api self.loginPage = LoginPage(self.driver, authorized_api) self.searchPage = SearchPage(self.driver, authorized_api) self.trackPage = TrackPage(self.driver, authorized_api) self.playlistPage = PlaylistPage(self.driver, authorized_api) self.data_provider = ApiDataProvider(authorized_api) self.apple_test_track_data = self.data_provider.get_top_charts_apple_track_data() self.spotify_test_track_data = self.data_provider.get_top_charts_spotify_track_data() self.spotify_isrc = self.spotify_test_track_data[1] self.apple_isrc = self.apple_test_track_data[1] self.spotify_market = "global" self.apple_market = "us" self.days_period = 180 self.spotify_playlist_data = self.data_provider.get_personalized_playlist_data_full_listeners(self.spotify_isrc, self.spotify_market, self.apple_market, self.days_period) self.apple_playlist_data = self.data_provider.get_apple_playlist_data(self.apple_isrc, self.apple_market) @allure.story("https://data-analytics.atlassian.net/browse/AG-8125") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Empty states") @allure.description("Appropriate messages should be displayed in case of no data available") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-8036") @pytest.mark.smoke def test_empty_states(self): spotify_playlist_without_followers_listeners = "french shanson" spotify_playlist_without_streams = "Alla Pugacheva" apple_playlist_without_streams = "Megan Thee Stallion: Apple" self.loginPage.login_as_regular_user() self.searchPage.click_playlists_tab().search_for(spotify_playlist_without_followers_listeners).open_playlist_page_from_results(1) assert_that(self.playlistPage.is_no_performance_streams_message_shown(), "Appropriate messages isn't displayed").is_true() assert_that(self.playlistPage.is_no_performance_listeners_message_shown(), "Appropriate messages isn't displayed").is_true() self.playlistPage.click_back_button().clear_playlists_search_field() self.searchPage.search_for(spotify_playlist_without_streams).open_playlist_page_from_results(6) assert_that(self.playlistPage.is_no_performance_followers_message_shown(), "Appropriate messages isn't displayed").is_true() self.playlistPage.click_back_button().clear_playlists_search_field() self.searchPage.search_for(apple_playlist_without_streams).open_playlist_page_from_results(1) assert_that(self.playlistPage.is_no_performance_streams_message_shown(), "Appropriate messages isn't displayed").is_true() @allure.story("https://data-analytics.atlassian.net/browse/AG-8125") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Streams Performance Card. Spotify") @allure.description("Verify default state for streams performance card for Spotify") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-8033" "https://data-analytics.atlassian.net/browse/AG-8039") @pytest.mark.smoke def test_default_state_streams_spotify(self): days_period = 181 dates = self.data_provider.get_track_start_end_dates(self.spotify_isrc, days_period) playlist_id, playlist_name = get_random_playlist("spotify") daily_avg_data = self.data_provider.get_playlist_daily_avg_and_trend("spotify", dates[0], dates[1], playlist_id, self.spotify_market, days_period + 1) streams_listeners_data = self.data_provider.get_playlist_streams_listeners_and_trend(dates[0], dates[1], playlist_id, self.spotify_market) self.loginPage.login_as_regular_user() self.searchPage.click_playlists_tab().search_for(playlist_name).open_playlist_page_from_results(1) self.playlistPage.open_date_picker().select_26_weeks_date_filter() streams_card_data = self.playlistPage.get_streams_performance_card_data() start_date = DataFormatter.format_api_to_ui_dates(str(dates[0])) end_date = DataFormatter.format_api_to_ui_dates(str(dates[1])) daily_avg_streams = str(DataFormatter.round_streams(daily_avg_data[0])) # Dates, market, daily avg assert_that(self.playlistPage.is_user_market_on_performance_section(self.spotify_market), "Selected market is wrong").is_true() assert_that(streams_card_data, "Streams card data").described_as("Start date").contains(start_date).described_as("End date").contains(end_date).described_as("Daily average").contains(daily_avg_streams) if daily_avg_data[1]: daily_avg_trend = str(DataFormatter.round_streams_trend(abs(round(daily_avg_data[1])))) daily_avg_trend_with_direction = daily_avg_data[1] assert_that(streams_card_data, "Daily average trend").contains(daily_avg_trend) if daily_avg_trend_with_direction >= 0.5: icon = "\ue902" elif daily_avg_trend_with_direction < 0: icon = "\ue905" elif daily_avg_trend_with_direction >= 0: icon = "\ue904" assert_that(streams_card_data).contains(icon) self.log.info(streams_listeners_data[0]) streams_listeners = str(DataFormatter.round_listeners(streams_listeners_data[0])) if streams_listeners.endswith(".0"): streams_listeners = streams_listeners.replace(".0", "") streams_listeners_trend_with_direction = streams_listeners_data[1] # Streams listeners assert_that(streams_card_data, "Streams/listeners value ").contains(streams_listeners) if streams_listeners_trend_with_direction: streams_listeners_trend = str(DataFormatter.round_streams_trend(abs(round(streams_listeners_trend_with_direction)))) assert_that(streams_card_data, "Streams/listeners trend").contains(streams_listeners_trend) if streams_listeners_trend_with_direction > 0: icon = "\ue902" elif streams_listeners_trend_with_direction < 0: icon = "\ue905" elif streams_listeners_trend_with_direction == 0: icon = "\ue904" assert_that(streams_card_data).contains(icon) @allure.story("https://data-analytics.atlassian.net/browse/AG-8125") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Streams Performance Card. Apple") @allure.description("Verify default state for streams performance card for Apple") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-8034" "https://data-analytics.atlassian.net/browse/AG-8039") @pytest.mark.smoke def test_default_state_streams_apple(self): days_period = 13 dates = self.data_provider.get_track_start_end_dates(self.apple_isrc, days_period) playlist_id, playlist_name = get_random_playlist("apple") daily_avg_data = self.data_provider.get_playlist_daily_avg_and_trend("apple", dates[0], dates[1], playlist_id, self.apple_market, days_period + 1) playlist_position = next(filter(lambda x: x.vendor == APPLE, self.api.apollo.get_playlist_search_results(playlist_name))).position self.loginPage.login_as_regular_user() self.searchPage.click_playlists_tab().search_for(playlist_name).open_playlist_page_from_results(playlist_position) streams_card_data = self.playlistPage.get_streams_performance_card_data() start_date = DataFormatter.format_api_to_ui_dates(str(dates[0])) end_date = DataFormatter.format_api_to_ui_dates(str(dates[1])) daily_avg_streams = str(DataFormatter.round_streams(daily_avg_data[0])) # Dates, market, daily avg assert_that(streams_card_data).described_as("Start date").contains(start_date).described_as("End date").contains(end_date).described_as("Daily average").contains(daily_avg_streams) if daily_avg_data[1]: daily_avg_trend = str(DataFormatter.round_streams_trend(abs(round(daily_avg_data[1])))) daily_avg_trend_with_direction = int(daily_avg_data[1]) assert_that(streams_card_data, "Daily average trend").contains(daily_avg_trend) if daily_avg_trend_with_direction > 0: icon = "\ue902" elif daily_avg_trend_with_direction < 0: icon = "\ue905" elif daily_avg_trend_with_direction == 0: icon = "\ue904" assert_that(streams_card_data).contains(icon) @allure.story("https://data-analytics.atlassian.net/browse/AG-8125") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Listeners Performance Card") @allure.description("Verify default state for listeners performance card") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-8061" "https://data-analytics.atlassian.net/browse/AG-8062") @pytest.mark.smoke def test_default_state_listeners(self): days_period = 181 dates = self.data_provider.get_track_start_end_dates(self.spotify_isrc, days_period) playlist_name = self.spotify_playlist_data[0] playlist_id = self.spotify_playlist_data[1] daily_avg_data = self.data_provider.get_playlist_listeners_daily_avg_and_trend(playlist_id, dates[0], dates[1], self.spotify_market, days_period + 1) # ADD period selection self.loginPage.login_as_regular_user() self.searchPage.click_playlists_tab().search_for(playlist_name).open_playlist_page_from_results(1) self.playlistPage.open_date_picker().select_26_weeks_date_filter() listeners_card_data = self.playlistPage.get_listeners_performance_card_data() start_date = DataFormatter.format_api_to_ui_dates(str(dates[0])) end_date = DataFormatter.format_api_to_ui_dates(str(dates[1])) daily_avg = str(DataFormatter.round_streams(daily_avg_data[0])) # Dates, market, daily avg assert_that(listeners_card_data).described_as("Start date").contains(start_date).described_as("End date").contains(end_date).described_as("Daily average").contains(daily_avg) if daily_avg_data[1]: daily_avg_trend = str(DataFormatter.round_streams_trend(abs(round(daily_avg_data[1])))) daily_avg_trend_with_direction = int(daily_avg_data[1]) assert_that(listeners_card_data, "Daily average trend ").contains(daily_avg_trend) if daily_avg_trend_with_direction > 0: icon = "\ue902" elif daily_avg_trend_with_direction < 0: icon = "\ue905" elif daily_avg_trend_with_direction == 0: icon = "\ue904" assert_that(listeners_card_data).contains(icon) @allure.story("https://data-analytics.atlassian.net/browse/AG-8125") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Followers Performance Card") @allure.description("Verify default state for followers performance card") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-8061" "https://data-analytics.atlassian.net/browse/AG-8062") @pytest.mark.smoke def test_default_state_followers(self): days_period = 27 dates = self.data_provider.get_track_start_end_dates(self.spotify_isrc, days_period) playlist_name = self.spotify_playlist_data[0] playlist_id = self.spotify_playlist_data[1] daily_avg_data = self.data_provider.get_playlist_followers_daily_avg_trend_last_total(playlist_id, dates[0], dates[1], self.spotify_market, days_period + 1) # ADD period selection self.loginPage.login_as_regular_user() self.searchPage.click_playlists_tab().search_for(playlist_name).open_playlist_page_from_results(1) self.playlistPage.open_date_picker().select_4_weeks_date_filter() followers_card_data = self.playlistPage.get_followers_performance_card_data() start_date = DataFormatter.format_api_to_ui_dates(str(dates[0])) end_date = DataFormatter.format_api_to_ui_dates(str(dates[1])) if daily_avg_data[0] < 100: daily_avg = str(int(float(DataFormatter.round_listeners(daily_avg_data[0])))) else: daily_avg = str(DataFormatter.round_listeners(daily_avg_data[0])) last_total = str(DataFormatter.round_listeners(daily_avg_data[2])) # Dates, market, daily avg assert_that(followers_card_data).described_as("Start date").contains(start_date).described_as("End date").contains(end_date).described_as("Daily average").contains(daily_avg).described_as("Last total").contains(last_total) if daily_avg_data[1]: daily_avg_trend = str(DataFormatter.round_streams_trend(abs(round(daily_avg_data[1])))) daily_avg_trend_with_direction = int(daily_avg_data[1]) assert_that(followers_card_data, "Daily average trend").contains(daily_avg_trend) if daily_avg_trend_with_direction > 0: icon = "\ue902" elif daily_avg_trend_with_direction < 0: icon = "\ue905" elif daily_avg_trend_with_direction == 0: icon = "\ue904" assert_that(followers_card_data).contains(icon) @allure.story("https://data-analytics.atlassian.net/browse/AG-8131") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Date picker") @allure.description("User should be able to change dates on graphs") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-8106" "https://data-analytics.atlassian.net/browse/AG-8105" "https://data-analytics.atlassian.net/browse/AG-8103") @pytest.mark.smoke # @pytest.mark.skip("Valid locator that cannot be found. Need to investigate") def test_date_picker_range_options(self): days_period = 13 playlist_name = self.apple_playlist_data[0] playlist_position = next(filter(lambda x: x.vendor == APPLE, self.api.apollo.get_playlist_search_results(playlist_name))).position dates = self.data_provider.get_track_start_end_dates(self.apple_isrc, days_period) self.loginPage.login_as_regular_user() self.searchPage.click_playlists_tab().search_for(playlist_name).open_playlist_page_from_results(playlist_position) assert_that(self.playlistPage.open_date_picker().is_date_picker_opened_playlist(), "Date picker popup is opened").is_true() self.playlistPage.select_4_weeks_date_filter_without_click() self.playlistPage.close_popup_by_swipe() streams_card_data = self.playlistPage.get_streams_performance_card_data() start_date = DataFormatter.format_api_to_ui_dates(str(dates[0])) end_date = DataFormatter.format_api_to_ui_dates(str(dates[1])) # Test the default dates, and checking that the button "Done" was not clicked assert_that(streams_card_data, "Dates matching").contains(start_date).contains(end_date) # Changing the period with clicking button "Done" days_period = 27 dates = self.data_provider.get_track_start_end_dates(self.apple_isrc, days_period) start_date = DataFormatter.format_api_to_ui_dates(str(dates[0])) end_date = DataFormatter.format_api_to_ui_dates(str(dates[1])) assert_that(self.playlistPage.open_date_picker().is_date_picker_opened_playlist(), "Date picker popup is opened").is_true() self.playlistPage.select_4_weeks_date_filter() self.playlistPage.close_popup_by_swipe() streams_card_data = self.playlistPage.get_streams_performance_card_data() # Test dates assert_that(streams_card_data, "Dates matching").contains(start_date).contains(end_date) @allure.story("https://data-analytics.atlassian.net/browse/AG-8131") @allure.severity(allure.severity_level.CRITICAL) @allure.title("List of markets") @allure.description("User should be able to change market for Spotify playlist") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-8118" "https://data-analytics.atlassian.net/browse/AG-8115") @pytest.mark.smoke def test_market_selector(self): days_period = 13 new_market = ["Spain", "es"] dates = self.data_provider.get_track_start_end_dates(self.spotify_isrc, days_period) playlist_name = self.spotify_playlist_data[0] playlist_id = self.spotify_playlist_data[1] daily_avg_data = self.data_provider.get_playlist_followers_daily_avg_trend_last_total(playlist_id, dates[0], dates[1], self.spotify_market, days_period + 1) daily_avg = str(DataFormatter.round_listeners(daily_avg_data[0])) self.loginPage.login_as_regular_user() self.searchPage.click_playlists_tab().search_for(playlist_name).open_playlist_page_from_results(1) self.playlistPage.open_markets().click_markets_cancel() followers_card_data = self.playlistPage.get_followers_performance_card_data() assert_that(followers_card_data, "Daily average").contains(daily_avg) self.playlistPage.open_markets().select_market_via_search(new_market[0]) assert_that(self.playlistPage.is_user_market_on_performance_section(new_market[1])).is_true() daily_avg_data = self.data_provider.get_playlist_followers_daily_avg_trend_last_total(playlist_id, dates[0], dates[1], new_market[1], days_period + 1) daily_avg = str(DataFormatter.round_listeners(daily_avg_data[0])) followers_card_data = self.playlistPage.get_followers_performance_card_data() assert_that(followers_card_data, "Daily average").contains(daily_avg) @allure.story("https://data-analytics.atlassian.net/browse/AG-8131") @allure.severity(allure.severity_level.NORMAL) @allure.title("i popups opening/closing mode") @allure.description("User should be able to open and close info popups on the playlist page") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-8079," "https://data-analytics.atlassian.net/browse/AG-8078,") @pytest.mark.smoke def test_playlists_popup(self): playlist_name = self.apple_playlist_data[0] self.loginPage.login_as_regular_user() self.searchPage.click_playlists_tab().search_for(playlist_name).open_playlist_page_from_results(1) self.playlistPage.open_playlists_popup() assert_that(self.playlistPage.is_playlists_popup_opened(), "Info popup is opened").is_true() self.playlistPage.close_popup_by_swipe() assert_that(self.playlistPage.is_playlists_text_popup_opened(), "Info popup is opened").is_false() @allure.story("https://data-analytics.atlassian.net/browse/AG-8128") @allure.severity(allure.severity_level.NORMAL) @allure.title("Streams detailed view") @allure.description("User should be able to open streams graphs detailed view in a landscape mode.") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-8071," "https://data-analytics.atlassian.net/browse/AG-8072,") @pytest.mark.smoke def test_streams_detailed_spotify(self): days_period = 13 new_market = ["United States", "US"] dates = self.data_provider.get_track_start_end_dates(self.spotify_isrc, days_period) playlist_name = self.spotify_playlist_data[0] playlist_id = self.spotify_playlist_data[1] streams_api_data = self.api.dsp.get_analytics_v1_playlists_streams_graph( "vendor=spotify", f"start_date={dates[0]}", f"end_date={dates[1]}", f"markets={self.spotify_market}," f"{new_market[1]}", f"playlist_id={playlist_id}", )[ "body" ]["items"] coord_data = {} for i in streams_api_data: if i["country_code"] == "_gl": coord_data = i["coordinates"] coord_data_us = {} for i in streams_api_data: if i["country_code"] == new_market[1].lower(): coord_data_us = i["coordinates"] list_data = [i["y"] for i in coord_data] data_formatted = [str(DataFormatter.round_streams(i)) for i in list_data] list_data_us = [i["y"] for i in coord_data_us] percent_of_global = list_data_us[0] / list_data[0] * 100 max_y = max(list_data) + 0.05 * max(list_data) y_axis_top_value = str(DataFormatter.round_streams(round(max_y))) self.loginPage.login_as_regular_user() self.searchPage.click_playlists_tab().search_for(playlist_name).open_playlist_page_from_results(1) streams_card_data_default = self.playlistPage.get_streams_performance_card_data_dates() self.playlistPage.click_streams_detailed_button() assert_that(self.playlistPage.is_streams_detailed_graphs_opened(), "Detailed view graph did not open").is_true() streams_card_data_detailed = self.playlistPage.get_spotify_streams_performance_card_detailed_data() assert_that(streams_card_data_detailed).described_as("The starting date").contains(streams_card_data_default[0]).described_as("The ending date ").contains(streams_card_data_default[1]).described_as("Y-axis value").contains(y_axis_top_value) self.playlistPage.click_performance_detailed_graph() stream_value = self.playlistPage.get_daily_value_from_detailed_view() assert_that(data_formatted, "Stream value").contains(stream_value) self.playlistPage.close_graph_detailed_view() assert_that(self.playlistPage.is_detailed_view_graph_closed(), "Detailed view did not close").is_true() self.playlistPage.open_markets().select_market_via_search(new_market[0]) assert_that(self.playlistPage.is_user_market_on_performance_section(new_market[1])).is_true() self.playlistPage.click_streams_detailed_button() assert_that(self.playlistPage.is_streams_detailed_graphs_opened(), "Detailed view graph did not open").is_true() assert_that(self.playlistPage.is_market_indicator_displayed(new_market[1]), "Market indicator isn't displayed").is_true() self.playlistPage.click_performance_detailed_graph() assert_that(self.playlistPage.is_percent_of_global_displayed(), "% of Global message isn't displayed").is_true() percent_of_total_ui = self.playlistPage.get_percent_of_total_value() assert_that(percent_of_total_ui, "% of Global").contains(str(round(percent_of_global))) @allure.story("https://data-analytics.atlassian.net/browse/AG-8128") @allure.severity(allure.severity_level.NORMAL) @allure.title("Streams detailed view for Apple") @allure.description("User should be able to open streams graphs detailed view in a landscape mode.") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-8071," "https://data-analytics.atlassian.net/browse/AG-8072,") @pytest.mark.smoke def test_streams_detailed_apple(self): days_period = 13 dates = self.data_provider.get_track_start_end_dates(self.apple_isrc, days_period) playlist_id, playlist_name = get_random_playlist("apple") playlist_position = next(filter(lambda x: x.vendor == APPLE, self.api.apollo.get_playlist_search_results(playlist_name))).position self.log.info(playlist_name) new_market = ["United States", "US"] streams_api_data = self.api.dsp.get_analytics_v1_playlists_streams_graph( "vendor=apple", f"start_date={dates[0]}", f"end_date={dates[1]}", f"markets={self.apple_market}", f"{new_market[1]}", f"playlist_id={playlist_id}", )[ "body" ]["items"] coord_data_us = {} for i in streams_api_data: if i["country_code"] == new_market[1].lower(): coord_data_us = i["coordinates"] list_data_us = [i["y"] for i in coord_data_us if i["y"] is not None] max_y = max(list_data_us) + 0.05 * max(list_data_us) y_axis_top_value = str(DataFormatter.round_streams(round(max_y))) data_formatted = [str(DataFormatter.round_streams(i)) for i in list_data_us] self.loginPage.login_as_regular_user() self.searchPage.click_playlists_tab().search_for(playlist_name).open_playlist_page_from_results(playlist_position) streams_card_data_default = self.playlistPage.get_streams_performance_card_data_dates() self.playlistPage.click_streams_detailed_button() assert_that(self.playlistPage.is_streams_detailed_graphs_opened(), "Detailed view graph did not open").is_true() streams_card_data_detailed = self.playlistPage.get_apple_streams_performance_card_detailed_data() assert_that(streams_card_data_detailed).described_as("The starting date").contains(streams_card_data_default[0]).described_as("The ending date ").contains(streams_card_data_default[1]).described_as("Y-axis value").contains(y_axis_top_value) self.playlistPage.click_performance_detailed_graph() stream_value = self.playlistPage.get_daily_value_from_detailed_view() assert_that(data_formatted, "Value matching").contains(stream_value) self.playlistPage.close_graph_detailed_view() assert_that(self.playlistPage.is_detailed_view_graph_closed(), "Detailed view did not close").is_true() @allure.story("https://data-analytics.atlassian.net/browse/AG-8130") @allure.severity(allure.severity_level.NORMAL) @allure.title("Followers detailed view") @allure.description("User should be able to open followers graphs detailed view in a landscape mode.") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-8097," "https://data-analytics.atlassian.net/browse/AG-8098,") @pytest.mark.smoke def test_followers_detailed_spotify(self): days_period = 55 dates = self.data_provider.get_track_start_end_dates(self.spotify_isrc, days_period) playlist_name = self.spotify_playlist_data[0] playlist_id = self.spotify_playlist_data[1] followers_api_data = self.api.apollo.get_v1_spotify_playlists_followers_graph( "vendor=spotify", f"start_date={dates[0]}", f"end_date={dates[1]}", f"markets={self.spotify_market}", f"id={playlist_id}", ) coord_data = followers_api_data["body"]["items"][0]["coordinates"] list_data = [i["y"] for i in coord_data if i["y"] is not None] data_formatted = [str(DataFormatter.round_streams(i)) for i in list_data] max_y = max(list_data) + 0.05 * max(list_data) y_axis_top_value = str(DataFormatter.round_streams(max_y)) self.loginPage.login_as_regular_user() self.searchPage.click_playlists_tab().search_for(playlist_name).open_playlist_page_from_results(1) self.playlistPage.open_date_picker().select_8_weeks_date_filter() followers_card_data_default = self.playlistPage.get_followers_performance_card_data_dates() self.playlistPage.click_followers_detailed_button() assert_that(self.playlistPage.is_followers_detailed_graphs_opened(), "Detailed view graph did not open").is_true() followers_card_data_detailed = self.playlistPage.get_followers_performance_card_detailed_data() assert_that(followers_card_data_detailed).described_as("The starting date").contains(followers_card_data_default[0]).described_as("The ending date").contains(followers_card_data_default[1]).described_as("Y-axis value").contains(y_axis_top_value) self.playlistPage.click_performance_detailed_graph() stream_value = self.playlistPage.get_daily_value_from_detailed_view() assert_that(data_formatted, "Value matching").contains(stream_value) self.playlistPage.close_graph_detailed_view() assert_that(self.playlistPage.is_detailed_view_graph_closed(), "Detailed view did not close").is_true() @allure.story("https://data-analytics.atlassian.net/browse/AG-8129") @allure.severity(allure.severity_level.NORMAL) @allure.title("Listeners detailed view") @allure.description("User should be able to open listeners graphs detailed view in a landscape mode.") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-8089," "https://data-analytics.atlassian.net/browse/AG-8090,") @pytest.mark.smoke def test_listeners_detailed_spotify(self): days_period = 181 new_market = ["United States", "US"] dates = self.data_provider.get_track_start_end_dates(self.spotify_isrc, days_period) playlist_id, playlist_name = get_random_playlist("spotify") # Example of few listeners playlist: # playlist_name = "This is LAY" # playlist_id = "37i9dQZF1DZ06evO2zgcdy" listeners_api_data = self.api.apollo.get_v1_spotify_playlists_listeners_graph("spotify", dates[0], dates[1], f"{self.spotify_market},{new_market[1]}", playlist_id).items for listeners_graph in listeners_api_data: if listeners_graph.country_code == "_gl": coord_data = listeners_graph.coordinates coord_data_us = {} for listeners_graph in listeners_api_data: if listeners_graph.country_code == new_market[1].lower(): coord_data_us = listeners_graph.coordinates list_data = [i.y for i in coord_data if i.y] list_data_round = [DataFormatter.round_listeners(i) for i in list_data] # Converting the current number of listeners to the integer format for a correct comparison; # The "list_data_round" contains available values of listeners for a given date range. # The exception is checking if the last value in the listener's data is without rounding extensions # (e.g. "k", "m"). try: list_data_round[-1] = int(float(list_data_round[-1])) data_formatted = [str(i) for i in list_data_round] except Exception as e: print(e) data_formatted = [str(i) for i in list_data_round] list_data_us = [i.y for i in coord_data_us] list_data_round_us = [DataFormatter.round_listeners(i) for i in list_data_us if i is not None] percent_of_global = None if list_data_us[0] and list_data[0]: percent_of_global = list_data_us[0] / list_data[0] * 100 with suppress(Exception): list_data_round_us[-1] = int(float(list_data_round_us[-1])) data_formatted_us = [str(i) for i in list_data_round_us] max_y = max(list_data) + 0.05 * max(list_data) y_axis_top_value = str(DataFormatter.round_listeners(max_y)) self.loginPage.login_as_regular_user() self.searchPage.click_playlists_tab().search_for(playlist_name).open_playlist_page_from_results_by_text(playlist_name) self.playlistPage.open_date_picker().select_26_weeks_date_filter() listeners_card_data_default = self.playlistPage.get_listeners_performance_card_data_dates() self.playlistPage.click_listeners_detailed_button() assert_that(self.playlistPage.is_listeners_detailed_graphs_opened(), "Detailed view graph did not open").is_true() listeners_card_data_detailed = self.playlistPage.get_listeners_performance_card_detailed_data() assert_that(listeners_card_data_detailed).described_as("The starting date").contains(listeners_card_data_default[0]).described_as("The ending date").contains(listeners_card_data_default[1]).described_as("Y-axis value ").contains(y_axis_top_value) self.playlistPage.click_listeners_detailed_graph() listeners_value = self.playlistPage.get_daily_value_from_detailed_view() assert_that(data_formatted, "Listeners value matching").contains(listeners_value) self.playlistPage.close_graph_detailed_view() assert_that(self.playlistPage.is_detailed_view_graph_closed(), "Detailed view did not close").is_true() self.playlistPage.open_markets().select_market_via_search(new_market[0]) assert_that(self.playlistPage.is_user_market_on_performance_section(new_market[1])).is_true() self.playlistPage.click_listeners_detailed_button().click_listeners_detailed_graph() listeners_value_us = self.playlistPage.get_daily_value_from_detailed_view() assert_that(data_formatted_us).contains(str(listeners_value_us)) assert_that(self.playlistPage.is_listeners_detailed_graphs_opened(), "Detailed view graph did not open").is_true() assert_that(self.playlistPage.is_listeners_market_indicator_displayed(new_market[1]), "Market indicator isn't displayed").is_true() if percent_of_global: self.playlistPage.click_performance_detailed_graph() assert_that(self.playlistPage.is_percent_of_global_displayed(), "% of Global message isn't displayed").is_true() percent_of_total_ui = self.playlistPage.get_percent_of_total_value() assert_that(percent_of_total_ui, "% of Global").contains(str(round(percent_of_global)))