import json import pytest import allure from assertpy import assert_that from src.data.entities_data import entity_ids from src.data.entities_data import entity_types @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-232") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-656") @allure.description("If data failed to load in one of the following sections, an appropriate placeholder for each " "section should be shown.") @pytest.mark.usefixtures("app") class TestEntityFailedToLoad: @allure.title("[Entity Page] Failed to Load - Performance section") @pytest.mark.regression @pytest.mark.parametrize('entity_type', entity_types) def test_entity_failed_to_load_whole_page(self, entity_type): entity = self.app.api.get_random_entity(entity_type) entity_id = entity['id'] self.app.abort_request("**discovery_result") self.app.go_to(f'/{entity_type}/{entity_id}') self.common_page.error_titles_container.contain_text( f'{entity_type.capitalize()} failed to load.Please try refreshing the page.') @allure.title("[Entity Page] Corrupted Data - Performance section") @pytest.mark.regression @pytest.mark.parametrize('entity_type', entity_types) def test_entity_corrupted_data(self, entity_type): entity = self.app.api.get_random_entity(entity_type) entity_id = entity['id'] self.app.fulfill_response('**discovery_result', '{}') self.app.go_to(f'/{entity_type}/{entity_id}') self.common_page.error_title.contain_text("Pause the music! Something's out of tune.") @allure.title("[Entity Page] Failed to Load - external links") @pytest.mark.regression @pytest.mark.parametrize('entity_type', entity_types) def test_entity_failed_to_load_external_links(self, entity_type): entity = self.app.api.get_random_entity(entity_type) entity_id = entity['id'] self.app.abort_request("**external_links") self.app.go_to(f'/{entity_type}/{entity_id}') self.common_page.error_titles_container.not_exist() self.artist_page.error_failed_to_load_ext_link.contain_text('Failed to load external links') @allure.title("[Entity Page] Failed to Load - categories") @pytest.mark.regression @pytest.mark.parametrize('entity_type', entity_types) def test_entity_failed_to_load_categories(self, entity_type): entity = self.app.api.get_random_entity(entity_type) entity_id = entity['id'] category_id = self.app.api.insert_category('category for failed requests') self.app.api.insert_entity_to_category(category_id, entity_id, entity_type) self.app.abort_request("**categories**") self.app.go_to(f'/{entity_type}/{entity_id}') alert_msg = self.common_page.alert_msg.get_text() assert_that(alert_msg).is_equal_to('Partial data failed to load. Try refreshing the page.') self.common_page.error_titles_container.not_exist() @allure.title("[Entity Page] Failed to Load - recent results") @pytest.mark.regression @pytest.mark.parametrize('entity_type', entity_types) def test_entity_failed_to_load_recent_results(self, entity_type): entity = self.app.api.get_random_entity(entity_type) entity_id = entity['id'] self.app.abort_request("**recent_searches") self.app.go_to(f'/{entity_type}/{entity_id}') self.common_page.error_titles_container.not_exist() self.home_page.placeholder_search.click() self.common_page.error_titles_container.contain_text('Recent results failed to load.') @allure.title("[Entity Page] Failed to Load - tracks and videos") @pytest.mark.regression @pytest.mark.parametrize('entity_type', entity_types) def test_entity_failed_to_load_tracks_and_videos(self, entity_type): entity_id = entity_ids[entity_type] self.app.abort_request("**tracks**") self.app.abort_request("**videos**") self.app.go_to(f'/{entity_type}/{entity_id}') self.artist_page.tracks_error.contain_text('Failed to load. Please try refreshing the page.') self.artist_page.videos_error.contain_text('Failed to load. Please try refreshing the page.') @allure.title("[Entity Page] Failed to Load - artist albums") @pytest.mark.regression def test_entity_failed_to_load_albums(self, entity_type='artist'): entity_id = entity_ids[entity_type] self.app.abort_request("**albums**") self.app.go_to(f'/{entity_type}/{entity_id}') alert_msg = self.common_page.alert_msg.get_text() assert_that(alert_msg).is_equal_to('Partial data failed to load. Try refreshing the page.') @allure.title("[Entity Page] Failed to Load - labels to Share") @pytest.mark.regression @pytest.mark.parametrize('entity_type', entity_types) def test_entity_failed_to_load_labels_to_share(self, entity_type): entity_id = entity_ids[entity_type] self.app.abort_request("**labels") self.app.go_to(f'/{entity_type}/{entity_id}') self.artist_page.btn_share.click() self.artist_page.error_share.contain_text('List of colleagues failed to load.Retry') @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-233") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-657") @allure.description("If no tracks/videos found then an appropriate message should be shown in placeholder") @pytest.mark.usefixtures("app") class TestEntityEmptyDataPlaceholders: @allure.title("[Artist Page] - Performance section - Not Enough historical data") def test_artist_performance_section_no_data(self, entity_type='artist'): entity_id = entity_ids[entity_type] with self.app.page.expect_response( self.artist_page.api_discovery_result.format(entity_type, entity_id)) as response: self.app.go_to(f"/{entity_type}/{entity_id}") discovery_result = response.value.json() discovery_result['tiktok']['followers_chart'] = [] discovery_result['tiktok']['likes_chart'] = [] discovery_result['youtube']['subscribers_chart'] = [] discovery_result['youtube']['views_chart'] = [] discovery_result['spotify']['followers_chart'] = [] discovery_result['spotify']['listeners_chart'] = [] discovery_result['soundcloud']['followers_chart'] = [] discovery_result['soundcloud']['plays_chart'] = [] data = json.dumps(discovery_result) self.app.fulfill_response('**discovery_result', data) self.app.page.reload() self.artist_page.not_enough_chart_data_message.get_by('Followers') self.artist_page.not_enough_chart_data_message.get_by('Likes') self.artist_page.tab_performance.get_by('youtube').click() self.artist_page.not_enough_chart_data_message.get_by('Subscribers') self.artist_page.not_enough_chart_data_message.get_by('Views') self.artist_page.tab_performance.get_by('spotify').click() self.artist_page.not_enough_chart_data_message.get_by('Followers') self.artist_page.not_enough_chart_data_message.get_by('Listeners/Mth') self.artist_page.tab_performance.get_by('soundcloud').click() self.artist_page.not_enough_chart_data_message.get_by('Followers') self.artist_page.not_enough_chart_data_message.get_by('Plays') @allure.title("[Entity Page] Empty Tracks placeholder") @pytest.mark.regression @pytest.mark.parametrize('entity_type', entity_types) def test_entity_empty_tracks(self, entity_type): entity_id = entity_ids[entity_type] self.app.fulfill_response("**tracks**", "[]") self.app.go_to(f'/{entity_type}/{entity_id}') error_text = {'artist': 'No tracks found for this artist.', 'track': 'No other tracks found for this artist.'} self.artist_page.tracks_error.contain_text(error_text[entity_type]) @allure.title("[Entity Page] Empty Videos placeholder") @pytest.mark.regression @pytest.mark.parametrize('entity_type', entity_types) def test_entity_empty_videos(self, entity_type): entity_id = entity_ids[entity_type] self.app.fulfill_response("**videos**", "[]") self.app.go_to(f'/{entity_type}/{entity_id}') self.artist_page.videos_error.contain_text(f'No videos found for this {entity_type}.')