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_import_submission_merge_existing_tracks(conn):
    prepare_database(conn, """
    INSERT INTO fingerprint (fingerprint, length, track_id, submission_count)
        VALUES (%(fp1)s, %(len1)s, 1, 1), (%(fp2)s, %(len2)s, 2, 1);
    """, dict(fp1=TEST_1A_FP_RAW, len1=TEST_1A_LENGTH,
              fp2=TEST_1B_FP_RAW, len2=TEST_1B_LENGTH))
    id = insert_submission(conn, {
        'fingerprint': TEST_1C_FP_RAW,
        'length': TEST_1C_LENGTH,
        'source_id': 1,
        'mbid': '1f143d2b-db04-47cc-82a0-eee6efaa1142',
        'puid': '7c1c6753-c834-44b1-884a-a5166c093139',
    })
    query = tables.submission.select(tables.submission.c.id == id)
    submission = conn.execute(query).fetchone()
    assert_false(submission['handled'])
    try:
        old_threshold = const.FINGERPRINT_MERGE_THRESHOLD
        const.FINGERPRINT_MERGE_THRESHOLD = 0.85
        fingerprint = import_submission(conn, submission)
    finally:
        const.FINGERPRINT_MERGE_THRESHOLD = old_threshold
    assert_equals(1, fingerprint['id'])
    assert_equals(1, fingerprint['track_id'])
    query = tables.fingerprint.select(tables.fingerprint.c.id == 1)
    fingerprint = conn.execute(query).fetchone()
    assert_equals(1, fingerprint['track_id'])
    query = tables.track.select(tables.track.c.id == 1)
    track = conn.execute(query).fetchone()
    assert_equals(None, track['new_id'])
    query = tables.track.select(tables.track.c.id == 2)
    track = conn.execute(query).fetchone()
    assert_equals(1, track['new_id'])
def test_can_merge_tracks(conn):
    prepare_database(conn, """
INSERT INTO fingerprint (fingerprint, length, track_id, submission_count)
    VALUES (%(fp1)s, %(len1)s, 1, 1), (%(fp2)s, %(len2)s, 2, 1),
           (%(fp3)s, %(len3)s, 3, 1);
    """, dict(fp1=TEST_1A_FP_RAW, len1=TEST_1A_LENGTH,
              fp2=TEST_1B_FP_RAW, len2=TEST_1B_LENGTH,
              fp3=TEST_2_FP_RAW, len3=TEST_2_LENGTH))
    groups = can_merge_tracks(conn, [1, 2, 3])
    assert_equal([set([1, 2])], groups)
def test_can_add_fp_to_track(conn):
    prepare_database(conn, """
INSERT INTO fingerprint (fingerprint, length, track_id, submission_count)
    VALUES (%(fp1)s, %(len1)s, 1, 1);
    """, dict(fp1=TEST_1A_FP_RAW, len1=TEST_1A_LENGTH))
    res = can_add_fp_to_track(conn, 1, TEST_2_FP_RAW, TEST_2_LENGTH)
    assert_equal(False, res)
    res = can_add_fp_to_track(conn, 1, TEST_1B_FP_RAW, TEST_1B_LENGTH + 20)
    assert_equal(False, res)
    res = can_add_fp_to_track(conn, 1, TEST_1B_FP_RAW, TEST_1B_LENGTH)
    assert_equal(True, res)
def test_merge_tracks_disabled_source(conn):
    prepare_database(conn, """
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 (2, '97edb73c-4dac-11e0-9096-0025225356f3', 11, true);
""")
    merge_tracks(conn, 1, [2])
    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)
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)
Пример #7
0
def test_can_add_fp_to_track(conn):
    prepare_database(
        conn, """
INSERT INTO fingerprint (fingerprint, length, track_id, submission_count)
    VALUES (%(fp1)s, %(len1)s, 1, 1);
    """, dict(fp1=TEST_1A_FP_RAW, len1=TEST_1A_LENGTH))
    res = can_add_fp_to_track(conn, 1, TEST_2_FP_RAW, TEST_2_LENGTH)
    assert_equals(False, res)
    res = can_add_fp_to_track(conn, 1, TEST_1B_FP_RAW, TEST_1B_LENGTH + 20)
    assert_equals(False, res)
    res = can_add_fp_to_track(conn, 1, TEST_1B_FP_RAW, TEST_1B_LENGTH)
    assert_equals(True, res)
Пример #8
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)
Пример #9
0
def test_find_current_stats(conn):
    prepare_database(conn, """
    INSERT INTO stats (name, value, date) VALUES
        ('account.all', 3, '2011-04-25'),
        ('account.all', 3, '2011-04-26'),
        ('account.all', 4, '2011-04-27'),
        ('track.all', 13, '2011-04-25'),
        ('track.all', 13, '2011-04-26'),
        ('track.all', 14, '2011-04-27');
    """)
    stats = find_current_stats(conn)
    assert_equals(4, stats['account.all'])
    assert_equals(14, stats['track.all'])
