import re import unittest import allure import pytest from assertpy import assert_that from app.src.helpers.api_data_provider import ApiDataProvider from app.src.helpers.waiting_wrapper import wait from app.src.pages.chart_digest_page import ChartDigestPage from app.src.pages.login_page import LoginPage from app.src.pages.notifications_page import NotificationsPage from app.src.pages.profile_page import ProfilePage from app.src.pages.search_page import SearchPage from app.src.pages.starred_page import StarredPage from app.src.pages.track_page import TrackPage def without_time(notification_text): without_time_pattern = r".*(?:AGO|NOW|MONTH|EARLIER)\s(.*)" return re.match(without_time_pattern, notification_text).groups()[0] @pytest.mark.usefixtures("set_up", "one_time_set_up", "authorized_api") class MarketSelectionTest(unittest.TestCase): @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.profilePage = ProfilePage(self.driver) self.starredPage = StarredPage(self.driver, authorized_api) self.notificationPage = NotificationsPage(self.driver) self.chartDigest = ChartDigestPage(self.driver, authorized_api) self.data_provider = ApiDataProvider(authorized_api) self.trackPage = TrackPage(self.driver, authorized_api) @allure.story("https://data-analytics.atlassian.net/browse/AG-4758") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Verify market selection on charts screens") @allure.description("User should be able to select market and see if it is selected on charts page") @allure.testcase( "https://data-analytics.atlassian.net/browse/AG-2493," "https://data-analytics.atlassian.net/browse/AG-2495," "https://data-analytics.atlassian.net/browse/AG-2494," "https://data-analytics.atlassian.net/browse/AG-2496," "https://data-analytics.atlassian.net/browse/AG-2501," "https://data-analytics.atlassian.net/browse/AG-2700," ) @pytest.mark.smoke def test_markets_selection_charts(self): additions_markets_apple = self.data_provider.get_top_market_with_entries_for_market_selector("apple") self.loginPage.login_as_regular_user() self.profilePage.open_profile_screen_and_select_market(additions_markets_apple[0]).select_chart_digest_tab() self.chartDigest.click_exits_show_all().click_market_icon_exits() assert_that(self.chartDigest.get_market_exits_entries()).described_as("markets matching ").is_equal_to(additions_markets_apple[0]) self.chartDigest.close_popup_tap_outside().click_back_button().click_entries_show_all().click_market_icon_entries() assert_that(self.chartDigest.get_market_exits_entries()).described_as("markets matching").is_equal_to(additions_markets_apple[0]) self.chartDigest.close_popup_tap_outside().click_back_button().open_full_charts().click_filter_selection() assert_that(self.chartDigest.get_market_full_charts(), "Markets matching").is_equal_to(additions_markets_apple[0]) self.chartDigest.close_popup_tap_outside().click_back_button().select_dsp("APPLE MUSIC").click_exits_show_all().click_market_icon_exits() assert_that(self.chartDigest.get_market_exits_entries(), "markets matching").is_equal_to(additions_markets_apple[0]) self.chartDigest.close_popup_tap_outside().click_back_button().click_entries_show_all().click_market_icon_entries() assert_that(self.chartDigest.get_market_exits_entries(), "Markets matching").is_equal_to(additions_markets_apple[0]) self.chartDigest.close_popup_tap_outside().click_back_button().open_full_charts().click_filter_selection() assert_that(self.chartDigest.get_market_full_charts(), "Markets matching").is_equal_to(additions_markets_apple[0]) self.chartDigest.close_popup_tap_outside().click_back_button() self.profilePage.open_profile_screen_and_select_market(additions_markets_apple[1]).select_chart_digest_tab() self.chartDigest.click_exits_show_all().click_market_icon_exits() assert_that(self.chartDigest.get_market_exits_entries(), "markets matching").is_equal_to(additions_markets_apple[1]) self.chartDigest.close_popup_tap_outside().click_back_button().click_entries_show_all().click_market_icon_entries() assert_that(self.chartDigest.get_market_exits_entries(), "markets matching").is_equal_to(additions_markets_apple[1]) self.chartDigest.close_popup_tap_outside().click_back_button().open_full_charts().click_filter_selection() assert_that(self.chartDigest.get_market_full_charts(), "markets matching").is_equal_to(additions_markets_apple[1]) @allure.story("https://data-analytics.atlassian.net/browse/AG-4758") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Verify market selection on starred tracks screen") @allure.description("User should be able to select market and see if it is selected on starred tracks page") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-2504") @pytest.mark.smoke def test_markets_selection_starred_tracks(self): first_market = "France" second_market = "Australia" self.loginPage.login_as_notifications_user() self.profilePage.open_profile_screen_and_select_market(first_market).select_starred_tracks_tab() self.starredPage.click_market_icon() assert_that(self.starredPage.get_market(), "markets matching").is_equal_to(first_market) self.starredPage.close_market_popup_by_swipe() self.profilePage.open_profile_screen_and_select_market(second_market).select_starred_tracks_tab() self.starredPage.click_market_icon() assert_that(self.starredPage.get_market(), "markets matching").is_equal_to(second_market) @allure.story("https://data-analytics.atlassian.net/browse/AG-4758") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Verifying all starred tracks are shown for several markets from profile") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-230") @pytest.mark.smoke def test_starred_tracks_across_markets(self): first_market = "France" second_market = "Australia" third_market = "Japan" fourth_market = "Turkey" fifth_market = "United States" # TODO: add scroll to starred tracks markets = [first_market, second_market, third_market, fourth_market, fifth_market] self.loginPage.login_as_notifications_user().select_starred_tracks_tab() starred_tracks_count = self.starredPage.get_starred_tracks_count() self.starredPage.select_profile_tab() self.profilePage.open_markets() for market in markets: self.profilePage.select_market(market) self.loginPage.select_starred_tracks_tab() market_count = self.starredPage.get_starred_tracks_count() assert_that( self.starredPage.are_number_of_tracks_match(starred_tracks_count, market_count), "Numbers of starred tracks aren't matching", ).is_true() self.starredPage.select_profile_tab() self.profilePage.open_markets() @allure.story("https://data-analytics.atlassian.net/browse/AG-4758") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Verifying all user notifications present across markets") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-230") @pytest.mark.smoke def test_notifications_across_markets(self): markets = ["France", "Australia", "Japan", "Turkey", "United States"] self.loginPage.login_as_notifications_user().select_notifications_tab() notifications = [without_time(e.text) for e in wait(lambda: self.notificationPage.lt_notifications.elements)] self.starredPage.select_profile_tab() self.profilePage.open_markets() for market in markets: self.profilePage.select_market_via_search(market) self.loginPage.select_notifications_tab() notifications_market = [without_time(e.text) for e in wait(lambda: self.notificationPage.lt_notifications.elements)] assert_that(notifications_market, "Notifications are matching").is_equal_to(notifications) self.starredPage.select_profile_tab() self.profilePage.open_markets() @allure.story("https://data-analytics.atlassian.net/browse/AG-7015") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Exists/Entries after changing market") @allure.description("Market should match with selected one on navigation back") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-5357") @pytest.mark.regression def test_markets_change_entries(self): market = self.data_provider.get_top_market_with_entries_for_market_selector("spotify") tracks = self.api.apollo.get_charts_additions("spotify", "global", fields=["name", "isrc", "is_sony"])["body"]["tracks"] track_position_ui, track = next(filter(lambda x: x[1]["is_sony"], enumerate(tracks))) track_position_ui += 1 self.loginPage.login_as_regular_user().select_chart_digest_tab() self.chartDigest.click_entries_show_all().click_track_from_exits_entries(track_position_ui) self.trackPage.click_select_market_button().select_market_via_search(market[1]).click_back_button() self.chartDigest.click_market_icon_entries() assert_that(self.chartDigest.get_market_exits_entries(), "markets matching").is_equal_to(market[1]) @allure.story("https://data-analytics.atlassian.net/browse/AG-7015") @allure.severity(allure.severity_level.CRITICAL) @allure.title("Track is unavailable") @allure.description("Tack is unavailable for particular market") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-5373") @pytest.mark.regression def test_track_unavailability_for_market(self): starred_track_isrc = "SEYQ61300112" starred_track_uri = "1508025712" starred_track_name = "What Is Love" market = "Albania" try: self.data_provider.star_track_apple(starred_track_isrc, starred_track_uri) self.loginPage.login_as_regular_user().select_starred_tracks_tab() self.starredPage.click_on_starred_track(starred_track_name) self.trackPage.click_select_market_button().select_market_via_search(market) self.assertTrue(self.trackPage.is_track_unavailable_error_is_displayed(), "Track is still available") finally: self.data_provider.unstar_track(starred_track_isrc)