import unittest import allure import pytest from assertpy import assert_that from parameterized import parameterized from ui_automation_framework.core import TestStatus from ui_automation_framework.utils import AppConfig from ...pages.login_page import LoginPage from ...pages.track_page import TrackPage @pytest.mark.usefixtures("set_up", "one_time_set_up") class DeepLinkingTrackPageTest(unittest.TestCase): @pytest.fixture(autouse=True) def classSetup(self): self.loginPage = LoginPage(self.driver) self.tp = TrackPage(self.driver) self.ts = TestStatus(self.driver) @parameterized.expand([AppConfig.get("dsp")["spotify"], AppConfig.get("dsp")["amazon"], AppConfig.get("dsp")["apple"]]) @allure.story("AP-4868") @allure.severity(allure.severity_level.NORMAL) @allure.title("[AP-4489] [Track Page] Lean Back/Lean Forward graph data validation") @allure.description("""TC verifies that user can see ‘Lean Back/Lean Forward’ graph for each DSP with proper data.""") def test_lb_lf_graph_data_validation(self, dsp): start_date = "2020-11-11" end_date = "2020-11-20" self.loginPage.login_with_worker() self.tp.open_spotify_track_page_with_market_id(track_id=AppConfig.get("track40")["id"], market_id=AppConfig.get("market")["us"]["url"]) # step 1, 5, 8 self.tp.select_dsp(dsp) base_url = self.tp.get_url() # step 2, 6 self.tp.open_current_url_with_param(f"&str_gr_start_date={start_date}&str_gr_end_date={start_date}") self.compare_by_source_legend([AppConfig.get("market")["us"]["market"]], AppConfig.get("track40")["isrc"]) # step 4, 7, 9, 10 self.tp.change_source_type(AppConfig.get("source")["lf_lb"]) self.compare_lb_lf_legend([AppConfig.get("market")["us"]["market"]], AppConfig.get("track40")["isrc"]) # step 3 self.tp.open_url(f"{base_url}&str_gr_start_date={start_date}&str_gr_end_date={end_date}") self.compare_by_source_legend([AppConfig.get("market")["us"]["market"]], AppConfig.get("track40")["isrc"]) # step 4, 7, 9, 10 self.tp.change_source_type(AppConfig.get("source")["lf_lb"]) self.compare_lb_lf_legend([AppConfig.get("market")["us"]["market"]], AppConfig.get("track40")["isrc"]) # step 11 self.tp.stream_and_source_choose_region(self.tp.REGION_EUROPE) self.compare_lb_lf_legend(AppConfig.get("regions")["europe"]["api"], AppConfig.get("track40")["isrc"]) self.tp.market_dd_choose_few_countries([AppConfig.get("market")["australia"]["name"], AppConfig.get("market")["uk"]["name"]]) self.compare_lb_lf_legend([AppConfig.get("market")["australia"]["market"], AppConfig.get("market")["uk"]["market"]], AppConfig.get("track40")["isrc"]) self.tp.market_dd_choose_few_countries([self.tp.all_markets]) self.compare_lb_lf_legend([AppConfig.get("market")["global"]["api"]], AppConfig.get("track40")["isrc"]) @allure.step("TP - get lean back/forward values API") def get_lb_lf_api_values(self, markets, isrc): start = self.tp.get_calendar_start_date() end = self.tp.get_calendar_end_date() dsp = self.tp.get_current_dsp() if dsp == AppConfig.get("dsp")["spotify"]: if markets == [AppConfig.get("market")["global"]["api"]]: markets = [AppConfig.get("market")["global"]["api3"]] api_sources = self.tp.graph_legend_get_api_values_spotify( markets=markets, start_date=start, end_date=end, isrc=isrc, ) elif dsp == AppConfig.get("dsp")["apple"]: if markets == [AppConfig.get("market")["global"]["api"]]: markets = [AppConfig.get("market")["global"]["api3"]] api_sources = self.tp.graph_legend_get_api_values_apple(markets=markets, isrc=isrc) else: api_sources = self.tp.graph_legend_get_api_values_amazon(markets=markets, isrc=isrc) lb_sum = sum(api_sources["lb"].values()) lf_sum = sum(api_sources["lf"].values()) api_sources_percentage = [int(p / api_sources["total"] * 100) for p in [lf_sum, lb_sum]] days_count = self.tp.graph_get_count_days_from_calendar() lb_lf_totals_api = [ api_sources["total"], self.tp.apply_rounding_percentage(api_sources["total"] / days_count), lf_sum, api_sources_percentage[0], self.tp.apply_rounding_percentage(lf_sum / days_count), lb_sum, api_sources_percentage[1], self.tp.apply_rounding_percentage(lb_sum / days_count), ] return {"lean_back_count": lb_sum, "lean_forward_count": lf_sum, "lean_back_percent": api_sources_percentage[1], "lean_forward_percent": api_sources_percentage[0], "total": api_sources["total"], "lb_lf_totals_api": lb_lf_totals_api} @allure.step("TP - get lean back/forward graph legend parsed") def get_graph_legend_lb_lf_values_parsed(self): totals = self.tp.graph_amazon_get_totals() t = [t.replace(",", "").replace("%", "").replace("(", "").replace(")", "") for t in totals] totals = [int(t[0]), int(t[1]), int(t[2].split("\n")[0]), int(float(t[2].split("\n")[1])), int(t[3]), int(t[4].split("\n")[0]), int(float(t[4].split("\n")[1])), int(t[5])] return totals @allure.step("TP - compare data for lean back/forward view - api UI legend") def compare_lb_lf_legend(self, markets, isrc): lb_lf_api = self.get_lb_lf_api_values(markets, isrc)["lb_lf_totals_api"] lb_lf_totals_ui = self.get_graph_legend_lb_lf_values_parsed() for a, u in zip(lb_lf_api, lb_lf_totals_ui): assert_that(a - u in list(range(-1, 2))).described_as(f"api: {a}, ui: {u}").is_true() @allure.step("TP - compare data for By Source view api UI legend") def compare_by_source_legend(self, markets, isrc): lb_lf_ui = self.tp.get_lean_values() lb_lf_api = self.get_lb_lf_api_values(markets, isrc) for n in ["lean_forward_count", "lean_back_count", "lean_forward_percent", "lean_back_percent", "total"]: assert_that(lb_lf_ui[n] - lb_lf_api[n] in list(range(-1, 2))).described_as(f"{n}: ui: {lb_lf_ui[n]}, api: {lb_lf_api[n]}").is_true()