Пример #10
0
def test_find_current_stats(conn):
    prepare_database(conn, """
    INSERT INTO stats (name, value, date) VALUES
        ('account.all', 3, '2011-04-25'),
        ('account.all', 3, '2011-04-26'),
        ('account.all', 4, '2011-04-27'),
        ('track.all', 13, '2011-04-25'),
        ('track.all', 13, '2011-04-26'),
        ('track.all', 14, '2011-04-27');
    """)
    stats = find_current_stats(conn)
    assert_equals(4, stats['account.all'])
    assert_equals(14, stats['track.all'])
def test_merge_tracks(conn):
    prepare_database(
        conn, """
TRUNCATE track_mbid CASCADE;
INSERT INTO fingerprint (fingerprint, length, track_id, submission_count)
    VALUES (%(fp1)s, %(len1)s, 1, 1), (%(fp2)s, %(len2)s, 2, 1);
INSERT INTO track_mbid (id, track_id, mbid, submission_count) VALUES (1, 1, '97edb73c-4dac-11e0-9096-0025225356f3', 10);
INSERT INTO track_mbid (id, track_id, mbid, submission_count) VALUES (2, 1, 'd575d506-4da4-11e0-b951-0025225356f3', 15);
INSERT INTO track_mbid (id, track_id, mbid, submission_count) VALUES (3, 2, 'd575d506-4da4-11e0-b951-0025225356f3', 50);
INSERT INTO track_mbid (id, track_id, mbid, submission_count) VALUES (4, 3, '97edb73c-4dac-11e0-9096-0025225356f3', 25);
INSERT INTO track_mbid (id, track_id, mbid, submission_count) VALUES (5, 4, '5d0290a6-4dad-11e0-a47a-0025225356f3', 30);
INSERT INTO track_puid (track_id, puid, submission_count) VALUES (1, '97edb73c-4dac-11e0-9096-0025225356f4', 10);
INSERT INTO track_puid (track_id, puid, submission_count) VALUES (1, 'd575d506-4da4-11e0-b951-0025225356f4', 15);
INSERT INTO track_puid (track_id, puid, submission_count) VALUES (2, 'd575d506-4da4-11e0-b951-0025225356f4', 50);
INSERT INTO track_puid (track_id, puid, submission_count) VALUES (3, '97edb73c-4dac-11e0-9096-0025225356f4', 25);
INSERT INTO track_puid (track_id, puid, submission_count) VALUES (4, '5d0290a6-4dad-11e0-a47a-0025225356f4', 30);
INSERT INTO track_mbid_change (track_mbid_id, account_id, disabled) VALUES (2, 1, true);
INSERT INTO track_mbid_change (track_mbid_id, account_id, disabled) VALUES (3, 1, true);
INSERT INTO track_mbid_change (track_mbid_id, account_id, disabled) VALUES (4, 1, true);
INSERT INTO track_mbid_change (track_mbid_id, account_id, disabled) VALUES (5, 1, true);
    """,
        dict(fp1=TEST_1A_FP_RAW,
             len1=TEST_1A_LENGTH,
             fp2=TEST_1B_FP_RAW,
             len2=TEST_1B_LENGTH))
    merge_tracks(conn, 3, [1, 2, 4])
    rows = conn.execute(
        "SELECT id, track_id FROM fingerprint ORDER BY id").fetchall()
    assert_equals([(1, 3), (2, 3)], rows)
    rows = conn.execute(
        "SELECT id, track_id, mbid, submission_count FROM track_mbid ORDER BY track_id, mbid"
    ).fetchall()
    expected = [(5, 3, UUID('5d0290a6-4dad-11e0-a47a-0025225356f3'), 30),
                (1, 3, UUID('97edb73c-4dac-11e0-9096-0025225356f3'), 35),
                (2, 3, UUID('d575d506-4da4-11e0-b951-0025225356f3'), 65)]
    assert_equals(expected, rows)
    rows = conn.execute(
        "SELECT track_id, puid, submission_count FROM track_puid ORDER BY track_id, puid"
    ).fetchall()
    expected = [(3, UUID('5d0290a6-4dad-11e0-a47a-0025225356f4'), 30),
                (3, UUID('97edb73c-4dac-11e0-9096-0025225356f4'), 35),
                (3, UUID('d575d506-4da4-11e0-b951-0025225356f4'), 65)]
    assert_equals(expected, 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), (2, 1), (2, 1), (5, 1)]
    assert_equals(expected_rows, rows)
    rows = conn.execute(
        "SELECT id, new_id FROM track ORDER BY id, new_id").fetchall()
    assert_equals([(1, 3), (2, 3), (3, None), (4, 3)], rows)
Пример #12
0
def prepare_database(ctx):
    """
    Drops schema of the current database and creates the new one with applied migrations. Designed for test running
    purpose only.

    Usage:
        inv dev.prepare_database
    """

    from config import set_config
    set_config('testing')

    from tests import prepare_database
    prepare_database()
def test_merge_tracks_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 (2, '97edb73c-4dac-11e0-9096-0025225356f3', 11, true);
""")
    merge_tracks(conn, 1, [2])
    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, True),
    ]
    assert_equals(expected_rows, rows)
def test_can_merge_tracks(conn):
    prepare_database(
        conn, """
