grooveondemand/test/test_shell.py

61 lines
1.9 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
def cmd_prompt(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 + [''])
@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.shell.base.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.shell.base.prompt', response_factory(inputs))
with pytest.raises(expected):
cmd_prompt.start()
def test_browse(monkeypatch, capsys, cmd_prompt):
monkeypatch.setattr('groove.shell.base.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.shell.base.prompt', response_factory([inputs]))
cmd_prompt.start()
output = capsys.readouterr()
for txt in expected:
assert txt in output.out