cleanup, more tests

This commit is contained in:
evilchili
2022-12-02 00:21:19 -08:00
parent a0de0eef48
commit ed16ebdd0e
7 changed files with 103 additions and 57 deletions
+31 -6
View File
@@ -4,8 +4,8 @@ from groove import playlist
def test_create(db):
pl = playlist.Playlist(slug='test-create-playlist', session=db, create_if_not_exists=True)
assert pl.exists
pl = playlist.Playlist(slug='test-create-playlist', session=db, create_ok=True)
assert pl.record.id
@pytest.mark.parametrize('tracks', [
@@ -13,7 +13,7 @@ def test_create(db):
('01 Guns Blazing', '02 UNKLE'),
])
def test_add(db, tracks):
pl = playlist.Playlist(slug='test-create-playlist', session=db, create_if_not_exists=True)
pl = playlist.Playlist(slug='test-create-playlist', session=db)
count = pl.add(tracks)
assert count == len(tracks)
@@ -32,13 +32,23 @@ 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
assert not pl.exists
assert pl.deleted
def test_delete_playlist_not_exist(db):
pl = playlist.Playlist(slug='playlist-doesnt-exist', session=db)
pl = playlist.Playlist(slug='playlist-doesnt-exist', session=db, create_ok=False)
assert not pl.delete()
assert not pl.as_dict
assert not pl.exists
assert not pl.deleted
def test_cannot_create_after_delete(db):
pl = playlist.Playlist(slug='playlist-one', session=db)
pl.delete()
with pytest.raises(RuntimeError):
assert pl.record
assert not pl.exists
def test_entries(db):
@@ -46,3 +56,18 @@ def test_entries(db):
# assert twice for branch coverage of cached values
assert pl.entries
assert pl.entries
def test_playlist_not_exist_formatted(db):
pl = playlist.Playlist(slug='fnord', session=db, create_ok=False)
assert not repr(pl)
assert not pl.as_dict
def test_playlist_formatted(db):
pl = playlist.Playlist(slug='playlist-one', session=db)
assert repr(pl)
assert pl.as_string
assert pl.as_dict
+12 -1
View File
@@ -13,7 +13,7 @@ def cmd_prompt(in_memory_engine, db):
def response_factory(responses):
return MagicMock(side_effect=responses + [''])
return MagicMock(side_effect=responses + ([''] * 10))
@pytest.mark.parametrize('inputs, expected', [
@@ -58,3 +58,14 @@ def test_help(monkeypatch, capsys, cmd_prompt, inputs, expected):
output = capsys.readouterr()
for txt in expected:
assert txt in output.out
@pytest.mark.parametrize('inputs, expected', [
('load A New Playlist', 'a-new-playlist'),
('new playlist', 'new-playlist'),
('load', '')
])
def test_load(monkeypatch, caplog, cmd_prompt, inputs, expected):
monkeypatch.setattr('groove.shell.base.prompt', response_factory([inputs]))
cmd_prompt.start()
assert expected in caplog.text