INSERT INTO fingerprint (fingerprint, length, track_id, submission_count)
    VALUES (%(fp1)s, %(len1)s, 1, 1), (%(fp2)s, %(len2)s, 2, 1),
           (%(fp3)s, %(len3)s, 3, 1);
    """,
        dict(fp1=TEST_1A_FP_RAW,
             len1=TEST_1A_LENGTH,
             fp2=TEST_1B_FP_RAW,
             len2=TEST_1B_LENGTH,
             fp3=TEST_2_FP_RAW,
             len3=TEST_2_LENGTH))
    groups = can_merge_tracks(conn, [1, 2, 3])
    assert_equal([set([1, 2])], groups)
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)
Пример #17
0
def test_import_submission_new_track_different(conn):
    prepare_database(conn, """
    INSERT INTO fingerprint (fingerprint, length, track_id, submission_count)
        VALUES (%(fp)s, %(len)s, 1, 1);
    """, dict(fp=TEST_1A_FP_RAW, len=TEST_1A_LENGTH))
    id = insert_submission(conn, {
        'fingerprint': TEST_2_FP_RAW,
        'length': TEST_2_LENGTH,
        'source_id': 1,
        'mbid': '1f143d2b-db04-47cc-82a0-eee6efaa1142',
        'puid': '7c1c6753-c834-44b1-884a-a5166c093139',
    })
    query = tables.submission.select(tables.submission.c.id == id)
    submission = conn.execute(query).fetchone()
    assert_false(submission['handled'])
    fingerprint = import_submission(conn, submission)
    assert_equals(2, fingerprint['id'])
    assert_equals(5, fingerprint['track_id'])
Пример #18
0
def test_import_submission_with_foreignid(conn):
    prepare_database(conn, """
    INSERT INTO foreignid_vendor (id, name) VALUES (1, 'foo');
    INSERT INTO foreignid (id, vendor_id, name) VALUES (1, 1, '123');
    """)
    id = insert_submission(conn, {
        'fingerprint': TEST_1_FP_RAW,
        'length': TEST_1_LENGTH,
        'bitrate': 192,
        'source_id': 1,
        'format_id': 1,
        'foreignid_id': 1,
    })
    query = tables.submission.select(tables.submission.c.id == id)
    submission = conn.execute(query).fetchone()
    fingerprint = import_submission(conn, submission)
    query = tables.track_foreignid.select(tables.track_foreignid.c.track_id == fingerprint['track_id'])
    track_foreignid = conn.execute(query).fetchone()
    assert_equals(1, track_foreignid['submission_count'])
Пример #19
0
def test_merge_tracks(conn):
    prepare_database(conn, """
TRUNCATE track_mbid CASCADE;
INSERT INTO fingerprint (fingerprint, length, track_id, submission_count)
    VALUES (%(fp1)s, %(len1)s, 1, 1), (%(fp2)s, %(len2)s, 2, 1);
INSERT INTO track_mbid (id, track_id, mbid, submission_count) VALUES (1, 1, '97edb73c-4dac-11e0-9096-0025225356f3', 10);
INSERT INTO track_mbid (id, track_id, mbid, submission_count) VALUES (2, 1, 'd575d506-4da4-11e0-b951-0025225356f3', 15);
INSERT INTO track_mbid (id, track_id, mbid, submission_count) VALUES (3, 2, 'd575d506-4da4-11e0-b951-0025225356f3', 50);
INSERT INTO track_mbid (id, track_id, mbid, submission_count) VALUES (4, 3, '97edb73c-4dac-11e0-9096-0025225356f3', 25);
INSERT INTO track_mbid (id, track_id, mbid, submission_count) VALUES (5, 4, '5d0290a6-4dad-11e0-a47a-0025225356f3', 30);
INSERT INTO track_puid (track_id, puid, submission_count) VALUES (1, '97edb73c-4dac-11e0-9096-0025225356f4', 10);
INSERT INTO track_puid (track_id, puid, submission_count) VALUES (1, 'd575d506-4da4-11e0-b951-0025225356f4', 15);
INSERT INTO track_puid (track_id, puid, submission_count) VALUES (2, 'd575d506-4da4-11e0-b951-0025225356f4', 50);
INSERT INTO track_puid (track_id, puid, submission_count) VALUES (3, '97edb73c-4dac-11e0-9096-0025225356f4', 25);
INSERT INTO track_puid (track_id, puid, submission_count) VALUES (4, '5d0290a6-4dad-11e0-a47a-0025225356f4', 30);
INSERT INTO track_mbid_change (track_mbid_id, account_id, disabled) VALUES (2, 1, true);
INSERT INTO track_mbid_change (track_mbid_id, account_id, disabled) VALUES (3, 1, true);
INSERT INTO track_mbid_change (track_mbid_id, account_id, disabled) VALUES (4, 1, true);
INSERT INTO track_mbid_change (track_mbid_id, account_id, disabled) VALUES (5, 1, true);
    """, dict(fp1=TEST_1A_FP_RAW, len1=TEST_1A_LENGTH,
              fp2=TEST_1B_FP_RAW, len2=TEST_1B_LENGTH))
    merge_tracks(conn, 3, [1, 2, 4])
    rows = conn.execute("SELECT id, track_id FROM fingerprint ORDER BY id").fetchall()
    assert_equals([(1, 3), (2, 3)], rows)
    rows = conn.execute("SELECT id, track_id, mbid, submission_count FROM track_mbid ORDER BY track_id, mbid").fetchall()
    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)
    ]
    assert_equals(expected, rows)
    rows = conn.execute("SELECT track_id, puid, submission_count FROM track_puid ORDER BY track_id, puid").fetchall()
    expected = [
        (3, '5d0290a6-4dad-11e0-a47a-0025225356f4', 30),
        (3, '97edb73c-4dac-11e0-9096-0025225356f4', 35),
        (3, 'd575d506-4da4-11e0-b951-0025225356f4', 65)
    ]
    assert_equals(expected, 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), (2, 1), (2, 1), (5, 1)]
    assert_equals(expected_rows, rows)
    rows = conn.execute("SELECT id, new_id FROM track ORDER BY id, new_id").fetchall()
    assert_equals([(1, 3), (2, 3), (3, None), (4, 3)], rows)
Пример #20
0
def test_lookup_handler(conn):
    values = {'client': 'app1key', 'length': str(TEST_1_LENGTH), 'fingerprint': TEST_1_FP}
    builder = EnvironBuilder(method='POST', data=values)
    handler = LookupHandler(connect=provider(conn))
    # no matches
    handler = LookupHandler(connect=provider(conn))
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('text/xml; charset=UTF-8', resp.content_type)
    expected = "<?xml version='1.0' encoding='UTF-8'?>\n<response><status>ok</status><results /></response>"
    assert_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
    # one exact match
    prepare_database(conn, """
