import allure from assertpy import assert_that @allure.severity(allure.severity_level.NORMAL) @allure.title("Search and recent search filtering") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-11673") def test_search_and_recent_search_filtering(authorized_api): query = "Top" limit = 30 recent_limit = 21 authorized_api.apollo.post_search_history( payload={"uri": "B07K2FVM3G:10_us", "searchTerm": "Top", "dsp": "amazon", "type": "playlist", "timestamp": 1692802364218}) authorized_api.apollo.post_search_history( payload={"uri": "spotify:playlist:44lA0PjWNnipvYv7ZF1eLi", "searchTerm": "Top", "dsp": "spotify", "type": "playlist", "timestamp": 1692802424051}) authorized_api.apollo.post_search_history( payload={"uri": "pl.b00965bf8c6c4be8b4721e9293e8ceab", "searchTerm": "Top", "dsp": "apple", "country_code": "us", "type": "playlist", "timestamp": 1692802453801}) def get_playlists_by_vendor(api, method, vendors, limit, query=None, _type=None): """ Helper function to retrieve playlists by vendors """ if method == 'search': return api.gate.get_playlists_search(query=query, vendor=vendors, limit=limit) elif method == 'history': return api.apollo.get_search_history(_type=_type, vendor=vendors, limit=limit)["body"]["items"] else: raise ValueError(f"Unsupported method: {method}") def assert_playlists_have_vendors(playlists, vendors): """ Helper function to assert all playlists are from the specified vendors """ assert_that({pl["vendor"] for pl in playlists}).is_equal_to(set(vendors)) # Test the search functionality for each vendor for vendor in ["spotify", "apple", "amazon"]: playlists = get_playlists_by_vendor(authorized_api, 'search', [vendor,], limit, query) assert_playlists_have_vendors(playlists, [vendor,]) # Test search with combined vendors combined_vendors = ["apple", "amazon"] combined_playlists = get_playlists_by_vendor(authorized_api, 'search', combined_vendors, limit, query) assert_playlists_have_vendors(combined_playlists, combined_vendors) # Test the recent search history for each vendor for vendor in ["spotify", "apple", "amazon"]: recent_playlists = get_playlists_by_vendor(authorized_api, 'history', [vendor,], recent_limit, _type="playlist") assert_playlists_have_vendors(recent_playlists, [vendor,]) # Test recent search with combined vendors combined_vendors = ["spotify", "apple"] combined_recent_playlists = get_playlists_by_vendor(authorized_api, 'history', combined_vendors, recent_limit, _type="playlist") assert_playlists_have_vendors(combined_recent_playlists, combined_vendors)