mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Fixing tests that rely on empty ignored directories.
This commit is contained in:
parent
ad8433f9f4
commit
95ecfcac04
5 changed files with 24 additions and 5 deletions
|
|
@ -287,6 +287,9 @@ def get_media_directory() -> Path:
|
|||
return MEDIA_DIRECTORY
|
||||
|
||||
|
||||
TESTING_SKIP_BACKUP = False
|
||||
|
||||
|
||||
class ConfigFile:
|
||||
"""
|
||||
This class keeps track of the contents of a config file. You can update the config (and it's file) by
|
||||
|
|
@ -360,9 +363,10 @@ class ConfigFile:
|
|||
with config_file.open('rt') as fh:
|
||||
config = yaml.load(fh, Loader=yaml.Loader)
|
||||
# Copy the existing config to the backup directory. One for each day.
|
||||
if not backup_file.parent.exists():
|
||||
backup_file.parent.mkdir(parents=True)
|
||||
shutil.copy(config_file, backup_file)
|
||||
if PYTEST and not TESTING_SKIP_BACKUP:
|
||||
if not backup_file.parent.exists():
|
||||
backup_file.parent.mkdir(parents=True)
|
||||
shutil.copy(config_file, backup_file)
|
||||
else:
|
||||
# Config file does not yet exist.
|
||||
config = dict()
|
||||
|
|
|
|||
|
|
@ -126,6 +126,13 @@ def test_config(test_directory) -> pathlib.Path:
|
|||
set_test_config(False)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def skip_config_backups():
|
||||
"""Do not backup configs during testing."""
|
||||
with mock.patch('wrolpi.common.TESTING_SKIP_BACKUP', True):
|
||||
yield
|
||||
|
||||
|
||||
ROUTES_ATTACHED = False
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ def attach_shared_contexts(app: Sanic):
|
|||
|
||||
# ConfigFile multiprocessing_dict's.
|
||||
# Shared Configs
|
||||
app.shared_ctx.wrolpi_config = manager.dict()
|
||||
app.shared_ctx.wrolpi_config = multiprocessing.Manager().dict()
|
||||
app.shared_ctx.tags_config = manager.dict()
|
||||
app.shared_ctx.inventories_config = manager.dict()
|
||||
app.shared_ctx.channels_config = manager.dict()
|
||||
|
|
|
|||
|
|
@ -631,8 +631,12 @@ async def test_get_file(test_session, test_async_client, test_directory, make_fi
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_ignore_directory(test_session, test_async_client, test_directory, make_files_structure, test_config):
|
||||
async def test_ignore_directory(test_session, test_async_client, test_directory, make_files_structure, test_config,
|
||||
skip_config_backups):
|
||||
"""A maintainer can ignore/un-ignore directories. The files in the directory should not be refreshed."""
|
||||
# Remove any default ignored directories.
|
||||
get_wrolpi_config().ignored_directories = []
|
||||
|
||||
foo, bar, baz = make_files_structure(['foo/foo.txt', 'foo/bar.txt', 'baz/baz.txt'])
|
||||
assert len(get_wrolpi_config().ignored_directories) == 0
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ async def test_valid_regex(test_session, test_async_client):
|
|||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_settings(test_session, test_async_client):
|
||||
get_wrolpi_config().ignored_directories = list()
|
||||
|
||||
with mock.patch('wrolpi.admin.CPUFREQ_INFO_BIN', '/usr/bin/cpufreq-info'), \
|
||||
mock.patch('wrolpi.admin.NMCLI_BIN', '/usr/bin/nmcli'):
|
||||
request, response = await test_async_client.get('/api/settings')
|
||||
|
|
@ -266,6 +268,8 @@ def test_hotspot_settings(test_session, test_client, test_config):
|
|||
|
||||
@skip_circleci
|
||||
def test_throttle_toggle(test_session, test_client, test_config):
|
||||
get_wrolpi_config().ignored_directories = list()
|
||||
|
||||
with mock.patch('wrolpi.admin.subprocess') as mock_subprocess, \
|
||||
mock.patch('wrolpi.admin.CPUFREQ_INFO_BIN', "this value isn't even used"):
|
||||
mock_subprocess.check_output.side_effect = [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue