import random import allure import pytest from assertpy import assert_that from src.data.constants import DSP from src.helpers.date_utils import get_ui_date_from_url, get_date_in_past_from_now from src.helpers.string_utils import get_int_from_str @pytest.mark.usefixtures("app") class TestArtistPageTableDataAndColumns: @pytest.mark.parametrize("market_url,market_api", [ ("4", "us"), ("14", "_gl"), ]) @allure.title("[AP-10635][Artist Page] Table. Streaming data verification") @allure.description("TC verifies that the correct number of streams is shown on the Artist page for each track.") @allure.testcase("https://data-analytics.atlassian.net/browse/AP-10660") def test_artist_page_tracks_table_streaming_data_verification(self, market_url, market_api): self.login_page.login() artist_id = "5YGY8feqx7naU7z4HrwZM6" self.app.go_to(self.artist_header.url.format(artist_id, market_url)) # steps 1-2, 10 response = self.app.api.get_dsp_dates() date_last = str(response["spotify"]) date_first = str(get_date_in_past_from_now(date_last, 6)) date_last_ui = get_ui_date_from_url(response["spotify"]) date_first_ui = get_ui_date_from_url(date_first) self.artists_tracks_table.streams_header._element.hover() self.artists_tracks_table.streams_tooltip.contain_text(f"{date_first_ui}–{date_last_ui}") # steps 5-8 api_response_artist = self.app.api.get_artist_tracks(artist_id, "all", market_api) self.app.go_to(self.artist_header.url.format(artist_id, market_url)) self.artists_tracks_table.verify_table_data_streams(api_response_artist) # step 3 track_from_resp_int = random.randint(0, len(api_response_artist) - 1) track_id = api_response_artist[track_from_resp_int]["spotifyTrack"]["trackId"] self.artists_sas_tab.dsp_dd.verify_chosen(DSP.BY_DSP) self.app.go_to(self.track_page_header.url.format("spotify", track_id, market_url)) self.tp_sas_tab.dsp_dd.verify_chosen(DSP.BY_DSP) self.tp_sas_tab.is_loaded() self.track_page_header.day_picker.select_two_dates(date_first, date_last) track_totals = int(get_int_from_str(self.tp_sas_tab.legend_totals_by_dsp._element.first.text_content())) assert_that(api_response_artist[track_from_resp_int]["streams_7_days"]) \ .is_equal_to(track_totals) # covered in other test - step 4 # not automated - step 9