fixing test env
This commit is contained in:
parent
41a21671ca
commit
6b53b11f0e
|
@ -19,6 +19,36 @@ from groove.webserver import webserver
|
||||||
from groove.exceptions import ConfigurationError
|
from groove.exceptions import ConfigurationError
|
||||||
from groove.console import Console
|
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()
|
app = typer.Typer()
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,7 +77,7 @@ def main(
|
||||||
groove.path.themes_root()
|
groove.path.themes_root()
|
||||||
groove.path.database()
|
groove.path.database()
|
||||||
except ConfigurationError as e:
|
except ConfigurationError as e:
|
||||||
sys.stderr.write(f'{e}\n')
|
sys.stderr.write(f'{e}\n\n{SETUP_HELP}')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,33 +90,7 @@ def setup(context: typer.Context):
|
||||||
"""
|
"""
|
||||||
Interactive setup is not yet available. Sorry!
|
Interactive setup is not yet available. Sorry!
|
||||||
|
|
||||||
In the mean time, please make sure you set MEDIA_ROOT and SECRET_KEY
|
{SETUP_HELP}
|
||||||
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
|
|
||||||
"""
|
"""
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
|
@ -9,15 +9,7 @@ _reinstall_hint = "You might need to reinstall Groove On Demand to fix this erro
|
||||||
|
|
||||||
|
|
||||||
def root():
|
def root():
|
||||||
path = os.environ.get('GROOVE_ON_DEMAND_ROOT', None)
|
path = Path(__file__).parent.parent
|
||||||
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}"
|
|
||||||
)
|
|
||||||
logging.debug(f"Root is {path}")
|
logging.debug(f"Root is {path}")
|
||||||
return Path(path)
|
return Path(path)
|
||||||
|
|
||||||
|
@ -43,12 +35,12 @@ def media(relpath):
|
||||||
def static_root():
|
def static_root():
|
||||||
dirname = os.environ.get('STATIC_PATH', 'static')
|
dirname = os.environ.get('STATIC_PATH', 'static')
|
||||||
path = root() / Path(dirname)
|
path = root() / Path(dirname)
|
||||||
|
logging.debug(f"Static root is {path}")
|
||||||
if not path.exists() or not path.is_dir():
|
if not path.exists() or not path.is_dir():
|
||||||
raise ConfigurationError( # pragma: no cover
|
raise ConfigurationError( # pragma: no cover
|
||||||
f"The static assets directory {dirname} (STATIC_PATH) "
|
f"The static assets directory {dirname} (STATIC_PATH) "
|
||||||
f"doesn't exist, or isn't a directory.\n\n{_reinstall_hint}"
|
f"doesn't exist, or isn't a directory.\n\n{_reinstall_hint}"
|
||||||
)
|
)
|
||||||
logging.debug(f"Static root is {path}")
|
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "grooveondemand"
|
name = "grooveondemand"
|
||||||
version = "0.1.0"
|
version = "0.9"
|
||||||
description = "audio playlist server"
|
description = "audio playlist server"
|
||||||
authors = ["evilchili <evilchili@gmail.com>"]
|
authors = ["evilchili <evilchili@gmail.com>"]
|
||||||
license = "MIT License"
|
license = "MIT License"
|
||||||
|
@ -9,7 +9,7 @@ packages = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "^3.10"
|
python = "^3.7"
|
||||||
bottle = "^0.12.23"
|
bottle = "^0.12.23"
|
||||||
typer = "^0.7.0"
|
typer = "^0.7.0"
|
||||||
python-dotenv = "^0.21.0"
|
python-dotenv = "^0.21.0"
|
||||||
|
|
|
@ -14,12 +14,11 @@ from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True, scope='function')
|
@pytest.fixture(autouse=True, scope='function')
|
||||||
def env():
|
def env(monkeypatch):
|
||||||
root = Path(__file__).parent / Path('fixtures')
|
root = Path(__file__).parent / Path('fixtures')
|
||||||
|
monkeypatch.setattr('groove.path.root', MagicMock(return_value=str(root)))
|
||||||
load_dotenv(Path('test/fixtures/env'))
|
load_dotenv(Path('test/fixtures/env'))
|
||||||
os.environ['GROOVE_ON_DEMAND_ROOT'] = str(root)
|
|
||||||
os.environ['MEDIA_ROOT'] = str(root / Path('media'))
|
os.environ['MEDIA_ROOT'] = str(root / Path('media'))
|
||||||
os.environ['DATABASE_PATH'] = ''
|
|
||||||
return os.environ
|
return os.environ
|
||||||
|
|
||||||
|
|
||||||
|
|
17
test/fixtures/env
vendored
17
test/fixtures/env
vendored
|
@ -1,25 +1,12 @@
|
||||||
# Will be overwritten by test setup
|
|
||||||
GROOVE_ON_DEMAND_ROOT=.
|
|
||||||
MEDIA_ROOT=.
|
|
||||||
|
|
||||||
# Admin user credentials
|
|
||||||
USERNAME=test_username
|
USERNAME=test_username
|
||||||
PASSWORD=test_password
|
PASSWORD=test_password
|
||||||
|
|
||||||
# Web interface configuration
|
|
||||||
HOST=127.0.0.1
|
HOST=127.0.0.1
|
||||||
PORT=2323
|
PORT=2323
|
||||||
THEMES_PATH=themes
|
|
||||||
STATIC_PATH=static
|
|
||||||
DEFAULT_THEME=default_theme
|
DEFAULT_THEME=default_theme
|
||||||
SECRET_KEY=fnord
|
SECRET_KEY=fnord
|
||||||
|
|
||||||
# Media scanner configuration
|
|
||||||
MEDIA_GLOB=*.mp3,*.flac,*.m4a
|
MEDIA_GLOB=*.mp3,*.flac,*.m4a
|
||||||
|
|
||||||
# Set this value to enable debugging
|
|
||||||
DEBUG=1
|
DEBUG=1
|
||||||
|
|
||||||
EDITOR=ed
|
EDITOR=ed
|
||||||
CONSOLE_THEMES=True
|
|
||||||
CONSOLE_WIDTH=80
|
CONSOLE_WIDTH=80
|
||||||
|
DATABASE_PATH=
|
||||||
|
MEDIA_ROOT=
|
||||||
|
|
|
@ -20,10 +20,9 @@ def test_static(monkeypatch):
|
||||||
assert path.static('foo', theme=themes.load_theme('default_theme'))
|
assert path.static('foo', theme=themes.load_theme('default_theme'))
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('root', ['/dev/null/missing', None])
|
def test_missing_theme_root(monkeypatch):
|
||||||
def test_missing_theme_root(monkeypatch, root):
|
|
||||||
broken_env = {k: v for (k, v) in os.environ.items()}
|
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)
|
monkeypatch.setattr(os, 'environ', broken_env)
|
||||||
with pytest.raises(ConfigurationError):
|
with pytest.raises(ConfigurationError):
|
||||||
path.themes_root()
|
path.themes_root()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user