#NEWLINE# @ with_database #NEWLINE# def test_merge_tracks( conn ) : #NEWLINE# #INDENT# prepare_database ( conn , "\nTRUNCATE track_mbid CASCADE;\nINSERT INTO fingerprint (fingerprint, length, track_id, submission_count)\n    VALUES (%(fp1)s, %(len1)s, 1, 1), (%(fp2)s, %(len2)s, 2, 1);\nINSERT INTO track_mbid (id, track_id, mbid, submission_count) VALUES (1, 1, '97edb73c-4dac-11e0-9096-0025225356f3', 10);\nINSERT INTO track_mbid (id, track_id, mbid, submission_count) VALUES (2, 1, 'd575d506-4da4-11e0-b951-0025225356f3', 15);\nINSERT INTO track_mbid (id, track_id, mbid, submission_count) VALUES (3, 2, 'd575d506-4da4-11e0-b951-0025225356f3', 50);\nINSERT INTO track_mbid (id, track_id, mbid, submission_count) VALUES (4, 3, '97edb73c-4dac-11e0-9096-0025225356f3', 25);\nINSERT INTO track_mbid (id, track_id, mbid, submission_count) VALUES (5, 4, '5d0290a6-4dad-11e0-a47a-0025225356f3', 30);\nINSERT INTO track_puid (track_id, puid, submission_count) VALUES (1, '97edb73c-4dac-11e0-9096-0025225356f4', 10);\nINSERT INTO track_puid (track_id, puid, submission_count) VALUES (1, 'd575d506-4da4-11e0-b951-0025225356f4', 15);\nINSERT INTO track_puid (track_id, puid, submission_count) VALUES (2, 'd575d506-4da4-11e0-b951-0025225356f4', 50);\nINSERT INTO track_puid (track_id, puid, submission_count) VALUES (3, '97edb73c-4dac-11e0-9096-0025225356f4', 25);\nINSERT INTO track_puid (track_id, puid, submission_count) VALUES (4, '5d0290a6-4dad-11e0-a47a-0025225356f4', 30);\nINSERT INTO track_mbid_change (track_mbid_id, account_id, disabled) VALUES (2, 1, true);\nINSERT INTO track_mbid_change (track_mbid_id, account_id, disabled) VALUES (3, 1, true);\nINSERT INTO track_mbid_change (track_mbid_id, account_id, disabled) VALUES (4, 1, true);\nINSERT INTO track_mbid_change (track_mbid_id, account_id, disabled) VALUES (5, 1, true);\n    " , dict ( fp1 = TEST_1A_FP_RAW , len1 = TEST_1A_LENGTH , fp2 = TEST_1B_FP_RAW , len2 = TEST_1B_LENGTH ) ) #NEWLINE# merge_tracks ( conn , 3 , [ 1 , 2 , 4 ] ) #NEWLINE# rows = conn . execute ( 'SELECT id, track_id FROM fingerprint ORDER BY id' ) . fetchall ( ) #NEWLINE# assert_equals ( [ ( 1 , 3 ) , ( 2 , 3 ) ] , rows ) #NEWLINE# rows = conn . execute ( 'SELECT id, track_id, mbid, submission_count FROM track_mbid ORDER BY track_id, mbid' ) . fetchall ( ) #NEWLINE# expected = [ ( 5 , 3 , '5d0290a6-4dad-11e0-a47a-0025225356f3' , 30 ) , ( 1 , 3 , '97edb73c-4dac-11e0-9096-0025225356f3' , 35 ) , ( 2 , 3 , 'd575d506-4da4-11e0-b951-0025225356f3' , 65 ) ] #NEWLINE# assert_equals ( expected , conn ) #NEWLINE# rows = conn . execute ( 'SELECT track_id, puid, submission_count FROM track_puid ORDER BY track_id, puid' ) . fetchall ( ) #NEWLINE# expected = [ ( 3 , '5d0290a6-4dad-11e0-a47a-0025225356f4' , 30 ) , ( 3 , '97edb73c-4dac-11e0-9096-0025225356f4' , 35 ) , ( 3 , 'd575d506-4da4-11e0-b951-0025225356f4' , 65 ) ] #NEWLINE# assert_equals ( expected , rows ) #NEWLINE# rows = conn . execute ( 'SELECT track_mbid_id, account_id FROM track_mbid_change ORDER BY track_mbid_id, account_id' ) . fetchall ( ) #NEWLINE# expected_rows = [ ( 1 , 1 ) , ( 2 , 1 ) , ( 2 , 1 ) , ( 5 , 1 ) ] #NEWLINE# assert_equals ( expected_rows , rows ) #NEWLINE# rows = conn . execute ( 'SELECT id, new_id FROM track ORDER BY id, new_id' ) . fetchall ( ) #NEWLINE# assert_equals ( [ ( 1 , 3 ) , ( 2 , 3 ) , ( 3 , None ) , ( 4 , 3 ) ] , rows )