import json import unittest from argparse import Namespace import allure import pytest from ui_automation_framework.core import TestStatus from ui_automation_framework.utils import AppConfig from app.api_client import ApiClient from app.mysql_db_client_custom import MySqlClient from ...pages.add_track_popup import AddTrackPopup from ...pages.comparison_page import TrackComparisonPage from ...pages.left_navigation_panel import LeftNavigationPanel from ...pages.login_page import LoginPage from ...pages.track_page import TrackPage @pytest.mark.usefixtures("set_up", "one_time_set_up") class ComparisonPlaylistSupportTest(unittest.TestCase): track16 = json.loads(json.dumps(AppConfig.get("track16")), object_hook=lambda d: Namespace(**d)) us = json.loads(json.dumps(AppConfig.get("market")["us"]), object_hook=lambda d: Namespace(**d)) spain = json.loads(json.dumps(AppConfig.get("market")["spain"]), object_hook=lambda d: Namespace(**d)) dsp_values_stream = ["Spotify", "Apple Music", "Amazon"] periods = [["14 Days", 14], ["28 Days", 28], ["8 Weeks", 56], ["12 Weeks", 84], ["6 Months", 182], ["1 Year", 365]] sources = ["MusicKit", "Station"] @pytest.fixture(autouse=True) def classSetup(self): self.loginPage = LoginPage(self.driver) self.trackPage = TrackPage(self.driver) self.add_track_popup = AddTrackPopup(self.driver) self.comparison_page = TrackComparisonPage(self.driver) self.left_panel = LeftNavigationPanel(self.driver) self.api_client = ApiClient() self.sql_client = MySqlClient() self.ts = TestStatus(self.driver) @allure.story("AP-3073") @allure.severity(allure.severity_level.NORMAL) @allure.title("""Adding track to comparison without existing ID in DB""") @allure.description( """TC verifies if an added track doesn't have existent ID/ISRS in DB, this track will be added to comparison and displayed successfully. This track should not be removed from comparison by refreshing the page or any other action except removing by user.""" ) def test_added_track_without_id_in_db(self): self.comparison_page.remove_tracks_if_present_with_worker(self.us.market) user = self.loginPage.get_user_email_with_worker() token = self.api_client.authorize(user=user) response = self.api_client.add_track_to_comparison(token=token, market=self.us.market, isrc=self.track16.isrc, id=self.track16.id) self.loginPage.login_with_worker() self.loginPage.is_logged_in() self.left_panel.open_comparison_page() self.comparison_page.wait_for_stream_performance_graph_visible() track_id_db = self.sql_client.get_track_id(self.track16.id) self.ts.markFinal(track_id_db == [], "STEP 1: track id is not exist in table") self.ts.markFinal(response.status_code == 201, "STEP 2: status code is 201") na_sections = self.comparison_page.get_all_section_with_na() self.ts.markFinal(len(na_sections) == 5, "STEP 3: all sections are empty, count: {}".format(len(na_sections))) self.comparison_page.open_playlist_details() self.comparison_page.empty_playlist_support_displayed() self.comparison_page.refresh() self.trackPage.select_market(self.us.name) self.comparison_page.select_market_from_dd(self.spain.name) self.comparison_page.select_period_from_dd(self.periods[0][0]) na_sections = self.comparison_page.get_all_section_with_na() self.ts.markFinal(len(na_sections) == 5, "STEP 4: all sections are empty") self.comparison_page.empty_playlist_support_displayed() self.comparison_page.track_performance_select_dsp_from_dd(self.dsp_values_stream[1]) self.comparison_page.wait_for_stream_performance_graph_visible() self.comparison_page.track_performance_select_source(self.sources[0]) self.comparison_page.wait_for_stream_performance_graph_visible() self.comparison_page.country_select_dsp_from_dd(self.dsp_values_stream[2]) self.comparison_page.country_select_source(self.sources[1]) self.comparison_page.by_engagement_select_dsp_from_dd(self.dsp_values_stream[2]) self.comparison_page.audience_select_dsp_from_dd(self.dsp_values_stream[1]) na_sections = self.comparison_page.get_all_section_with_na() self.ts.markFinal(len(na_sections) == 5, "STEP 5: all sections are empty") self.comparison_page.playlist_details_select_dsp_from_dd(self.dsp_values_stream[1]) self.comparison_page.empty_playlist_support_displayed()