updated CRUD tests, added type hinting.
This commit is contained in:
+2
-1
@@ -38,7 +38,8 @@ def db(in_memory_db):
|
||||
in_memory_db.execute(query, [
|
||||
{'id': 1, 'name': 'playlist one', 'description': 'the first one', 'slug': 'playlist-one'},
|
||||
{'id': 2, 'name': 'playlist two', 'description': 'the second one', 'slug': 'playlist-two'},
|
||||
{'id': 3, 'name': 'playlist three', 'description': 'the threerd one', 'slug': 'playlist-three'}
|
||||
{'id': 3, 'name': 'playlist three', 'description': 'the threerd one', 'slug': 'playlist-three'},
|
||||
{'id': 4, 'name': 'empty playlist', 'description': 'no tracks', 'slug': 'empty-playlist'}
|
||||
])
|
||||
|
||||
# populate the playlists
|
||||
|
||||
+42
-6
@@ -1,12 +1,48 @@
|
||||
# 70, 73-81, 84, 88-97, 100-104
|
||||
import pytest
|
||||
from groove import playlist
|
||||
|
||||
|
||||
def test_create_playlist():
|
||||
pass
|
||||
def test_create(db):
|
||||
pl = playlist.Playlist(slug='test-create-playlist', session=db, create_if_not_exists=True)
|
||||
assert pl.exists
|
||||
|
||||
|
||||
def test_update_playlist():
|
||||
pass
|
||||
@pytest.mark.parametrize('tracks', [
|
||||
('01 Guns Blazing', ),
|
||||
('01 Guns Blazing', '02 UNKLE'),
|
||||
])
|
||||
def test_add(db, tracks):
|
||||
pl = playlist.Playlist(slug='test-create-playlist', session=db, create_if_not_exists=True)
|
||||
count = pl.add(tracks)
|
||||
assert count == len(tracks)
|
||||
|
||||
|
||||
def delete_playlist():
|
||||
pass
|
||||
def test_add_no_matches(db):
|
||||
pl = playlist.Playlist(slug='playlist-one', session=db)
|
||||
assert pl.add(('no match', )) == 0
|
||||
|
||||
|
||||
def test_add_multiple_matches(db):
|
||||
pl = playlist.Playlist(slug='playlist-one', session=db)
|
||||
assert pl.add('UNKLE',) == 0
|
||||
|
||||
|
||||
def test_delete(db):
|
||||
pl = playlist.Playlist(slug='playlist-one', session=db)
|
||||
expected = pl.record.id
|
||||
assert pl.delete() == expected
|
||||
assert not pl.as_dict
|
||||
|
||||
|
||||
def test_delete_playlist_not_exist(db):
|
||||
pl = playlist.Playlist(slug='playlist-doesnt-exist', session=db)
|
||||
assert not pl.delete()
|
||||
assert not pl.as_dict
|
||||
|
||||
|
||||
def test_entries(db):
|
||||
pl = playlist.Playlist(slug='playlist-one', session=db)
|
||||
# assert twice for branch coverage of cached values
|
||||
assert pl.entries
|
||||
assert pl.entries
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import pytest
|
||||
import os
|
||||
from pathlib import Path
|
||||
from unittest.mock import MagicMock
|
||||
from sqlalchemy import func
|
||||
@@ -47,3 +48,9 @@ def test_scanner(monkeypatch, in_memory_db, media):
|
||||
|
||||
# verify idempotency
|
||||
assert test_scanner.scan() == 0
|
||||
|
||||
|
||||
def test_scanner_no_media_root(in_memory_db):
|
||||
del os.environ['MEDIA_ROOT']
|
||||
with pytest.raises(SystemExit):
|
||||
assert scanner.media_scanner(root=None, db=in_memory_db)
|
||||
|
||||
Reference in New Issue
Block a user