import allure import pytest from assertpy import assert_that @allure.story("https://data-analytics.atlassian.net/browse/AG-6814") @allure.severity(allure.severity_level.NORMAL) @allure.title("Sorting on major moves") @allure.description("Sort by the number of moved positions, the minimum step for position change is 5") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-275" "https://data-analytics.atlassian.net/browse/AG-277") @pytest.mark.parametrize("vendor", ["spotify", "apple"]) def test_major_moves_sorting_and_minimal_step(authorized_api, vendor): fields = [ "artist", "artists", "change", "id", "image_url", "is_starred", "isrc", "name", "position", "is_sony", "is_new", "is_re_enter", "is_starred_track", ] response = authorized_api.apollo.get_charts_moves(vendor, "global", ["moves", "track_name"], fields) assert_that(response.tracks).is_sorted(key=lambda x: x.change) @allure.severity(allure.severity_level.NORMAL) @allure.title("Sorting by is_starred_track Spotify") @allure.description("") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-11668") def test_sorting_by_is_starred_track_spotify(authorized_api): vendor = "spotify" market = "global" fields = ["artist", "artists", "change", "id", "image_url", "is_starred", "name", "isrc", "position", "is_sony", "is_new", "is_re_enter", "is_starred_track"] distributors = ["sme", "theorchard", "awal"] order_by = ["-is_starred_track", "position"] limit = 2 def fetch_tracks(chart_type): if chart_type == "additions": return authorized_api.apollo.get_charts_additions( vendor=vendor, market=market, order_by=order_by, fields=fields, distributors=distributors)["body"]["tracks"] elif chart_type == "removals": return authorized_api.apollo.get_charts_removals( vendor=vendor, market=market, order_by=order_by, fields=fields, distributors=distributors)["body"]["tracks"] def star_and_validate_tracks(tracks): track_isrcs_and_ids = [(t["isrc"], t["id"]) for t in tracks] try: for isrc, _id in track_isrcs_and_ids[-limit:]: authorized_api.apollo.post_v1_starred_tracks_spotify(isrc, _id) updated_tracks = fetch_tracks(chart_type) for track in updated_tracks[:limit]: assert_that(track["is_starred_track"]).is_true() finally: for isrc, _ in track_isrcs_and_ids[-limit:]: authorized_api.apollo.delete_v1_starred_tracks(isrc) for chart_type in ["additions", "removals"]: tracks = fetch_tracks(chart_type) star_and_validate_tracks(tracks) @allure.severity(allure.severity_level.NORMAL) @allure.title("Sorting by is_starred_track Apple") @allure.description("") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-11668") def test_sorting_by_is_starred_track_apple(authorized_api): vendor = "apple" market = "global" fields = ["artist", "artists", "change", "id", "image_url", "is_starred", "name", "isrc", "position", "is_sony", "is_new", "is_re_enter", "is_starred_track"] distributors = ["sme", "theorchard", "awal"] order_by = ["-is_starred_track", "position"] limit = 2 def fetch_tracks(chart_type): if chart_type == "additions": return authorized_api.apollo.get_charts_additions( vendor=vendor, market=market, order_by=order_by, fields=fields, distributors=distributors)["body"]["tracks"] elif chart_type == "removals": return authorized_api.apollo.get_charts_removals( vendor=vendor, market=market, order_by=order_by, fields=fields, distributors=distributors)["body"]["tracks"] def star_and_validate_tracks(tracks): track_isrcs_and_ids = [(t["isrc"], t["id"]) for t in tracks] try: for isrc, _id in track_isrcs_and_ids[-limit:]: authorized_api.apollo.post_v1_starred_tracks_apple(isrc, _id) updated_tracks = fetch_tracks(chart_type) for track in updated_tracks[:limit]: assert_that(track["is_starred_track"]).is_true() finally: for isrc, _ in track_isrcs_and_ids[-limit:]: authorized_api.apollo.delete_v1_starred_tracks(isrc) for chart_type in ["additions", "removals"]: tracks = fetch_tracks(chart_type) star_and_validate_tracks(tracks) @allure.severity(allure.severity_level.NORMAL) @allure.title("Full charts and entries correlation") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-11669") @pytest.mark.parametrize("vendor", ["spotify", "apple"]) def test_full_charts_and_entries_correlation(authorized_api, vendor): fields = [ "artist", "artists", "change", "id", "image_url", "is_starred", "name", "isrc", "position", "is_sony", "is_new", "is_re_enter", "is_starred_track" ] distributors = ["sme", "theorchard", "awal"] order_by_entries = ["-is_starred_track", "position"] order_by_full_charts = ["position"] tracks_from_entries = authorized_api.apollo.get_charts_additions( vendor=vendor, order_by=order_by_entries, distributors=distributors, market="global", fields=fields)["body"]["tracks"] tracks_from_full_chart = authorized_api.apollo.get_charts_top( vendor=vendor, market="global", order_by=order_by_full_charts, fields=fields)["body"]["tracks"] # Use a dictionary for quick lookup track_chart_dict = {track['isrc']: track for track in tracks_from_full_chart} for track_entry in tracks_from_entries: matching_track = track_chart_dict.get(track_entry["isrc"]) if matching_track: assert_that(matching_track["is_new"]).is_true() @allure.severity(allure.severity_level.NORMAL) @allure.title("Full charts and exits correlation") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-11669") @pytest.mark.parametrize("vendor", ["spotify", "apple"]) def test_full_charts_and_exits_correlation(authorized_api, vendor): fields = [ "artist", "artists", "change", "id", "image_url", "is_starred", "name", "isrc", "position", "is_sony", "is_new", "is_re_enter", "is_starred_track" ] distributors = ["sme", "theorchard", "awal"] order_by_entries = ["-is_starred_track", "position"] order_by_full_charts = ["position"] tracks_from_removals = authorized_api.apollo.get_charts_removals( vendor=vendor, order_by=order_by_entries, distributors=distributors, market="global", fields=fields)["body"]["tracks"] tracks_from_full_chart = authorized_api.apollo.get_charts_top( vendor=vendor, market="global", order_by=order_by_full_charts, fields=fields)["body"]["tracks"] track_isrcs_from_removals = {track["isrc"] for track in tracks_from_removals} track_isrcs_from_full_chart = {track["isrc"] for track in tracks_from_full_chart} assert_that(track_isrcs_from_removals.issubset(track_isrcs_from_full_chart)).is_false() @allure.severity(allure.severity_level.NORMAL) @allure.title("Full charts and major moves correlation") @allure.testcase("https://data-analytics.atlassian.net/browse/AG-11671") @pytest.mark.parametrize("vendor", ["spotify", "apple"]) def test_full_charts_and_major_moves_correlation(authorized_api, vendor): fields = [ "artist", "artists", "change", "id", "image_url", "is_starred", "name", "isrc", "position", "is_sony", "is_new", "is_re_enter", "is_starred_track" ] distributors = ["sme", "theorchard", "awal"] order_by_entries = ["-is_starred_track", "position"] order_by_full_charts = ["position"] tracks_from_moves = authorized_api.apollo.get_charts_moves( vendor=vendor, order_by=order_by_entries, distributors=distributors, market="global", fields=fields) tracks_from_full_chart = authorized_api.apollo.get_charts_top( vendor=vendor, market="global", order_by=order_by_full_charts, fields=fields)["body"]["tracks"] tracks_chart_dict = {track["isrc"]: track for track in tracks_from_full_chart} for track_moves in tracks_from_moves.tracks: matching_track = tracks_chart_dict.get(track_moves.isrc) if matching_track: assert_that(abs(track_moves.change)).is_greater_than_or_equal_to(5)