from collections import Counter def assert_no_duplicates(items, key_name): duplicates = [] counts = Counter(items) for item, count in counts.items(): if count > 1: duplicates.append(item) assert not duplicates, ( f"Duplicate {key_name}s found: {duplicates}\n" f"Total: {len(items)}, Unique: {len(set(items))}" ) def test_no_duplicate_isrcs_in_songs(graphql): variables = { "orderDir": "desc", "countries": [], "globalParticipantIds": [], "orderBy": "streams_1_day", "labelIds": [], "subaccountIds": [], "distributors": "theorchard,awal,sme", "brandsFilter": { "brandUuids": [] }, "offset": 0, "limit": 500 } response = graphql.fetch_data("TopGlobalSoundRecordings", variables) sound_recordings = response["topGlobalSoundRecordings"] isrcs = [recording["isrc"] for recording in sound_recordings] assert_no_duplicates(isrcs, key_name="ISRC") def test_no_duplicate_ids_in_artists(graphql): variables = { "orderBy": "streams_1_day", "countries": [], "labelIds": [], "globalParticipantIds": [], "subaccountIds": [], "distributors": "theorchard,awal,sme", "orderDir": "DESC", "brandsFilter": { "brandUuids": [] }, "offset": 0, "limit": 500 } response = graphql.fetch_data("TopParticipants", variables) participants = response["topGlobalParticipantsResults"]["participants"] ids = [participant["id"] for participant in participants] assert_no_duplicates(ids, key_name="Participant ID") def test_no_duplicate_upcs_in_products(graphql): variables = { "orderBy": "streams_1_day", "countries": [], "labelIds": [], "globalParticipantIds": [], "brandsFilter": { "brandUuids": [] }, "subaccountIds": [], "orderDir": "DESC", "distributors": "theorchard,awal,sme", "offset": 0, "limit": 500 } response = graphql.fetch_data("TopProducts", variables) products = response["topProductResults"]["products"] upcs = [product["upc"] for product in products] assert_no_duplicates(upcs, key_name="UPC")