import random import pytest import allure from assertpy import assert_that from src.data.entities_data import entity_types @pytest.mark.usefixtures("app") class TestSaveEntityToCategory: @allure.title("[Discovery Results] – Save entity to the category (no existing categories)") @allure.description("As user I want to save artist/track to new category") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-460") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-153") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-155") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-462") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-192") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-203") @pytest.mark.smoke @pytest.mark.parametrize('entity_type', entity_types) def test_save_entity_to_new_category(self, entity_type): self.app.go_to(self.discovery_page.url) self.discovery_page.is_page_loaded() if entity_type == 'track': self.discovery_page.switch_scope_to_tracks() # Set random parameters self.discovery_page.dsp_tiktok_on(True) self.discovery_page.bn_discovery.click() self.discovery_results_page.is_page_loaded() entities = self.discovery_results_page.page_cards_id_list() entity_id = random.choice(entities) entity_name = self.discovery_results_page.card_name.get_by(entity_id).get_text() self.discovery_results_page.card_menu.get_by(entity_id).click() self.common_page.modal_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"AutoCategory for {entity_type}" self.common_page.placeholder_category_title.input_text(category_name) self.common_page.modal_btn_create_and_save.click() alert_msg = self.common_page.alert_msg.get_text() assert_that(alert_msg).is_equal_to( f'{entity_name}  is added to the {category_name} category.') # Check Category is created and artist is saved in it category = [cat for cat in self.app.api.get_user_categories() if cat['name'] == category_name] category_entities = self.app.api.get_category_entities(category[0]['id']) saved_to_category_item = category_entities[0] assert_that(saved_to_category_item["entity_type"]).is_equal_to(entity_type) assert_that(saved_to_category_item["id"]).is_equal_to(entity_id) assert_that(saved_to_category_item["name"]).is_equal_to(entity_name) # Check Green Mark self.discovery_results_page.verify_green_mark_for_card(entity_id) @allure.title("[Discovery Results] – Save an artist/track to the category (many existing categories)") @allure.description("As user I want to save artist/track to new category") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-461") @allure.testcase("https://data-analytics.atlassian.net/browse/DNAD-463") @pytest.mark.smoke @pytest.mark.parametrize('entity_type', entity_types) def test_save_entity_to_existent_category(self, entity_type): category_name_home = f"autotest {entity_type} cat home" category_name_2 = f"autotest {entity_type} cat aaa" category_name_3 = f"autotest {entity_type} cat bbb" self.app.api.insert_category(category_name_home, True) self.app.api.insert_category(category_name_2, False) self.app.api.insert_category(category_name_3, False) self.app.go_to(self.discovery_page.url) self.discovery_page.is_page_loaded() if entity_type == 'track': self.discovery_page.switch_scope_to_tracks() # Set random parameters self.discovery_page.dsp_youtube_on(True) self.discovery_page.bn_discovery.click() self.discovery_results_page.is_page_loaded() entities = self.discovery_results_page.page_cards_id_list() entity_id = random.choice(entities) entity_name = self.discovery_results_page.card_name.get_by(entity_id).get_text() self.discovery_results_page.card_menu.get_by(entity_id).click() self.common_page.modal_btn_add_to_category.click() self.common_page.modal_lb_add_to_category.exists() self.common_page.modal_category_dropdown.click() # Verify ordering in Categories drop-down cat1 = self.common_page.modal_category_dropdown_item.nth(0).text_content() cat2 = self.common_page.modal_category_dropdown_item.nth(1).text_content() cat3 = self.common_page.modal_category_dropdown_item.nth(2).text_content() assert_that(cat1).is_equal_to(category_name_home) assert_that(cat2).is_equal_to(category_name_3) assert_that(cat3).is_equal_to(category_name_2) self.common_page.modal_category_dropdown.click() self.common_page.modal_btn_save.is_enabled(False) # Select category and save self.common_page.modal_category_dropdown.select_option(category_name_3) self.common_page.modal_btn_save.click() alert_msg = self.common_page.alert_msg.get_text() assert_that(alert_msg).is_equal_to( f'{entity_name}  is added to the {category_name_3} category.') # Check artist is saved in appropriate category category_3 = [cat for cat in self.app.api.get_user_categories() if cat['name'] == category_name_3] category_entities = self.app.api.get_category_entities(category_3[0]['id']) saved_to_category_item = category_entities[0] assert_that(saved_to_category_item["entity_type"]).is_equal_to(entity_type) assert_that(saved_to_category_item["id"]).is_equal_to(entity_id) assert_that(saved_to_category_item["name"]).is_equal_to(entity_name) # Check others categories are empty category_2 = [cat for cat in self.app.api.get_user_categories() if cat['name'] == category_name_2] category_2_entities = self.app.api.get_category_entities(category_2[0]['id']) assert_that(category_2_entities).is_none() category_home = [cat for cat in self.app.api.get_user_categories() if cat['name'] == category_name_home] category_home_entities = self.app.api.get_category_entities(category_home[0]['id']) assert_that(category_home_entities).is_none()