import json import math 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.track_page import TrackPage @pytest.mark.usefixtures("set_up", "one_time_set_up") class ApplePlaylistPageTest(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.amazon_playlist = AmazonPlaylistPage(self.driver) self.trackPage = TrackPage(self.driver) self.api_client = ApiClient() self.ts = TestStatus(self.driver) @allure.story("AP-8343") @allure.severity(allure.severity_level.NORMAL) @allure.title("[AP-8027][Amazon Playlist] Streams Index calculation logic verification") @allure.description("TC verifies the calculation of streams Index on the Amazon Playlist page.") def test_amazon_streams_index_verification_verification(self): self.loginPage.login_with_worker() self.amazon_playlist.open_amazon_playlist_page(self.playlist35.amazon_id) self.amazon_playlist.change_market(AppConfig.get("market")["us"]["name"]) # step 1-3 self.amazon_playlist.sort_table_by_column(self.amazon_playlist.TL_COLUMN_AVG_STREAMS) self.verify_stream_indexes() # step 5 self.amazon_playlist.tl_change_date(2) self.verify_stream_indexes() @allure.step("Amazon playlist page - verify stream indexes") def verify_stream_indexes(self): count_to_verify = 5 avg_streams = self.amazon_playlist.tl_get_column_values(self.amazon_playlist.TL_COLUMN_AVG_STREAMS)[:count_to_verify] streams_indexes = self.amazon_playlist.tl_get_column_values(self.amazon_playlist.TL_COLUMN_STREAMS_INDEX)[:count_to_verify] streams_indexes = [math.ceil(i) for i in streams_indexes] calculated_indexes = [math.ceil(a / avg_streams[0] * 100) for a in avg_streams] self.trackPage.log.info(f"indexes: {streams_indexes}\n{calculated_indexes}") for fu, fa in zip(calculated_indexes, streams_indexes): assert_that(list(range(-1, 2))).contains(fu - fa) # NOT AUTOMATED STEPS - 4