import pytest import allure from random import choice from assertpy import assert_that from src.data.entities_data import entity_types from src.data.entities_data import entity_ids from src.helpers.api_helper import api_amplitude @allure.description("Send statistics to amplitude on Entity page actions") @pytest.mark.usefixtures("app") class TestAmplitudeEntity: @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-729") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-730") @allure.title("[Amplitude] - Entity Page - Visit") @pytest.mark.regression @pytest.mark.parametrize('entity_type', entity_types) def test_amplitude_entity_page_visit(self, entity_type): entity = self.app.api.get_random_entity(entity_type) entity_id = entity['id'] with self.app.page.expect_response( lambda response: response.url == api_amplitude and response.request.method == 'POST' and response.status == 200) as amplitude_response: self.app.go_to(f"/{entity_type}/{entity_id}") event = self.common_page.get_amplitude_event(amplitude_response) print(entity) print("==========") print(event) assert_that(event['event_type']).is_equal_to(f'{entity_type.capitalize()} Page - Visit') assert_that(event['event_properties'][f'{entity_type}Id']).is_equal_to(entity_id) assert_that(event['event_properties'][f'{entity_type}Name']).is_equal_to(entity['name']) if entity_type == 'track': assert_that(event['event_properties']['trackArtistId']).is_equal_to(entity['cm_artist_id']) assert_that(event['event_properties']['trackArtistName']).is_equal_to(entity['artist_name']) @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-143") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-141") @allure.title("[Amplitude] - Entity page - external link clicked") @pytest.mark.regression @pytest.mark.parametrize('entity_type', entity_types) def test_amplitude_entity_external_link(self, entity_type): entity_id = entity_ids[entity_type] with self.app.page.expect_response( lambda response: response.url == api_amplitude and response.request.method == 'POST' and response.status == 200) as amplitude_response: self.app.go_to(f"/{entity_type}/{entity_id}") ext_link_dsp = choice( {'artist': ['tiktok', 'youtube', 'spotify', 'soundcloud'], 'track': ['tiktok', 'spotify']}[entity_type]) # as current entity does HAVE these with self.app.page.expect_response( lambda response: response.url == api_amplitude and response.request.method == 'POST' and response.status == 200) as amplitude_response: self.artist_page.ext_link.get_by(ext_link_dsp).click() event = self.common_page.get_amplitude_event(amplitude_response) assert_that(event['event_type']).is_equal_to(f'{entity_type.capitalize()} Page External Link Clicked') assert_that(event['event_properties']['link_type']).is_equal_to(ext_link_dsp) @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-304") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-124") @allure.title("[Amplitude] - Entity - Share") @pytest.mark.regression @pytest.mark.parametrize('entity_type', entity_types) def test_amplitude_entity_share(self, entity_type): entity = self.app.api.get_random_entity(entity_type) entity_id = entity['id'] self.app.go_to(f"/{entity_type}/{entity_id}") self.artist_page.btn_share.click() self.common_page.share_user.get_by(1).click() with self.app.page.expect_response( lambda response: response.url == api_amplitude and response.request.method == 'POST' and response.status == 200) as amplitude_response: self.common_page.modal_btn_share.click() event = self.common_page.get_amplitude_event(amplitude_response) assert_that(event['event_type']).is_equal_to(f'Share {entity_type.capitalize()}') assert_that(event['event_properties'][f'{entity_type}_id']).is_equal_to(entity_id) assert_that(event['event_properties'][f'{entity_type}_name']).is_equal_to(entity['name']) @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-217") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-144") @allure.title("[Amplitude] - Entity page - DSP tab click") @pytest.mark.regression @pytest.mark.parametrize('entity_type', entity_types) def test_amplitude_entity_dsp_tab_click(self, entity_type): entity_id = entity_ids[entity_type] with self.app.page.expect_response( lambda response: response.url == api_amplitude and response.request.method == 'POST' and response.status == 200) as amplitude_response: self.app.go_to(f"/{entity_type}/{entity_id}") dsp = choice(['youtube', 'spotify', 'soundcloud']) # as current artist does HAVE all with self.app.page.expect_response( lambda response: response.url == api_amplitude and response.request.method == 'POST' and response.status == 200) as amplitude_response: self.artist_page.tab_performance.get_by(dsp).click() event = self.common_page.get_amplitude_event(amplitude_response) assert_that(event['event_type']).is_equal_to(f'{entity_type.capitalize()} Page Tab Clicked') assert_that(event['event_properties']['tab']).is_equal_to(dsp) @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-216") @allure.title("[Amplitude] - Entity page - Video click") @pytest.mark.regression @pytest.mark.parametrize('entity_type', entity_types) def test_amplitude_entity_video_click(self, entity_type): entity_id = entity_ids[entity_type] with self.app.page.expect_response( lambda response: response.url == api_amplitude and response.request.method == 'POST' and response.status == 200) as amplitude_response: self.app.go_to(f"/{entity_type}/{entity_id}") self.artist_page.is_page_loaded() self.artist_page.scope_bar.get_by('tiktok').is_active() with self.app.page.expect_response( lambda response: response.url == api_amplitude and response.request.method == 'POST' and response.status == 200) as amplitude_response: self.artist_page.card_tiktok_src.get_by(1).click() event = self.common_page.get_amplitude_event(amplitude_response) assert_that(event['event_type']).is_equal_to(f'{entity_type.capitalize()} Page Video Clicked') assert_that(event['event_properties']['video_type']).is_equal_to('tiktok') # Click YouTube self.artist_page.scope_bar.get_by('youtube').click() self.artist_page.scope_bar.get_by('youtube').is_active() with self.app.page.expect_response( lambda response: response.url == api_amplitude and response.request.method == 'POST' and response.status == 200) as amplitude_response: self.artist_page.card_youtube_title.get_by(1).click() event = self.common_page.get_amplitude_event(amplitude_response) assert_that(event['event_type']).is_equal_to(f'{entity_type.capitalize()} Page Video Clicked') assert_that(event['event_properties']['video_type']).is_equal_to('youtube') @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-720") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-267") @allure.title("[Amplitude] - Discovery Result Page - Add To and Delete Entity From Category") @pytest.mark.smoke @pytest.mark.parametrize('entity_type', entity_types) def test_amplitude_save_and_delete_entity_in_category(self, entity_type): entity = self.app.api.get_random_entity(entity_type) entity_id = entity['id'] entity_name = entity['name'] with self.app.page.expect_response( lambda response: response.url == api_amplitude and response.request.method == 'POST' and response.status == 200) as amplitude_response: self.app.go_to(f"/{entity_type}/{entity_id}") self.artist_page.btn_add_to_category.click() self.common_page.modal_lb_add_to_category.exists() self.common_page.modal_btn_create_and_save.is_enabled(False) category_name = f"Cat for {entity_name}" self.common_page.placeholder_category_title.input_text(category_name) with self.app.page.expect_response( lambda response: response.url == api_amplitude and response.request.method == 'POST' and response.status == 200) as amplitude_response: self.common_page.modal_btn_create_and_save.click() event = self.common_page.get_amplitude_event(amplitude_response) assert_that(event['event_type']).is_equal_to(f'Save {entity_type.capitalize()}') assert_that(event['event_properties'][f'{entity_type}_id']).is_equal_to(entity_id) assert_that(event['event_properties'][f'{entity_type}_name']).is_equal_to(entity_name) assert_that(int(event['event_properties']['category_id'])).is_greater_than(0) # Remove entity from category self.artist_page.btn_remove_entity_category.get_by(1).click() with self.app.page.expect_response( lambda response: response.url == api_amplitude and response.request.method == 'POST' and response.status == 200) as amplitude_response: self.common_page.modal_btn_remove.click() event = self.common_page.get_amplitude_event(amplitude_response) assert_that(event['event_type']).is_equal_to('Remove Entity') assert_that(event['event_properties']['entity_id']).is_equal_to(entity_id) assert_that(event['event_properties']['entity_name']).is_equal_to(entity_name) assert_that(int(event['event_properties']['category_id'])).is_greater_than(0)