Commit 7e0d31a7 authored by Lukáš Lalinský's avatar Lukáš Lalinský

More tests and bug fixes

parent ab78ba1d
......@@ -68,7 +68,7 @@ class SubmitHandlerParams(v2.SubmitHandlerParams):
def _parse_duration_and_format(self, p, values, suffix):
p['duration'] = values.get('length' + suffix, type=int)
if not p['duration']:
raise MissingParameterError('length' + suffix)
raise errors.MissingParameterError('length' + suffix)
p['format'] = values.get('format' + suffix)
......
......@@ -42,7 +42,9 @@ def import_submission(conn, submission):
if submission['mbid']:
mbids.append(submission['mbid'])
if submission['puid']:
mbids.extend(find_puid_mbids(submission['puid']))
min_duration = submission['length'] - 15
max_duration = submission['length'] + 15
mbids.extend(find_puid_mbids(conn, submission['puid'], min_duration, max_duration))
logger.info("Importing submission %d with MBIDs %s",
submission['id'], ', '.join(mbids))
matches = lookup_fingerprint(conn,
......
......@@ -144,6 +144,16 @@ def test_submit_handler_params(conn):
values = MultiDict({'client': 'app1key', 'user': 'user1key'})
params = SubmitHandlerParams()
assert_raises(errors.MissingParameterError, params.parse, values, conn)
# missing duration
values = MultiDict({'client': 'app1key', 'user': 'user1key',
'mbid': ['4d814cb1-20ec-494f-996f-f31ca8a49784', '66c0f5cc-67b6-4f51-80cd-ab26b5aaa6ea'],
'puid': '4e823498-c77d-4bfb-b6cc-85b05c2783cf',
'fingerprint': TEST_1_FP,
'bitrate': '192',
'format': 'MP3'
})
params = SubmitHandlerParams()
assert_raises(errors.MissingParameterError, params.parse, values, conn)
# all ok (single submission)
values = MultiDict({'client': 'app1key', 'user': 'user1key',
'mbid': ['4d814cb1-20ec-494f-996f-f31ca8a49784', '66c0f5cc-67b6-4f51-80cd-ab26b5aaa6ea'],
......
......@@ -24,7 +24,7 @@ def test_find_or_insert_source(conn):
expected_rows = [
(1, 1, 1),
(2, 2, 2),
(3, 1, 2),
(3, 2, 1),
]
assert_equals(expected_rows, rows)
......@@ -42,6 +42,8 @@ def test_import_submission(conn):
'bitrate': 192,
'source_id': 1,
'format_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()
......@@ -76,6 +78,8 @@ def test_import_submission(conn):
'bitrate': 192,
'source_id': 1,
'format_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()
......
......@@ -9,6 +9,7 @@ def test_singular():
assert_equals('artist', singular('artists'))
assert_equals('release', singular('releases'))
assert_equals('city', singular('cities'))
assert_raises(ValueError, singular, 'city')
def test_is_uuid():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment