import datetime import logging import unittest import allure import pytest from assertpy import assert_that from ui_automation_framework.core import TestStatus from ui_automation_framework.utils import AppConfig from ui_automation_framework.utils import logger as cl from app.api_client import ApiClient from app.src.pages.chart_digest import ChartDigestPage from app.src.pages.login_page import LoginPage 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): log = cl.Logger(logging.DEBUG) 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.chart_digest = ChartDigestPage(self.driver) self.api_client = ApiClient() self.ts = TestStatus(self.driver) @pytest.mark.flaky(reruns=0) @pytest.mark.timeout(300) @allure.story("AP-1772") @allure.severity(allure.severity_level.NORMAL) @allure.title("Signify songs re-entering Apple charts not for the first time") @allure.description( """TC verifies that a user is able to distinguish new tracks quickly and identify newcomers in the scope of tracks that just did a major move. """ ) def test_top_apple_reentered(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.APPLE_TYPE) # step 1-5 self.verify_new_and_reentered_apple(self.us["api"]) def verify_new_and_reentered_apple(self, market): ui_data_from_table = self.topChartsPage.get_all_from_table_apple() 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]) chart_date = datetime.datetime.strptime(self.topChartsPage.get_chosen_date(), self.trackPage.get_date_format_from_locale()).strftime("%Y-%m-%d") apple_api = self.api_client.get_apple_top_chart_tracks(chart_date=chart_date, market=market)["items"] entry_api_tracks = [] reentry_api_tracks = [] for i in range(len(apple_api)): if apple_api[i]["metrics"]["is_entry"] is True and datetime.datetime.strptime(apple_api[i]["lifetime_metrics"]["earliest_position_date"], "%Y-%m-%d").date() == datetime.datetime.strptime(apple_api[i]["lifetime_metrics"]["latest_position_date"], "%Y-%m-%d").date(): entry_api_tracks.append(apple_api[i]["public_meta"]["name"]) elif apple_api[i]["metrics"]["is_entry"] is True and datetime.datetime.strptime(apple_api[i]["lifetime_metrics"]["earliest_position_date"], "%Y-%m-%d").date() < datetime.datetime.strptime(apple_api[i]["lifetime_metrics"]["latest_position_date"], "%Y-%m-%d").date(): reentry_api_tracks.append(apple_api[i]["public_meta"]["name"]) self.topChartsPage.log.info(f"New entry tracks: {entry_api_tracks}") self.topChartsPage.log.info(f"Re entry tracks: {reentry_api_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="apple") assert_that(reentry_api_tracks).is_subset_of(entry_reentry_ui_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="apple") assert_that(entry_api_tracks).is_subset_of(entry_reentry_ui_tracks) assert_that(len(entry_api_tracks + reentry_api_tracks)).is_equal_to(len(entry_reentry_ui_tracks))