tests and bug fixes

This commit is contained in:
evilchili 2022-12-07 23:41:49 -08:00
parent af33e91232
commit 228d44ce98
7 changed files with 48 additions and 23 deletions

View File

@ -44,7 +44,7 @@ def static_root():
dirname = os.environ.get('STATIC_PATH', 'static')
path = root() / Path(dirname)
if not path.exists() or not path.is_dir():
raise ConfigurationError(
raise ConfigurationError( # pragma: no cover
f"The static assets directory {dirname} (STATIC_PATH) "
f"doesn't exist, or isn't a directory.\n\n{_reinstall_hint}"
)
@ -56,7 +56,7 @@ def static(relpath, theme=None):
if theme:
root = theme.path / Path('static')
if not root.is_dir():
raise ThemeConfigurationError(
raise ThemeConfigurationError( # pragma: no cover
f"The themes directory {relpath} (THEMES_PATH) "
f"doesn't contain a 'static' directory."
)
@ -73,7 +73,7 @@ def themes_root():
dirname = os.environ.get('THEMES_PATH', 'themes')
path = root() / Path(dirname)
if not path.exists() or not path.is_dir():
raise ConfigurationError(
raise ConfigurationError( # pragma: no cover
f"The themes directory {dirname} (THEMES_PATH) "
f"doesn't exist, or isn't a directory.\n\n{_reinstall_hint}"
)
@ -84,7 +84,7 @@ def themes_root():
def theme(name):
path = themes_root() / Path(name)
if not path.exists() or not path.is_dir():
available = ','.join(available_themes)
available = ','.join(available_themes())
raise ThemeMissingException(
f"A theme directory named {name} does not exist or isn't a directory. "
"Perhaps there is a typo in the name?\n"

View File

@ -7,7 +7,7 @@ class BasePrompt(Completer):
def __init__(self, manager=None, parent=None):
super(BasePrompt, self).__init__()
if (not manager and not parent):
if (not manager and not parent): # pragma: no cover
raise RuntimeError("Must define either a database manager or a parent object.")
self._prompt = ''

View File

@ -33,7 +33,7 @@ class CommandPrompt(BasePrompt):
def values(self):
return [k for k in self.commands.keys() if not k.startswith('_')]
def default_completer(self, document, complete_event):
def default_completer(self, document, complete_event): # pragma: no cover
def _formatter(row):
self._playlist = Playlist.from_row(row, self.manager.session)
return self.playlist.record.name
@ -47,7 +47,7 @@ class CommandPrompt(BasePrompt):
name = cmd + ' ' + ' '.join(parts)
if cmd in self.commands:
self.commands[cmd].start(name)
else:
return True
self._playlist = Playlist(
slug=slugify(name),
name=name,
@ -55,11 +55,9 @@ class CommandPrompt(BasePrompt):
create_ok=True
)
res = self.commands['_playlist'].start()
if res is False:
return res
return True
return True and res
def start():
def start(): # pragma: no cover
with database_manager() as manager:
CommandPrompt(manager).start()

View File

@ -2,12 +2,35 @@ import pytest
import os
from groove import path
from groove.exceptions import ConfigurationError
from groove.exceptions import ConfigurationError, ThemeMissingException
from groove.webserver import themes
def test_missing_theme_root(monkeypatch):
@pytest.mark.parametrize('root', ['/dev/null/missing', None])
def test_missing_media_root(monkeypatch, root):
broken_env = {k: v for (k, v) in os.environ.items()}
broken_env['GROOVE_ON_DEMAND_ROOT'] = '/dev/null/missing'
broken_env['MEDIA_ROOT'] = root
monkeypatch.setattr(os, 'environ', broken_env)
with pytest.raises(ConfigurationError):
path.media_root()
def test_static(monkeypatch):
assert path.static('foo')
assert path.static('foo', theme=themes.load_theme('default_theme'))
@pytest.mark.parametrize('root', ['/dev/null/missing', None])
def test_missing_theme_root(monkeypatch, root):
broken_env = {k: v for (k, v) in os.environ.items()}
broken_env['GROOVE_ON_DEMAND_ROOT'] = root
monkeypatch.setattr(os, 'environ', broken_env)
with pytest.raises(ConfigurationError):
path.themes_root()
def test_theme_no_path():
with pytest.raises(ThemeMissingException):
path.theme('nope')
def test_database(env):
assert env['DATABASE_PATH'] in path.database().name

View File

@ -6,8 +6,6 @@ from unittest.mock import MagicMock
from groove import playlist, editor
from groove.exceptions import PlaylistValidationError, TrackNotFoundError
# 166-167, 200, 203-204, 227-228, 253->255, 255->exit, 270, 346-347
def test_create(empty_playlist):
assert empty_playlist.record.id

View File

@ -58,6 +58,7 @@ def test_help(monkeypatch, capsys, cmd_prompt, inputs, expected):
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', [
@ -69,3 +70,8 @@ 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
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