78 lines
2.5 KiB
Python
78 lines
2.5 KiB
Python
import pytest
|
|
|
|
from groove.db.manager import database_manager
|
|
from groove.shell import interactive_shell
|
|
from unittest.mock import MagicMock
|
|
|
|
|
|
@pytest.fixture
|
|
def cmd_prompt(monkeypatch, in_memory_engine, db):
|
|
with database_manager() as manager:
|
|
manager._session = db
|
|
yield interactive_shell.CommandPrompt(manager)
|
|
|
|
|
|
def response_factory(responses):
|
|
return MagicMock(side_effect=responses + ([''] * 10))
|
|
|
|
|
|
@pytest.mark.parametrize('inputs, expected', [
|
|
(['stats'], 'Database contains 4 playlists'), # match the db fixture
|
|
])
|
|
def test_stats(monkeypatch, capsys, cmd_prompt, inputs, expected):
|
|
monkeypatch.setattr('groove.console.Console.prompt', response_factory(inputs))
|
|
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):
|
|
monkeypatch.setattr('groove.console.Console.prompt', response_factory(inputs))
|
|
with pytest.raises(expected):
|
|
cmd_prompt.start()
|
|
|
|
|
|
def test_browse(monkeypatch, capsys, cmd_prompt):
|
|
monkeypatch.setattr('groove.console.Console.prompt', response_factory(['browse']))
|
|
cmd_prompt.start()
|
|
output = capsys.readouterr()
|
|
assert 'Displaying 4 playlists' in output.out
|
|
assert 'playlist one' in output.out
|
|
assert 'the first one' in output.out
|
|
assert 'playlist-one' in output.out
|
|
assert 'the second one' in output.out
|
|
assert 'the threerd one' in output.out
|
|
assert 'empty playlist' in output.out
|
|
|
|
|
|
@pytest.mark.parametrize('inputs, expected', [
|
|
(['help'], ['Available Commands', ' help ', ' stats ', ' browse ']),
|
|
(['help browse'], ['Help for browse']),
|
|
])
|
|
def test_help(monkeypatch, capsys, cmd_prompt, inputs, expected):
|
|
monkeypatch.setattr('groove.console.Console.prompt', response_factory(inputs))
|
|
cmd_prompt.start()
|
|
output = capsys.readouterr()
|
|
for txt in expected:
|
|
assert txt in output.out
|
|
assert cmd_prompt.__doc__ == cmd_prompt.help_text
|
|
|
|
|
|
@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.console.Console.prompt', response_factory(inputs))
|
|
cmd_prompt.start()
|
|
assert expected in caplog.text
|
|
|
|
|
|
def test_values(cmd_prompt):
|
|
for cmd in [cmd for cmd in cmd_prompt.commands.keys() if not cmd.startswith('_')]:
|
|
assert cmd in cmd_prompt.values
|