fixing test env

This commit is contained in:
evilchili 2022-12-21 22:27:30 -08:00
parent 41a21671ca
commit 6b53b11f0e
6 changed files with 42 additions and 61 deletions

View File

@ -19,6 +19,36 @@ from groove.webserver import webserver
from groove.exceptions import ConfigurationError
from groove.console import Console
SETUP_HELP = """
Please make sure you set MEDIA_ROOT and SECRET_KEY in your environment.
By default, Groove on Demand will attempt to load these variables from
~/.groove, which may contain the following variables as well. See also
the --env paramter.
# Set this one. The path containing your media files
MEDIA_ROOT=
# the kinds of files to import
# MEDIA_GLOB=*.mp3,*.flac,*.m4a
# where to store the groove_on_demand.db sqlite database.
# DATABASE_PATH=~
# Try 'groove themes' to see a list of available themes.
# DEFAULT_THEME=blue_train
# Web interface configuration
# HOST=127.0.0.1
# PORT=2323
# Set this to a suitably random string.
SECRET_KEY=much secret very private
# Console configuration
# EDITOR=
# CONSOLE_WIDTH=auto
"""
app = typer.Typer()
@ -47,7 +77,7 @@ def main(
groove.path.themes_root()
groove.path.database()
except ConfigurationError as e:
sys.stderr.write(f'{e}\n')
sys.stderr.write(f'{e}\n\n{SETUP_HELP}')
sys.exit(1)
@ -60,33 +90,7 @@ def setup(context: typer.Context):
"""
Interactive setup is not yet available. Sorry!
In the mean time, please make sure you set MEDIA_ROOT and SECRET_KEY
in your environment. By default, Groove on Demand will attempt to load
these variables from ~/.groove, which may contain the following
variables as well. See also the --env paramter.
# Set this one. The path containing your media files
MEDIA_ROOT=
# the kinds of files to import
# MEDIA_GLOB=*.mp3,*.flac,*.m4a
# where to store the groove_on_demand.db sqlite database.
# DATABASE_PATH=~
# Try 'groove themes' to see a list of available themes.
# DEFAULT_THEME=blue_train
# Web interface configuration
# HOST=127.0.0.1
# PORT=2323
# Set this to a suitably random string.
SECRET_KEY=much secret very private
# Console configuration
# EDITOR=
# CONSOLE_WIDTH=auto
{SETUP_HELP}
"""
))

View File

@ -9,15 +9,7 @@ _reinstall_hint = "You might need to reinstall Groove On Demand to fix this erro
def root():
path = os.environ.get('GROOVE_ON_DEMAND_ROOT', None)
if not path:
raise ConfigurationError(f"GROOVE_ON_DEMAND_ROOT is not defined in your environment.\n{_setup_hint}")
path = Path(path).expanduser()
if not path.exists() or not path.is_dir():
raise ConfigurationError(
"The Groove on Demand root directory (GROOVE_ON_DEMAND_ROOT) "
f"does not exist or isn't a directory.\n\n{_reinstall_hint}"
)
path = Path(__file__).parent.parent
logging.debug(f"Root is {path}")
return Path(path)
@ -43,12 +35,12 @@ def media(relpath):
def static_root():
dirname = os.environ.get('STATIC_PATH', 'static')
path = root() / Path(dirname)
logging.debug(f"Static root is {path}")
if not path.exists() or not path.is_dir():
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}"
)
logging.debug(f"Static root is {path}")
return path

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "grooveondemand"
version = "0.1.0"
version = "0.9"
description = "audio playlist server"
authors = ["evilchili <evilchili@gmail.com>"]
license = "MIT License"
@ -9,7 +9,7 @@ packages = [
]
[tool.poetry.dependencies]
python = "^3.10"
python = "^3.7"
bottle = "^0.12.23"
typer = "^0.7.0"
python-dotenv = "^0.21.0"

View File

@ -14,12 +14,11 @@ from unittest.mock import MagicMock
@pytest.fixture(autouse=True, scope='function')
def env():
def env(monkeypatch):
root = Path(__file__).parent / Path('fixtures')
monkeypatch.setattr('groove.path.root', MagicMock(return_value=str(root)))
load_dotenv(Path('test/fixtures/env'))
os.environ['GROOVE_ON_DEMAND_ROOT'] = str(root)
os.environ['MEDIA_ROOT'] = str(root / Path('media'))
os.environ['DATABASE_PATH'] = ''
return os.environ

17
test/fixtures/env vendored
View File

@ -1,25 +1,12 @@
# Will be overwritten by test setup
GROOVE_ON_DEMAND_ROOT=.
MEDIA_ROOT=.
# Admin user credentials
USERNAME=test_username
PASSWORD=test_password
# Web interface configuration
HOST=127.0.0.1
PORT=2323
THEMES_PATH=themes
STATIC_PATH=static
DEFAULT_THEME=default_theme
SECRET_KEY=fnord
# Media scanner configuration
MEDIA_GLOB=*.mp3,*.flac,*.m4a
# Set this value to enable debugging
DEBUG=1
EDITOR=ed
CONSOLE_THEMES=True
CONSOLE_WIDTH=80
DATABASE_PATH=
MEDIA_ROOT=

View File

@ -20,10 +20,9 @@ def test_static(monkeypatch):
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):
def test_missing_theme_root(monkeypatch):
broken_env = {k: v for (k, v) in os.environ.items()}
broken_env['GROOVE_ON_DEMAND_ROOT'] = root
broken_env['THEMES_PATH'] = '/dev/null/enoexist'
monkeypatch.setattr(os, 'environ', broken_env)
with pytest.raises(ConfigurationError):
path.themes_root()