grooveondemand/test/test_path.py

42 lines
1.1 KiB
Python
Raw Normal View History

2022-12-05 01:06:57 -08:00
import pytest
import os
from groove import path
2022-12-07 23:41:49 -08:00
from groove.exceptions import ConfigurationError, ThemeMissingException
from groove.webserver import themes
2022-12-05 01:06:57 -08:00
2022-12-07 23:41:49 -08:00
@pytest.mark.parametrize('root', ['/dev/null/missing', None])
def test_missing_media_root(monkeypatch, root):
2022-12-05 01:06:57 -08:00
broken_env = {k: v for (k, v) in os.environ.items()}
2022-12-07 23:41:49 -08:00
broken_env['MEDIA_ROOT'] = root
monkeypatch.setattr(os, 'environ', broken_env)
with pytest.raises(ConfigurationError):
path.media_root()
2022-12-21 15:17:13 -08:00
2022-12-07 23:41:49 -08:00
def test_static(monkeypatch):
assert path.static('foo')
assert path.static('foo', theme=themes.load_theme('default_theme'))
2022-12-21 15:17:13 -08:00
2022-12-21 22:27:30 -08:00
def test_missing_theme_root(monkeypatch):
2022-12-07 23:41:49 -08:00
broken_env = {k: v for (k, v) in os.environ.items()}
2022-12-21 22:27:30 -08:00
broken_env['THEMES_PATH'] = '/dev/null/enoexist'
2022-12-05 01:06:57 -08:00
monkeypatch.setattr(os, 'environ', broken_env)
with pytest.raises(ConfigurationError):
path.themes_root()
2022-12-07 23:41:49 -08:00
def test_theme_no_path():
with pytest.raises(ThemeMissingException):
path.theme('nope')
2022-12-21 15:17:13 -08:00
def test_database_default(env):
2022-12-21 21:16:06 -08:00
assert path.database()
2022-12-21 15:17:13 -08:00
2022-12-07 23:41:49 -08:00
def test_database(env):
2022-12-21 15:17:13 -08:00
assert env['DATABASE_PATH'] in str(path.database().absolute())