import unittest from datetime import datetime import allure import pytest from assertpy import assert_that from ui_automation_framework.core import TestStatus from ui_automation_framework.utils import AppConfig from app.api_client import ApiClient from app.src.pages.chart_digest import ChartDigestPage from app.src.pages.comparison_page import TrackComparisonPage from app.src.pages.login_page import LoginPage from app.src.pages.third_party.spotifycharts_page import SpotifyCharts from app.src.pages.top_charts_page import TopChartsPage from app.src.pages.track_page import TrackPage @pytest.mark.usefixtures("set_up", "one_time_set_up") class TopChartsPageTest(unittest.TestCase): us = AppConfig.get("market")["us"] @pytest.fixture(autouse=True) def classSetup(self): self.loginPage = LoginPage(self.driver) self.topChartsPage = TopChartsPage(self.driver) self.trackPage = TrackPage(self.driver) self.comparison_page = TrackComparisonPage(self.driver) self.spotify_charts = SpotifyCharts(self.driver) self.ts = TestStatus(self.driver) self.chart_digest = ChartDigestPage(self.driver) self.api_client = ApiClient() @allure.story("AP-1770") @allure.severity(allure.severity_level.NORMAL) @allure.title("Verification of new tracks and re-entry on Daily Charts and Top Chart for Spotify") @allure.description( """TC verifies that special sign is used for Spotify chart in case new tracks are entering or tracks that have already been in the chart then were removed and now entering again (Re-entry).""" ) def test_top_spotify_daily_new_and_reentry(self): self.loginPage.login_with_worker() self.loginPage.is_logged_in() self.topChartsPage.open_top_chart_page() self.topChartsPage.top_chart_page_is_opened() self.topChartsPage.select_market(self.us["name"]) self.topChartsPage.switch_tab(self.topChartsPage.SPOTIFY_TYPE) self.topChartsPage.change_sub_tab(self.topChartsPage.DAILY) # step 1-6 current_date_ui = self.topChartsPage.get_chosen_date() current_date_ui_f = datetime.strptime(current_date_ui, AppConfig.get("date_formats")["mm/dd/yy"]).strftime("%Y-%m-%d") for d in [current_date_ui_f, "2019-12-30"]: self.verify_new_and_reentered_daily_date(date=d, market=self.us) self.chart_digest.open_charts_digest_page() self.chart_digest.is_opened() mm_trends = self.chart_digest.get_position_trends_for_table("{}-table".format(self.chart_digest.MAJOR_MOVES)) self.ts.markFinal(all(str(t).isdigit() for t in mm_trends), "no newcomers in mm table") def verify_new_and_reentered_daily_date(self, date, market): d_r = str(datetime.strptime(date, "%Y-%m-%d").date()) d = datetime.strptime(d_r, "%Y-%m-%d").strftime(AppConfig.get("date_formats")["mm/dd/yy"]) self.topChartsPage.open_spotify_chart_for_date(d) ui_data_from_table = self.topChartsPage.get_all_from_table() spotify_api = self.api_client.get_charts_tracks(vendor="spotify", market=market["api"], date=date, type=self.topChartsPage.DAILY) entry_reentry_ui_tracks = [] for i, j in zip(ui_data_from_table[1]["trends"], ui_data_from_table[1]["names"]): if i == "": entry_reentry_ui_tracks.append(str(j).split("\n")[0]) self.topChartsPage.log.info("Entry and reentry tracks: " + str(entry_reentry_ui_tracks)) entry_api_tracks = [] reentry_api_tracks = [] for i in range(len(spotify_api["tracks"])): if spotify_api["tracks"][i]["is_new"] is True and spotify_api["tracks"][i]["is_re_enter"] is False: entry_api_tracks.append(spotify_api["tracks"][i]["name"]) for j in range(len(spotify_api["tracks"])): if spotify_api["tracks"][j]["is_new"] is True and spotify_api["tracks"][j]["is_re_enter"] is True: reentry_api_tracks.append(spotify_api["tracks"][j]["name"]) self.topChartsPage.log.info("Entry tracks: " + str(entry_api_tracks)) self.topChartsPage.log.info("Reentry tracks: " + str(reentry_api_tracks)) if len(entry_api_tracks) > 0: self.topChartsPage.verify_blue_dot_hover(track=entry_api_tracks[0], ui_table_tr=ui_data_from_table[1]["names"], new_reentry="new", tab="spotify") assert_that(entry_api_tracks).is_subset_of(entry_reentry_ui_tracks) if len(reentry_api_tracks) > 0: self.topChartsPage.verify_blue_dot_hover(track=reentry_api_tracks[0], ui_table_tr=ui_data_from_table[1]["names"], new_reentry="reentry", tab="spotify") assert_that(reentry_api_tracks).is_subset_of(entry_reentry_ui_tracks)