def test_get_release_mbids_using_msid(self): """Test if release_mbid are fetched correctly for a given MSID""" msb_listens = self._load_test_data("recordings_for_release_clusters.json") submit_listens(msb_listens) create_release_clusters() with db.engine.begin() as connection: gid_from_data = UUID(data.get_release(connection, "The Blueprint\u00b2: The Gift & The Curse")) release_mbid_1 = get_release_mbids_using_msid(connection, gid_from_data) gid_from_data = UUID(data.get_release(connection, "The Blueprint\u00b2: The Gift and The Curse")) release_mbid_2 = get_release_mbids_using_msid(connection, gid_from_data) self.assertEqual(release_mbid_1, release_mbid_2)
def test_create_release_clusters_for_anomalies(self): """Tests if clusters are created correctly for the anomalies.""" msb_listens = self._load_test_data("recordings_for_release_clusters.json") submit_listens(msb_listens) with db.engine.begin() as connection: clusters_modified, clusters_add_to_redirect = create_release_clusters_without_considering_anomalies(connection) self.assertEqual(clusters_modified, 5) self.assertEqual(clusters_add_to_redirect, 5) # Before clustering anomalies # 'The Notorious KIM' with release MBID '09701309-2f7b-4537-a066-daa1c79b3f06' # is clustered as before no release_gid exists with this release # in release_cluster table before this is inserted. # 'The Blueprint\u00b2: The Gift & The Curse' with release MBID '2c5e4198-24cf-3c95-a16e-83be8e877dfa' # has been clustered. gid_from_data = UUID(data.get_release(connection, "The Notorious KIM")) release_mbids = get_release_mbids_using_msid(connection, gid_from_data) self.assertListEqual(release_mbids, [UUID("09701309-2f7b-4537-a066-daa1c79b3f06")]) gid_from_data = UUID(data.get_release(connection, "The Blueprint\u00b2: The Gift & The Curse")) release_mbids = get_release_mbids_using_msid(connection, gid_from_data) self.assertListEqual(release_mbids, [UUID("2c5e4198-24cf-3c95-a16e-83be8e877dfa")]) clusters_add_to_redirect = create_release_clusters_for_anomalies(connection) self.assertEqual(clusters_add_to_redirect, 2) # After clustering anomalies # 'The Notorious KIM' with release MBID 'e8c8bbf8-15c1-477f-af5b-2c1479af037e' # is clustered and 'The Blueprint\u00b2: The Gift & The Curse' with release MBID # '801678aa-5d30-4342-8227-e9618f164cca' is clustered gid_from_data = UUID(data.get_release(connection, "The Notorious KIM")) release_mbids = set(get_release_mbids_using_msid(connection, gid_from_data)) self.assertSetEqual(release_mbids, set([ UUID("09701309-2f7b-4537-a066-daa1c79b3f06"), UUID("e8c8bbf8-15c1-477f-af5b-2c1479af037e"), ])) gid_from_data = UUID(data.get_release(connection, "The Blueprint\u00b2: The Gift & The Curse")) release_mbids = set(get_release_mbids_using_msid(connection, gid_from_data)) self.assertSetEqual(release_mbids, set([ UUID("2c5e4198-24cf-3c95-a16e-83be8e877dfa"), UUID("801678aa-5d30-4342-8227-e9618f164cca"), ]))
def test_create_release_clusters_without_considering_anomalies(self): """Tests if clusters are created without considering anomalies are are correctly formed. """ msb_listens = self._load_test_data("recordings_for_release_clusters.json") submit_listens(msb_listens) with db.engine.begin() as connection: clusters_modified, clusters_add_to_redirect = create_release_clusters_without_considering_anomalies(connection) self.assertEqual(clusters_modified, 5) self.assertEqual(clusters_add_to_redirect, 5) # 'The Blueprint\u00b2: The Gift & The Curse' and 'The Blueprint\u00b2: The Gift and The Curse' # form one cluster gid_from_data = UUID(data.get_release(connection, "The Blueprint\u00b2: The Gift & The Curse")) release_mbids_1 = get_release_mbids_using_msid(connection, gid_from_data) cluster_id_1 = get_cluster_id_using_msid(connection, gid_from_data) gid_from_data = UUID(data.get_release(connection, "The Blueprint\u00b2: The Gift and The Curse")) release_mbids_2 = get_release_mbids_using_msid(connection, gid_from_data) cluster_id_2 = get_cluster_id_using_msid(connection, gid_from_data) self.assertListEqual(release_mbids_1, release_mbids_2) self.assertEqual(cluster_id_1, cluster_id_2) # 'The Blueprint Collector's Edition' form one cluster gid_from_data = UUID(data.get_release(connection, "The Blueprint Collector's Edition")) release_mbids = get_release_mbids_using_msid(connection, gid_from_data) self.assertListEqual(release_mbids, [UUID("d75e103c-5ef4-4146-ae81-e27d19dc7fc4")]) # 'Syreeta' form one cluster gid_from_data = UUID(data.get_release(connection, "Syreeta")) release_mbids = get_release_mbids_using_msid(connection, gid_from_data) self.assertListEqual(release_mbids, [UUID("5f7853be-1f7a-4850-b0b8-2333d6b0318f")]) # 'Blueprint 2.1' form one cluster gid_from_data = UUID(data.get_release(connection, "Blueprint 2.1")) release_mbids = get_release_mbids_using_msid(connection, gid_from_data) self.assertListEqual(release_mbids, [UUID("7111c8bc-8549-4abc-8ab9-db13f65b4a55")]) # 'The Notorious KIM' with MBID '09701309-2f7b-4537-a066-daa1c79b3f06' form one cluster gid_from_data = UUID(data.get_release(connection, "The Notorious KIM")) release_mbids = get_release_mbids_using_msid(connection, gid_from_data) self.assertListEqual(release_mbids, [UUID("09701309-2f7b-4537-a066-daa1c79b3f06")])
def test_create_release_clusters(self): """Tests if release clusters are correctly formed.""" msb_listens = self._load_test_data( "recordings_for_release_clusters.json") submit_listens(msb_listens) clusters_modified, clusters_add_to_redirect = create_release_clusters() self.assertEqual(clusters_modified, 5) self.assertEqual(clusters_add_to_redirect, 7) with db.engine.begin() as connection: # 'The Blueprint\u00b2: The Gift & The Curse' and 'The Blueprint\u00b2: The Gift and The Curse' # form one cluster gid_from_data = UUID( data.get_release(connection, "The Blueprint\u00b2: The Gift & The Curse")) release_mbids_1 = get_release_mbids_using_msid( connection, gid_from_data) cluster_id_1 = get_cluster_id_using_msid(connection, gid_from_data) gid_from_data = UUID( data.get_release( connection, "The Blueprint\u00b2: The Gift and The Curse")) release_mbids_2 = get_release_mbids_using_msid( connection, gid_from_data) cluster_id_2 = get_cluster_id_using_msid(connection, gid_from_data) self.assertListEqual(release_mbids_1, release_mbids_2) self.assertEqual(cluster_id_1, cluster_id_2) # 'The Blueprint Collector's Edition' form one cluster gid_from_data = UUID( data.get_release(connection, "The Blueprint Collector's Edition")) release_mbids = get_release_mbids_using_msid( connection, gid_from_data) self.assertListEqual( release_mbids, [UUID("d75e103c-5ef4-4146-ae81-e27d19dc7fc4")]) # 'Syreeta' form one cluster gid_from_data = UUID(data.get_release(connection, "Syreeta")) release_mbids = get_release_mbids_using_msid( connection, gid_from_data) self.assertListEqual( release_mbids, [UUID("5f7853be-1f7a-4850-b0b8-2333d6b0318f")]) # 'Blueprint 2.1' form one cluster gid_from_data = UUID(data.get_release(connection, "Blueprint 2.1")) release_mbids = get_release_mbids_using_msid( connection, gid_from_data) self.assertListEqual( release_mbids, [UUID("7111c8bc-8549-4abc-8ab9-db13f65b4a55")]) # After clustering anomalies # 'The Notorious KIM' with MBID '09701309-2f7b-4537-a066-daa1c79b3f06', # 'e8c8bbf8-15c1-477f-af5b-2c1479af037e' form one cluster gid_from_data = UUID( data.get_release(connection, "The Notorious KIM")) release_mbids = set( get_release_mbids_using_msid(connection, gid_from_data)) self.assertSetEqual( release_mbids, set([ UUID("09701309-2f7b-4537-a066-daa1c79b3f06"), UUID("e8c8bbf8-15c1-477f-af5b-2c1479af037e"), ])) # 'The Blueprint\u00b2: The Gift & The Curse' with MBID '2c5e4198-24cf-3c95-a16e-83be8e877dfa', # '801678aa-5d30-4342-8227-e9618f164cca' form one cluster gid_from_data = UUID( data.get_release(connection, "The Blueprint\u00b2: The Gift & The Curse")) release_mbids = set( get_release_mbids_using_msid(connection, gid_from_data)) self.assertSetEqual( release_mbids, set([ UUID("2c5e4198-24cf-3c95-a16e-83be8e877dfa"), UUID("801678aa-5d30-4342-8227-e9618f164cca"), ])) # Inserting new recordings # recording_1 is already clustered recording_1 = { "artist": "Jay‐Z and Beyoncé", "title": "'03 Bonnie and Clyde", "release_mbid": "2c5e4198-24cf-3c95-a16e-83be8e877dfa", "release": "The Blueprint\u00b2: The Gift and The Curse", } # recording_2, recording_3 are new recordings recording_2 = { "artist": "Donal Leace", "title": "Today Won't Come Again", "release_mbid": "2b82a22b-0492-44be-bfd8-d1cee7d259fb", "release": "Donal Leace", } recording_3 = { "artist": "Memphis Minnie", "title": "Banana Man Blues", "release_mbid": "27b3c191-7e46-4d00-b6bb-cdce39c13568", "release": "Please Warm My Weiner: Old Time Hokum Blues", } submit_listens([recording_1, recording_2, recording_3]) clusters_modified, clusters_add_to_redirect = create_release_clusters( ) self.assertEqual(clusters_modified, 2) self.assertEqual(clusters_add_to_redirect, 2) # After clustering retry creating clusters clusters_modified, clusters_add_to_redirect = create_release_clusters( ) self.assertEqual(clusters_modified, 0) self.assertEqual(clusters_add_to_redirect, 0)