import datetime import json import unittest from argparse import Namespace 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.amazon_playlist_page import AmazonPlaylistPage from app.src.pages.login_page import LoginPage from app.src.pages.position_playlist_popup import PositionPlaylistPopup from app.src.pages.top_charts_page import TopChartsPage from app.src.pages.track_page import TrackPage from app.src.pages.tt_dashboard_pot_popup import TTDashboardPOTPopup @pytest.mark.usefixtures("set_up", "one_time_set_up") class DeepLinkingTrackPageTest(unittest.TestCase): playlist35 = json.loads(json.dumps(AppConfig.get("playlist35")), object_hook=lambda d: Namespace(**d)) @pytest.fixture(autouse=True) def classSetup(self): self.loginPage = LoginPage(self.driver) self.tp = TrackPage(self.driver) self.amazon_playlist = AmazonPlaylistPage(self.driver) self.pip = PositionPlaylistPopup(self.driver) self.topChartsPage = TopChartsPage(self.driver) self.tt_dashboard_potp = TTDashboardPOTPopup(self.driver) self.api_client = ApiClient() self.ts = TestStatus(self.driver) @allure.story("AP-8379") @allure.severity(allure.severity_level.NORMAL) @allure.title("[AP-8040] [Amazon Playlist Page> Details Pop Up] Date-picker verification.") @allure.description("TC verifies Date-picker functionality on Amazon Playlist Details popup.") def test_amazon_playlist_popup_datepicker_verification(self): self.loginPage.login_with_worker() self.tp.select_market(AppConfig.get("market")["us"]["name"]) self.amazon_playlist.open_amazon_playlist_page(self.playlist35.amazon_id) # steps 1-2 self.amazon_playlist.open_popup() start = self.tp.get_calendar_start_date() end = self.tp.get_calendar_end_date() track_id = self.pip.get_metadata()["track_id"] isrc = self.api_client.get_isrc_by_apple_id(market=AppConfig.get("market")["us"]["market"], id=track_id)["data"][0]["attributes"]["isrc"] api_resp = self.api_client.get_track_positions_playlist(isrc=isrc, dsp="amazon")["items"] start_api, end_api = [], [] for item in api_resp: if item["isrc"] == isrc: start_api.append(item["earliest_position_date"]) end_api.append(item["latest_position_date"]) assert_that(set(start_api)).contains(start) assert_that(end).is_equal_to(str(max(end_api))) # step 3 self.tt_dashboard_potp.verify_calendar_hover() # step 4, 10, 12 for p, d in zip(self.tp.dp_predefined_periods, self.tp.dp_predefined_count_days): xaxis_before = self.tp.graph_get_xaxis() kpis_before = self.pip.get_legend_kpis() days_count_before = int(self.pip.get_graph_period_displayed()) self.tp.select_predefined_period(p) days_count = int(self.pip.get_graph_period_displayed()) count_p = self.tp.graph_get_count_days_from_calendar() xaxis_after = self.tp.graph_get_xaxis() date_to_ui = self.tp.get_calendar_end_date() kpis_after = self.pip.get_legend_kpis() assert_that(days_count).is_equal_to(days_count_before) if d == self.tp.dp_predefined_count_days[-1]: assert_that(count_p).is_greater_than_or_equal_to(d - 5) assert_that(count_p).is_less_than_or_equal_to(d + 5) else: assert_that(count_p).is_equal_to(d) assert_that(str(datetime.datetime.today().date())).is_equal_to(date_to_ui) if p > self.tp.dp_predefined_periods[0]: assert_that(xaxis_before).is_not_equal_to(xaxis_after) assert_that(sum(kpis_before)).is_less_than_or_equal_to(sum(kpis_after)) # step 5 self.tt_dashboard_potp.click_on_date_picker() self.topChartsPage.verify_datepicker() # step 7-8 self.tt_dashboard_potp.verify_datepicker_dates() # step 9 self.tt_dashboard_potp.click_on_date_picker() self.tp.select_previous_mounth_period() assert_that(self.tp.graph_get_count_days_from_calendar()).is_equal_to(28) # step 11 days_count_step11 = int(self.pip.get_graph_period_displayed()) assert_that(days_count_step11).is_equal_to(days_count) # step 13 self.tp.select_predefined_period(self.tp.dp_predefined_periods[0]) self.tt_dashboard_potp.click_on_date_picker() self.tt_dashboard_potp.verify_datepicker_start_end_hover() # step 16 self.pip.select_today_period() self.pip.verify_no_data() # step 17 self.tp.select_one_day_period_in_previous_month() days_count_step17 = int(self.pip.get_graph_period_displayed()) assert_that(days_count_step17).is_equal_to(days_count) assert_that(self.tp.graph_get_count_days_from_calendar()).is_equal_to(1) # NOT AUTOMATED STEPS - 6, 14-15