grooveondemand/test/test_shell.py

110 lines
3.1 KiB
Python
Raw Normal View History

2022-12-01 00:32:48 -08:00
import pytest
from groove.db.manager import database_manager
from groove.shell import interactive_shell
from unittest.mock import MagicMock
@pytest.fixture
2022-12-17 12:43:57 -08:00
def cmd_prompt(monkeypatch, in_memory_engine, db):
2022-12-01 00:32:48 -08:00
with database_manager() as manager:
manager._session = db
2022-12-17 18:02:12 -08:00
yield interactive_shell.InteractiveShell(manager)
2022-12-01 00:32:48 -08:00
def response_factory(responses):
2022-12-02 00:21:19 -08:00
return MagicMock(side_effect=responses + ([''] * 10))
2022-12-01 00:32:48 -08:00
@pytest.mark.parametrize('inputs, expected', [
(['stats'], 'Database contains 4 playlists'), # match the db fixture
])
def test_stats(monkeypatch, capsys, cmd_prompt, inputs, expected):
2022-12-17 12:43:57 -08:00
monkeypatch.setattr('groove.console.Console.prompt', response_factory(inputs))
2022-12-01 00:32:48 -08:00
cmd_prompt.start()
output = capsys.readouterr()
assert expected in output.out
@pytest.mark.parametrize('inputs, expected', [
(['quit'], SystemExit),
])
def test_quit(monkeypatch, capsys, cmd_prompt, inputs, expected):
2022-12-17 12:43:57 -08:00
monkeypatch.setattr('groove.console.Console.prompt', response_factory(inputs))
2022-12-01 00:32:48 -08:00
with pytest.raises(expected):
cmd_prompt.start()
2022-12-17 18:02:12 -08:00
def test_list(monkeypatch, capsys, cmd_prompt):
monkeypatch.setattr('groove.console.Console.prompt', response_factory(['list']))
2022-12-01 00:32:48 -08:00
cmd_prompt.start()
2022-12-17 18:02:12 -08:00
@pytest.mark.parametrize('inputs', ['help', 'help list'])
def test_help(monkeypatch, capsys, cmd_prompt, inputs):
monkeypatch.setattr('groove.console.Console.prompt', response_factory([inputs]))
2022-12-01 00:32:48 -08:00
cmd_prompt.start()
2022-12-02 00:21:19 -08:00
@pytest.mark.parametrize('inputs, expected', [
2022-12-17 12:43:57 -08:00
(['load A New Playlist'], 'a-new-playlist'),
(['new playlist'], 'new-playlist'),
(['load'], '')
2022-12-02 00:21:19 -08:00
])
def test_load(monkeypatch, caplog, cmd_prompt, inputs, expected):
2022-12-17 12:43:57 -08:00
monkeypatch.setattr('groove.console.Console.prompt', response_factory(inputs))
2022-12-02 00:21:19 -08:00
cmd_prompt.start()
assert expected in caplog.text
2022-12-07 23:41:49 -08:00
def test_values(cmd_prompt):
for cmd in [cmd for cmd in cmd_prompt.commands.keys() if not cmd.startswith('_')]:
2022-12-17 18:02:12 -08:00
assert cmd in cmd_prompt.autocomplete_values
def test_playlist_usage(monkeypatch, cmd_prompt):
monkeypatch.setattr('groove.console.Console.prompt', response_factory([
'load new playlist',
'help'
]))
cmd_prompt.start()
def test_playliest_edit(monkeypatch, cmd_prompt):
monkeypatch.setattr('groove.console.Console.prompt', response_factory([
'load new playlist',
'edit'
]))
cmd_prompt.start()
def test_playlist_show(monkeypatch, cmd_prompt):
monkeypatch.setattr('groove.console.Console.prompt', response_factory([
'load playlist one',
'show'
]))
cmd_prompt.start()
def test_playlist_add(monkeypatch, cmd_prompt):
monkeypatch.setattr('groove.console.Console.prompt', response_factory([
'load playlist one',
'add',
'',
'add',
'UNKLE/Psyence Fiction/01 Guns Blazing (Drums of Death, Part 1).flac',
'',
]))
cmd_prompt.start()
def test_playlist_delete(monkeypatch, cmd_prompt):
monkeypatch.setattr('groove.console.Console.prompt', response_factory([
'load playlist one',
'delete',
'',
'delete',
'DELETE',
]))
cmd_prompt.start()