INSERT INTO fingerprint (length, fingerprint, source_id, track_id)
    VALUES (%s, %s, 1, 1);
""", (TEST_1_LENGTH, TEST_1_FP_RAW))
    handler = LookupHandler(connect=provider(conn))
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('text/xml; charset=UTF-8', resp.content_type)
    expected = "<?xml version='1.0' encoding='UTF-8'?>\n<response><status>ok</status><results><result><score>1.0</score><id>1</id></result></results></response>"
    assert_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
    # one exact match with MBIDs
    values = {'client': 'app1key', 'length': str(TEST_1_LENGTH), 'fingerprint': TEST_1_FP, 'meta': '1'}
    builder = EnvironBuilder(method='POST', data=values)
    handler = LookupHandler(connect=provider(conn))
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('text/xml; charset=UTF-8', resp.content_type)
    expected = "<?xml version='1.0' encoding='UTF-8'?>\n<response><status>ok</status><results><result><tracks><track><id>b81f83ee-4da4-11e0-9ed8-0025225356f3</id></track></tracks><score>1.0</score><id>1</id></result></results></response>"
    assert_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
    # one exact match with MBIDs (no exta metadata in v1)
    values = {'client': 'app1key', 'length': str(TEST_1_LENGTH), 'fingerprint': TEST_1_FP, 'meta': '2'}
    builder = EnvironBuilder(method='POST', data=values)
    handler = LookupHandler(connect=provider(conn))
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('text/xml; charset=UTF-8', resp.content_type)
    expected = "<?xml version='1.0' encoding='UTF-8'?>\n<response><status>ok</status><results><result><tracks><track><id>b81f83ee-4da4-11e0-9ed8-0025225356f3</id></track></tracks><score>1.0</score><id>1</id></result></results></response>"
    #expected = "<?xml version='1.0' encoding='UTF-8'?>\n<response><status>ok</status><results><result><tracks><track><length>123</length><artist><id>a64796c0-4da4-11e0-bf81-0025225356f3</id><name>Artist A</name></artist><id>b81f83ee-4da4-11e0-9ed8-0025225356f3</id><releases><release><track_num>1</track_num><id>dd6c2cca-a0e9-4cc4-9a5f-7170bd098e23</id><track_count>2</track_count><name>Album A</name></release></releases><name>Track A</name></track></tracks><score>1.0</score><id>1</id></result></results></response>"
    assert_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
Пример #21
0
def test_lookup_handler(conn):
    values = {'client': 'app1key', 'length': str(TEST_1_LENGTH), 'fingerprint': TEST_1_FP}
    builder = EnvironBuilder(method='POST', data=values)
    handler = LookupHandler(connect=provider(conn))
    # no matches
    handler = LookupHandler(connect=provider(conn))
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('text/xml; charset=UTF-8', resp.content_type)
    expected = "<?xml version='1.0' encoding='UTF-8'?>\n<response><status>ok</status><results /></response>"
    assert_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
    # one exact match
    prepare_database(conn, """
INSERT INTO fingerprint (length, fingerprint, track_id, submission_count)
    VALUES (%s, %s, 1, 1);
""", (TEST_1_LENGTH, TEST_1_FP_RAW))
    handler = LookupHandler(connect=provider(conn))
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('text/xml; charset=UTF-8', resp.content_type)
    expected = "<?xml version='1.0' encoding='UTF-8'?>\n<response><status>ok</status><results><result><score>1.0</score><id>eb31d1c3-950e-468b-9e36-e46fa75b1291</id></result></results></response>"
    assert_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
    # one exact match with MBIDs
    values = {'client': 'app1key', 'length': str(TEST_1_LENGTH), 'fingerprint': TEST_1_FP, 'meta': '1'}
    builder = EnvironBuilder(method='POST', data=values)
    handler = LookupHandler(connect=provider(conn))
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('text/xml; charset=UTF-8', resp.content_type)
    expected = "<?xml version='1.0' encoding='UTF-8'?>\n<response><status>ok</status><results><result><tracks><track><id>b81f83ee-4da4-11e0-9ed8-0025225356f3</id></track></tracks><score>1.0</score><id>eb31d1c3-950e-468b-9e36-e46fa75b1291</id></result></results></response>"
    assert_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
    # one exact match with MBIDs (no exta metadata in v1)
    values = {'client': 'app1key', 'length': str(TEST_1_LENGTH), 'fingerprint': TEST_1_FP, 'meta': '2'}
    builder = EnvironBuilder(method='POST', data=values)
    handler = LookupHandler(connect=provider(conn))
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('text/xml; charset=UTF-8', resp.content_type)
    expected = "<?xml version='1.0' encoding='UTF-8'?>\n<response><status>ok</status><results><result><tracks><track><id>b81f83ee-4da4-11e0-9ed8-0025225356f3</id></track></tracks><score>1.0</score><id>eb31d1c3-950e-468b-9e36-e46fa75b1291</id></result></results></response>"
    #expected = "<?xml version='1.0' encoding='UTF-8'?>\n<response><status>ok</status><results><result><tracks><track><length>123</length><artist><id>a64796c0-4da4-11e0-bf81-0025225356f3</id><name>Artist A</name></artist><id>b81f83ee-4da4-11e0-9ed8-0025225356f3</id><releases><release><track_num>1</track_num><id>dd6c2cca-a0e9-4cc4-9a5f-7170bd098e23</id><track_count>2</track_count><name>Album A</name></release></releases><name>Track A</name></track></tracks><score>1.0</score><id>1</id></result></results></response>"
    assert_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
Пример #22
0
def lookup_handler(ctx):
    # type: (ScriptContext) -> None
    values = {'client': 'app1key', 'length': str(TEST_1_LENGTH), 'fingerprint': TEST_1_FP}
    builder = EnvironBuilder(method='POST', data=values)
    # no matches
    handler = LookupHandler(ctx)
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('text/xml; charset=UTF-8', resp.content_type)
    expected = "<?xml version='1.0' encoding='UTF-8'?>\n<response><status>ok</status><results /></response>"
    assert_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
    # one exact match
    prepare_database(ctx.db.get_fingerprint_db(), """
INSERT INTO fingerprint (length, fingerprint, track_id, submission_count)
    VALUES (%s, %s, 1, 1);
""", (TEST_1_LENGTH, TEST_1_FP_RAW))
    handler = LookupHandler(ctx)
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('text/xml; charset=UTF-8', resp.content_type)
    expected = "<?xml version='1.0' encoding='UTF-8'?>\n<response><status>ok</status><results><result><score>1.0</score><id>eb31d1c3-950e-468b-9e36-e46fa75b1291</id></result></results></response>"
    assert_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
    # one exact match with MBIDs
    values = {'client': 'app1key', 'length': str(TEST_1_LENGTH), 'fingerprint': TEST_1_FP, 'meta': '1'}
    builder = EnvironBuilder(method='POST', data=values)
    handler = LookupHandler(ctx)
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('text/xml; charset=UTF-8', resp.content_type)
    expected = "<?xml version='1.0' encoding='UTF-8'?>\n<response><status>ok</status><results><result><tracks><track><id>b81f83ee-4da4-11e0-9ed8-0025225356f3</id></track></tracks><score>1.0</score><id>eb31d1c3-950e-468b-9e36-e46fa75b1291</id></result></results></response>"
    assert_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
    # one exact match with MBIDs (no exta metadata in v1)
    values = {'client': 'app1key', 'length': str(TEST_1_LENGTH), 'fingerprint': TEST_1_FP, 'meta': '2'}
    builder = EnvironBuilder(method='POST', data=values)
    handler = LookupHandler(ctx)
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('text/xml; charset=UTF-8', resp.content_type)
    expected = "<?xml version='1.0' encoding='UTF-8'?>\n<response><status>ok</status><results><result><tracks><track><id>b81f83ee-4da4-11e0-9ed8-0025225356f3</id></track></tracks><score>1.0</score><id>eb31d1c3-950e-468b-9e36-e46fa75b1291</id></result></results></response>"
    assert_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
Пример #23
0
def test_import_submission_merge_existing_tracks(conn):
    prepare_database(
        conn, """
    INSERT INTO fingerprint (fingerprint, length, track_id, submission_count)
        VALUES (%(fp1)s, %(len1)s, 1, 1), (%(fp2)s, %(len2)s, 2, 1);
    """,
        dict(fp1=TEST_1A_FP_RAW,
             len1=TEST_1A_LENGTH,
             fp2=TEST_1B_FP_RAW,
             len2=TEST_1B_LENGTH))
    id = insert_submission(
        conn, {
            'fingerprint': TEST_1C_FP_RAW,
            'length': TEST_1C_LENGTH,
            'source_id': 1,
            'mbid': '1f143d2b-db04-47cc-82a0-eee6efaa1142',
            'puid': '7c1c6753-c834-44b1-884a-a5166c093139',
        })
    query = tables.submission.select(tables.submission.c.id == id)
    submission = conn.execute(query).fetchone()
    assert_false(submission['handled'])
    try:
        old_threshold = const.FINGERPRINT_MERGE_THRESHOLD
        const.FINGERPRINT_MERGE_THRESHOLD = 0.85
        fingerprint = import_submission(conn, submission)
    finally:
        const.FINGERPRINT_MERGE_THRESHOLD = old_threshold
    assert_equals(1, fingerprint['id'])
    assert_equals(1, fingerprint['track_id'])
    query = tables.fingerprint.select(tables.fingerprint.c.id == 1)
    fingerprint = conn.execute(query).fetchone()
    assert_equals(1, fingerprint['track_id'])
    query = tables.track.select(tables.track.c.id == 1)
    track = conn.execute(query).fetchone()
    assert_equals(None, track['new_id'])
    query = tables.track.select(tables.track.c.id == 2)
    track = conn.execute(query).fetchone()
    assert_equals(1, track['new_id'])
Пример #24
0
def test_merge_missing_mbids(conn):
    prepare_database(conn, """
TRUNCATE track_mbid;
INSERT INTO track_mbid (track_id, mbid) VALUES (1, '97edb73c-4dac-11e0-9096-0025225356f3');
INSERT INTO track_mbid (track_id, mbid) VALUES (1, 'b81f83ee-4da4-11e0-9ed8-0025225356f3');
INSERT INTO track_mbid (track_id, mbid) VALUES (1, 'd575d506-4da4-11e0-b951-0025225356f3');
INSERT INTO track_mbid (track_id, mbid) VALUES (2, 'd575d506-4da4-11e0-b951-0025225356f3');
INSERT INTO track_mbid (track_id, mbid) VALUES (3, '97edb73c-4dac-11e0-9096-0025225356f3');
INSERT INTO track_mbid (track_id, mbid) VALUES (4, '5d0290a6-4dad-11e0-a47a-0025225356f3');
INSERT INTO musicbrainz.gid_redirect (newid, gid, tbl) VALUES
    (1, 'd575d506-4da4-11e0-b951-0025225356f3', 3),
    (2, '5d0290a6-4dad-11e0-a47a-0025225356f3', 3),
    (99, 'b44dfb2a-4dad-11e0-bae4-0025225356f3', 2);
""")
    merge_missing_mbids(conn)
    rows = conn.execute("SELECT track_id, mbid FROM track_mbid ORDER BY track_id, mbid").fetchall()
    expected_rows = [
        (1, '97edb73c-4dac-11e0-9096-0025225356f3'),
        (1, 'b81f83ee-4da4-11e0-9ed8-0025225356f3'),
        (2, 'b81f83ee-4da4-11e0-9ed8-0025225356f3'),
        (3, '97edb73c-4dac-11e0-9096-0025225356f3'),
        (4, '6d885000-4dad-11e0-98ed-0025225356f3'),
    ]
    assert_equals(expected_rows, rows)
Пример #25
0
def test_lookup_handler(conn):
    values = {'format': 'json', 'client': 'app1key', 'duration': str(TEST_1_LENGTH), 'fingerprint': TEST_1_FP}
    builder = EnvironBuilder(method='POST', data=values)
    handler = LookupHandler(connect=provider(conn))
    # no matches
    handler = LookupHandler(connect=provider(conn))
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('application/json; charset=UTF-8', resp.content_type)
    expected = {
        "status": "ok",
        "results": []
    }
    assert_json_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
    # one exact match
    prepare_database(conn, """
INSERT INTO fingerprint (length, fingerprint, track_id, submission_count)
    VALUES (%s, %s, 1, 1);
""", (TEST_1_LENGTH, TEST_1_FP_RAW))
    handler = LookupHandler(connect=provider(conn))
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('application/json; charset=UTF-8', resp.content_type)
    expected = {
        "status": "ok",
        "results": [{
            "id": 'eb31d1c3-950e-468b-9e36-e46fa75b1291',
            "score": 1.0,
        }],
    }
    assert_json_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
    # one exact match with MBIDs
    values = {'format': 'json', 'client': 'app1key', 'duration': str(TEST_1_LENGTH), 'fingerprint': TEST_1_FP, 'meta': '1'}
    builder = EnvironBuilder(method='POST', data=values)
    handler = LookupHandler(connect=provider(conn))
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('application/json; charset=UTF-8', resp.content_type)
    expected = {
        "status": "ok",
        "results": [{
            "id": 'eb31d1c3-950e-468b-9e36-e46fa75b1291',
            "score": 1.0,
            "recordings": [{"id": "b81f83ee-4da4-11e0-9ed8-0025225356f3"}],
        }],
    }
    assert_json_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
    # one exact match with MBIDs and metadata
    prepare_database(conn, "INSERT INTO track_mbid (track_id, mbid, submission_count) VALUES (1, '373e6728-35e3-4633-aab1-bf7092ec43d8', 1)")
    values = {'format': 'json', 'client': 'app1key', 'duration': str(TEST_1_LENGTH), 'fingerprint': TEST_1_FP, 'meta': '2'}
    builder = EnvironBuilder(method='POST', data=values)
    handler = LookupHandler(connect=provider(conn))
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('application/json; charset=UTF-8', resp.content_type)
    expected = {
        "status": "ok",
        "results": [{
            "id": 'eb31d1c3-950e-468b-9e36-e46fa75b1291',
            "score": 1.0,
            "recordings": [{
                "id": "373e6728-35e3-4633-aab1-bf7092ec43d8",
            }, {
                "id": "b81f83ee-4da4-11e0-9ed8-0025225356f3",
                "duration": 123,
                "tracks": [{
                    "title": "Track A",
                    "duration": 123,
                    "position": 1,
                    "medium": {
                        "track_count": 2,
                        "position": 1,
                        "format": "DVD",
                        "release": {
                            "id": "1d4d546f-e2ec-4553-8df7-9004298924d5",
                            "title": "Album A",
                        },
                    },
                    "artists": [{
                            "id": "a64796c0-4da4-11e0-bf81-0025225356f3",
                            "name": "Artist A",
                    }],
                }, {
                    "title": "Track A",
                    "duration": 123,
                    "position": 1,
                    "medium": {
                        "track_count": 2,
                        "position": 1,
                        "format": "CD",
                        "release": {
                            "id": "dd6c2cca-a0e9-4cc4-9a5f-7170bd098e23",
                            "title": "Album A",
                        },
                    },
                    "artists": [{
                            "id": "a64796c0-4da4-11e0-bf81-0025225356f3",
                            "name": "Artist A",
                    }],
                }],
            }],
        }]
    }
    assert_json_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
    # duplicate fingerprint
    prepare_database(conn, """
