mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-25 01:16:18 -05:00
Preventing empty destinations from being imported from wrolpi config.
This commit is contained in:
parent
77c94da3a3
commit
84a173677c
2 changed files with 14 additions and 3 deletions
|
|
@ -684,8 +684,15 @@ class WROLPiConfig(ConfigFile):
|
|||
|
||||
def import_config(self, file: pathlib.Path = None, send_events=False):
|
||||
try:
|
||||
super().import_config(file)
|
||||
# WROLPiConfig does not sync to database.
|
||||
super().import_config(file)
|
||||
|
||||
# Destinations cannot be empty.
|
||||
self.archive_destination = self.archive_destination or self.default_config['archive_destination']
|
||||
self.map_destination = self.map_destination or self.default_config['map_destination']
|
||||
self.videos_destination = self.videos_destination or self.default_config['videos_destination']
|
||||
self.zims_destination = self.zims_destination or self.default_config['zims_destination']
|
||||
|
||||
self.successful_import = True
|
||||
except Exception as e:
|
||||
self.successful_import = False
|
||||
|
|
|
|||
|
|
@ -925,6 +925,7 @@ async def test_config_lifecycle(async_client, test_wrolpi_config):
|
|||
assert config.wrol_mode is False
|
||||
assert config.is_valid() is False
|
||||
assert config.version == 0
|
||||
assert config.zims_destination
|
||||
|
||||
# Bad config cannot be imported.
|
||||
test_wrolpi_config.parent.mkdir(exist_ok=True)
|
||||
|
|
@ -935,6 +936,7 @@ async def test_config_lifecycle(async_client, test_wrolpi_config):
|
|||
assert config.successful_import is False
|
||||
assert config.version == 0
|
||||
assert 'invalid' in str(e)
|
||||
assert config.zims_destination
|
||||
|
||||
# Cannot dump config because import was not successful.
|
||||
with pytest.raises(RuntimeError) as e:
|
||||
|
|
@ -942,14 +944,16 @@ async def test_config_lifecycle(async_client, test_wrolpi_config):
|
|||
assert 'imported' in str(e)
|
||||
assert config.version == 0
|
||||
|
||||
# Incomplete config can still be imported.
|
||||
test_wrolpi_config.write_text('wrol_mode: true')
|
||||
# Incomplete config can still be imported. "destinations" cannot be empty
|
||||
test_wrolpi_config.write_text('wrol_mode: true\nzims_destination: null')
|
||||
assert config.is_valid() is True
|
||||
config.import_config()
|
||||
assert config.successful_import is True
|
||||
assert config.wrol_mode is True
|
||||
assert config.is_valid() is True
|
||||
assert config.version == 0
|
||||
# Default destination was used instead.
|
||||
assert config.zims_destination
|
||||
|
||||
# Items from the default config are written to the file.
|
||||
config.dump_config()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue