Skip to content

Commit

Permalink
track_dict.length also accepts float type
Browse files Browse the repository at this point in the history
  • Loading branch information
jonbesga committed Aug 1, 2018
1 parent 890d2c0 commit 418d512
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mosbot/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ async def save_track(*, track_dict: dict, conn=None) -> Optional[dict]:
:return: None if it failed, the updated track if not
"""
assert track_dict
assert isinstance(track_dict.get('length'), int)
assert isinstance(track_dict.get('length'), (int, float))
assert isinstance(track_dict.get('origin'), (str, Origin))
assert isinstance(track_dict.get('extid'), str)
assert isinstance(track_dict.get('name'), str)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,13 @@ async def test_get_track(db_conn, track_generator, track_dict, raises_exception)
@pytest.mark.parametrize("track_dict, raises_exception", [
({'extid': 'ab12', 'origin': 'youtube', 'length': 120, 'name': 'One name'}, None),
({'extid': 'ab12', 'origin': Origin.youtube, 'length': 120, 'name': 'One name'}, None),
({'extid': 'ab12', 'origin': Origin.youtube, 'length': 120.0, 'name': 'One name'}, None),
({'extid': 12345, 'origin': 'youtube', 'length': 120, 'name': 'One name'}, AssertionError),
({'extid': 'ab12', 'origin': 'youtube', 'length': '120', 'name': 'One name'}, AssertionError),
({'extid': 'ab12', 'origin': (1, 2), 'length': 120, 'name': 'One name'}, AssertionError),
({'extid': 'ab12', 'origin': 'youtube', 'length': 120, 'name': 12345}, AssertionError),
({}, AssertionError),
], ids=['good_with_string', 'good_with_enum', 'bad_with_int', 'bad_with_string', 'bad_with_tuple', 'bad_with_int_name',
], ids=['good_with_string', 'good_with_enum', 'good_with_float', 'bad_with_int', 'bad_with_string', 'bad_with_tuple', 'bad_with_int_name',
'bad_no_data'])
@pytest.mark.asyncio
async def test_save_track(db_conn, track_dict, raises_exception):
Expand Down

0 comments on commit 418d512

Please sign in to comment.