INSERT INTO fingerprint (length, fingerprint, track_id, submission_count)
    VALUES (%s, %s, 1, 1);
""", (TEST_1_LENGTH, TEST_1_FP_RAW))
    values = {'format': 'json', 'client': 'app1key', 'duration': str(TEST_1_LENGTH), 'fingerprint': TEST_1_FP}
    builder = EnvironBuilder(method='POST', data=values)
    handler = LookupHandler(connect=provider(conn))
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('application/json; charset=UTF-8', resp.content_type)
    expected = {
        "status": "ok",
        "results": [{
            "id": 'eb31d1c3-950e-468b-9e36-e46fa75b1291',
            "score": 1.0,
        }],
    }
    assert_json_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
Пример #26
0
def test_lookup_handler(ctx):
    # type: (ScriptContext) -> None
    values = {
        'format': 'json',
        'client': 'app1key',
        'duration': str(TEST_1_LENGTH),
        'fingerprint': TEST_1_FP
    }
    builder = EnvironBuilder(method='POST', data=values)
    handler = LookupHandler(ctx)
    # no matches
    handler = LookupHandler(ctx)
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('application/json; charset=UTF-8', resp.content_type)
    expected = {"status": "ok", "results": []}  # type: Dict[str, Any]
    assert_json_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
    # one exact match
    prepare_database(
        ctx, """
INSERT INTO fingerprint (length, fingerprint, track_id, submission_count)
    VALUES (%s, %s, 1, 1);
""", (TEST_1_LENGTH, TEST_1_FP_RAW))
    handler = LookupHandler(ctx)
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('application/json; charset=UTF-8', resp.content_type)
    expected = {
        "status":
        "ok",
        "results": [{
            "id": 'eb31d1c3-950e-468b-9e36-e46fa75b1291',
            "score": 1.0,
        }],
    }
    assert_json_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
    # one exact match with MBIDs
    values = {
        'format': 'json',
        'client': 'app1key',
        'duration': str(TEST_1_LENGTH),
        'fingerprint': TEST_1_FP,
        'meta': '1'
    }
    builder = EnvironBuilder(method='POST', data=values)
    handler = LookupHandler(ctx)
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('application/json; charset=UTF-8', resp.content_type)
    expected = {
        "status":
        "ok",
        "results": [{
            "id":
            'eb31d1c3-950e-468b-9e36-e46fa75b1291',
            "score":
            1.0,
            "recordings": [{
                "id": "b81f83ee-4da4-11e0-9ed8-0025225356f3"
            }],
        }],
    }
    assert_json_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
    # one exact match with MBIDs and metadata
    prepare_database(
        ctx,
        "INSERT INTO track_mbid (track_id, mbid, submission_count) VALUES (1, '373e6728-35e3-4633-aab1-bf7092ec43d8', 1)"
    )
    values = {
        'format': 'json',
        'client': 'app1key',
        'duration': str(TEST_1_LENGTH),
        'fingerprint': TEST_1_FP,
        'meta': '2'
    }
    builder = EnvironBuilder(method='POST', data=values)
    handler = LookupHandler(ctx)
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('application/json; charset=UTF-8', resp.content_type)
    expected = {
        "status":
        "ok",
        "results": [{
            "id":
            'eb31d1c3-950e-468b-9e36-e46fa75b1291',
            "score":
            1.0,
            "recordings": [{
                "id": "373e6728-35e3-4633-aab1-bf7092ec43d8",
            }, {
                "id":
                "b81f83ee-4da4-11e0-9ed8-0025225356f3",
                "duration":
                123,
                "tracks": [{
                    "title":
                    "Track A",
                    "duration":
                    123,
                    "position":
                    1,
                    "medium": {
                        "track_count": 2,
                        "position": 1,
                        "format": "DVD",
                        "release": {
                            "id": "1d4d546f-e2ec-4553-8df7-9004298924d5",
                            "title": "Album A",
                        },
                    },
                    "artists": [{
                        "id": "a64796c0-4da4-11e0-bf81-0025225356f3",
                        "name": "Artist A",
                    }],
                }, {
                    "title":
                    "Track A",
                    "duration":
                    123,
                    "position":
                    1,
                    "medium": {
                        "track_count": 2,
                        "position": 1,
                        "format": "CD",
                        "release": {
                            "id": "dd6c2cca-a0e9-4cc4-9a5f-7170bd098e23",
                            "title": "Album A",
                        },
                    },
                    "artists": [{
                        "id": "a64796c0-4da4-11e0-bf81-0025225356f3",
                        "name": "Artist A",
                    }],
                }],
            }],
        }]
    }
    assert_json_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
    # duplicate fingerprint
    prepare_database(
        ctx, """
