def test_merge_mbids(conn):
    insert_submission(conn, {'fingerprint': [1], 'length': 123, 'source_id': 1})
    insert_submission(conn, {'fingerprint': [1], 'length': 123, 'source_id': 1})
    prepare_database(conn, """
TRUNCATE track_mbid CASCADE;
INSERT INTO track_mbid (id, track_id, mbid, submission_count) VALUES (1, 1, '97edb73c-4dac-11e0-9096-0025225356f3', 9);
INSERT INTO track_mbid (id, track_id, mbid, submission_count) VALUES (2, 1, 'd575d506-4da4-11e0-b951-0025225356f3', 11);
INSERT INTO track_mbid_source (track_mbid_id, submission_id, source_id) VALUES (1, 1, 1);
INSERT INTO track_mbid_source (track_mbid_id, submission_id, source_id) VALUES (2, 2, 1);
INSERT INTO track_mbid_change (track_mbid_id, account_id, disabled) VALUES (1, 1, true);
INSERT INTO track_mbid_change (track_mbid_id, account_id, disabled) VALUES (2, 1, true);
""")
    merge_mbids(conn, '97edb73c-4dac-11e0-9096-0025225356f3', ['d575d506-4da4-11e0-b951-0025225356f3'])
    rows = conn.execute("SELECT track_id, mbid, submission_count, disabled FROM track_mbid ORDER BY track_id, mbid").fetchall()
    expected_rows = [
        (1, '97edb73c-4dac-11e0-9096-0025225356f3', 20, False),
    ]
    assert_equals(expected_rows, rows)
    rows = conn.execute("SELECT track_mbid_id, submission_id, source_id FROM track_mbid_source ORDER BY track_mbid_id, submission_id, source_id").fetchall()
    expected_rows = [
        (1, 1, 1),
        (1, 2, 1),
    ]
    assert_equals(expected_rows, rows)
    rows = conn.execute("SELECT track_mbid_id, account_id FROM track_mbid_change ORDER BY track_mbid_id, account_id").fetchall()
    expected_rows = [
        (1, 1),
        (1, 1),
    ]
    assert_equals(expected_rows, rows)
def test_merge_mbids_disabled_both(conn):
    prepare_database(conn, """
TRUNCATE track_mbid CASCADE;
INSERT INTO track_mbid (track_id, mbid, submission_count, disabled) VALUES (1, '97edb73c-4dac-11e0-9096-0025225356f3', 9, true);
INSERT INTO track_mbid (track_id, mbid, submission_count, disabled) VALUES (1, 'd575d506-4da4-11e0-b951-0025225356f3', 11, true);
""")
    merge_mbids(conn, '97edb73c-4dac-11e0-9096-0025225356f3', ['d575d506-4da4-11e0-b951-0025225356f3'])
    rows = conn.execute("SELECT track_id, mbid, submission_count, disabled FROM track_mbid ORDER BY track_id, mbid").fetchall()
    expected_rows = [
        (1, '97edb73c-4dac-11e0-9096-0025225356f3', 20, True),
    ]
    assert_equals(expected_rows, rows)
Example #3
0
def test_merge_mbids_disabled_source(ctx):
    # type: (ScriptContext) -> None
    prepare_database(ctx.db.get_fingerprint_db(), """
TRUNCATE track_mbid CASCADE;
INSERT INTO track_mbid (track_id, mbid, submission_count) VALUES (1, '97edb73c-4dac-11e0-9096-0025225356f3', 9);
INSERT INTO track_mbid (track_id, mbid, submission_count, disabled) VALUES (1, 'd575d506-4da4-11e0-b951-0025225356f3', 11, true);
""")
    merge_mbids(ctx.db.get_fingerprint_db(), ctx.db.get_ingest_db(), '97edb73c-4dac-11e0-9096-0025225356f3', ['d575d506-4da4-11e0-b951-0025225356f3'])
    rows = ctx.db.get_fingerprint_db().execute("SELECT track_id, mbid, submission_count, disabled FROM track_mbid ORDER BY track_id, mbid").fetchall()
    expected_rows = [
        (1, UUID('97edb73c-4dac-11e0-9096-0025225356f3'), 20, False),
    ]
    assert_equals(expected_rows, rows)
def test_merge_mbids_disabled_target(conn):
    prepare_database(
        conn, """
TRUNCATE track_mbid CASCADE;
INSERT INTO track_mbid (track_id, mbid, submission_count, disabled) VALUES (1, '97edb73c-4dac-11e0-9096-0025225356f3', 9, true);
INSERT INTO track_mbid (track_id, mbid, submission_count) VALUES (1, 'd575d506-4da4-11e0-b951-0025225356f3', 11);
""")
    merge_mbids(conn, '97edb73c-4dac-11e0-9096-0025225356f3',
                ['d575d506-4da4-11e0-b951-0025225356f3'])
    rows = conn.execute(
        "SELECT track_id, mbid, submission_count, disabled FROM track_mbid ORDER BY track_id, mbid"
    ).fetchall()
    expected_rows = [
        (1, UUID('97edb73c-4dac-11e0-9096-0025225356f3'), 20, False),
    ]
    assert_equals(expected_rows, rows)
def test_merge_mbids(conn):
    insert_submission(conn, {
        'fingerprint': [1],
        'length': 123,
        'source_id': 1
    })
    insert_submission(conn, {
        'fingerprint': [1],
        'length': 123,
        'source_id': 1
    })
    prepare_database(
        conn, """
TRUNCATE track_mbid CASCADE;
INSERT INTO track_mbid (id, track_id, mbid, submission_count) VALUES (1, 1, '97edb73c-4dac-11e0-9096-0025225356f3', 9);
INSERT INTO track_mbid (id, track_id, mbid, submission_count) VALUES (2, 1, 'd575d506-4da4-11e0-b951-0025225356f3', 11);
INSERT INTO track_mbid_source (track_mbid_id, submission_id, source_id) VALUES (1, 1, 1);
INSERT INTO track_mbid_source (track_mbid_id, submission_id, source_id) VALUES (2, 2, 1);
INSERT INTO track_mbid_change (track_mbid_id, account_id, disabled) VALUES (1, 1, true);
INSERT INTO track_mbid_change (track_mbid_id, account_id, disabled) VALUES (2, 1, true);
""")
    merge_mbids(conn, '97edb73c-4dac-11e0-9096-0025225356f3',
                ['d575d506-4da4-11e0-b951-0025225356f3'])
    rows = conn.execute(
        "SELECT track_id, mbid, submission_count, disabled FROM track_mbid ORDER BY track_id, mbid"
    ).fetchall()
    expected_rows = [
        (1, UUID('97edb73c-4dac-11e0-9096-0025225356f3'), 20, False),
    ]
    assert_equals(expected_rows, rows)
    rows = conn.execute(
        "SELECT track_mbid_id, submission_id, source_id FROM track_mbid_source ORDER BY track_mbid_id, submission_id, source_id"
    ).fetchall()
    expected_rows = [
        (1, 1, 1),
        (1, 2, 1),
    ]
    assert_equals(expected_rows, rows)
    rows = conn.execute(
        "SELECT track_mbid_id, account_id FROM track_mbid_change ORDER BY track_mbid_id, account_id"
    ).fetchall()
    expected_rows = [
        (1, 1),
        (1, 1),
    ]
    assert_equals(expected_rows, rows)