import logging import pandas import pytest from parameterized import parameterized from ui_automation_framework.utils import logger as cl import app.src.tests.decomission.api_init as api_init API = api_init.APIOverride() log = cl.Logger(logging.DEBUG) current_playlist_apollo_portal = "/applemusic/playlists/{0}/tracklisthistory/countrydates?datetimeFormat=MM%2Fdd%2Fyy%2C+h%3Amm+tt" current_playlist_delphi = "/v3/public/track-positions/playlists?dsp=apple&include=playlists&playlist_id=apple_{0}&country_code=us,gb,cn,au,ca,ru,de,fr,mx,br,in,za,kr,it,tw,tr,ch,es,th,hk,ae,nz,dk,id,il,nl,se,no" @parameterized.expand( [ # 'pl.132b9a231cbf464086b4f838b2726f94', "pl.f4d106fed2bd41149aaacabb233eb5eb", "pl.b7ae3e0a28e84c5c96c4284b6a6c70af", ] ) @pytest.mark.skip() def test_playlist_markets(playlist_id): apollo_response = API.get_apollo_response(current_playlist_apollo_portal.format(playlist_id)) apollo_markets = sorted([market for market in apollo_response]) delphi_response = API.get_delphi_response(current_playlist_delphi.format(playlist_id)) delphi_markets = sorted(list(set([dict(r["playlist"])["country_code"] for r in delphi_response["items"]]))) apollo_markets_amount = len(apollo_markets) delphi_markets_amount = len(delphi_markets) for market_a in apollo_markets: if market_a not in delphi_markets: index = apollo_markets.index(market_a) delphi_markets.insert(index, "0") for market_d in delphi_markets: if market_d not in apollo_markets and market_d != "0": index = delphi_markets.index(market_d) apollo_markets.insert(index, "0") def f(dat): colors = [] for i in dat: if i == "issue with logic": c = "orange" elif i: c = "green" else: c = "red" colors.append(f"background-color: {c}") return colors change_values = [] for market_a, market_d in zip(apollo_markets, delphi_markets): if market_a == market_d: change_values.append(True) elif market_a == "0" or market_d == "0": change_values.append(False) elif market_a != market_d: change_values.append("issue with logic") index_for_all_fields = list(range(1, len(apollo_markets) + 1)) df = pandas.DataFrame( { "apollo": apollo_markets, "delphi": delphi_markets, "change": change_values, }, index=index_for_all_fields, ) df.style.apply(f, subset=["change"]).to_excel(f"decomission/apple_playlist_markets/apple_playlist_{playlist_id}_markets_apollo_{apollo_markets_amount}_delphi_{delphi_markets_amount}.xlsx")