INSERT INTO fingerprint (length, fingerprint, track_id, submission_count)
    VALUES (%s, %s, 1, 1);
""", (TEST_1_LENGTH, TEST_1_FP_RAW))
    values = {
        'format': 'json',
        'client': 'app1key',
        'duration': str(TEST_1_LENGTH),
        'fingerprint': TEST_1_FP
    }
    builder = EnvironBuilder(method='POST', data=values)
    handler = LookupHandler(ctx)
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('application/json; charset=UTF-8', resp.content_type)
    expected = {
        "status":
        "ok",
        "results": [{
            "id": 'eb31d1c3-950e-468b-9e36-e46fa75b1291',
            "score": 1.0,
        }],
    }
    assert_json_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
Пример #27
0
def test_lookup_handler(conn):
    values = {'format': 'json', 'client': 'app1key', 'duration': str(TEST_1_LENGTH), 'fingerprint': TEST_1_FP}
    builder = EnvironBuilder(method='POST', data=values)
    handler = LookupHandler(connect=provider(conn))
    # no matches
    handler = LookupHandler(connect=provider(conn))
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('application/json; charset=UTF-8', resp.content_type)
    expected = {
        "status": "ok",
        "results": []
    }
    assert_json_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
    # one exact match
    prepare_database(conn, """
INSERT INTO fingerprint (length, fingerprint, source_id, track_id)
    VALUES (%s, %s, 1, 1);
""", (TEST_1_LENGTH, TEST_1_FP_RAW))
    handler = LookupHandler(connect=provider(conn))
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('application/json; charset=UTF-8', resp.content_type)
    expected = {
        "status": "ok",
        "results": [{
            "id": 1,
            "score": 1.0,
        }],
    }
    assert_json_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
    # one exact match with MBIDs
    values = {'format': 'json', 'client': 'app1key', 'duration': str(TEST_1_LENGTH), 'fingerprint': TEST_1_FP, 'meta': '1'}
    builder = EnvironBuilder(method='POST', data=values)
    handler = LookupHandler(connect=provider(conn))
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('application/json; charset=UTF-8', resp.content_type)
    expected = {
        "status": "ok",
        "results": [{
            "id": 1,
            "score": 1.0,
            "recordings": [{"id": "b81f83ee-4da4-11e0-9ed8-0025225356f3"}],
        }],
    }
    assert_json_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
    # one exact match with MBIDs and metadata
    prepare_database(conn, "INSERT INTO track_mbid (track_id, mbid) VALUES (1, '373e6728-35e3-4633-aab1-bf7092ec43d8')")
    values = {'format': 'json', 'client': 'app1key', 'duration': str(TEST_1_LENGTH), 'fingerprint': TEST_1_FP, 'meta': '2'}
    builder = EnvironBuilder(method='POST', data=values)
    handler = LookupHandler(connect=provider(conn))
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('application/json; charset=UTF-8', resp.content_type)
    expected = {
        "status": "ok",
        "results": [{
            "id": 1,
            "score": 1.0,
            "recordings": [{
                "id": "373e6728-35e3-4633-aab1-bf7092ec43d8",
            }, {
                "id": "b81f83ee-4da4-11e0-9ed8-0025225356f3",
                "tracks": [{
                    "title": "Track A",
                    "duration": 123,
                    "position": 1,
                    "medium": {
                        "track_count": 2,
                        "release": {
                            "id": "dd6c2cca-a0e9-4cc4-9a5f-7170bd098e23",
                            "title": "Album A",
                        },
                    },
                    "artist": {
                        "id": "a64796c0-4da4-11e0-bf81-0025225356f3",
                        "name": "Artist A",
                    },
                }],
            }],
        }]
    }
    assert_json_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)
    # duplicate fingerprint
    prepare_database(conn, """
INSERT INTO fingerprint (length, fingerprint, source_id, track_id)
    VALUES (%s, %s, 1, 1);
""", (TEST_1_LENGTH, TEST_1_FP_RAW))
    values = {'format': 'json', 'client': 'app1key', 'duration': str(TEST_1_LENGTH), 'fingerprint': TEST_1_FP}
    builder = EnvironBuilder(method='POST', data=values)
    handler = LookupHandler(connect=provider(conn))
    resp = handler.handle(Request(builder.get_environ()))
    assert_equals('application/json; charset=UTF-8', resp.content_type)
    expected = {
        "status": "ok",
        "results": [{
            "id": 1,
            "score": 1.0,
        }],
    }
    assert_json_equals(expected, resp.data)
    assert_equals('200 OK', resp.status)