mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-30 03:46:29 -05:00
Saving zims.yaml keeps the entries of Zims the database does not have yet (#935)
A rebuilt database imports zims.yaml before the refresh has modeled a single Zim. That import has no database version to compare with, so it saves the config afterward, and the save wrote only the Zims in the database: none. The file's choices were erased and every Zim was then modeled with the default. The dump now starts from the file's entries and overlays the database's, so a choice survives until its Zim is modeled again, and a Zim in the database still decides its own line. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
c0452e29e6
commit
5be899bf1f
2 changed files with 34 additions and 2 deletions
|
|
@ -97,3 +97,32 @@ async def test_older_file_saves_the_database(test_session, test_directory, async
|
|||
data = config.read_config_file()
|
||||
assert data['auto_search'] == {'wikipedia_en_all_maxi': False}
|
||||
assert data['version'] > saved_version
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_dump_keeps_zims_the_database_does_not_have(test_session, test_directory, async_client,
|
||||
test_wrolpi_config, zim_path_factory):
|
||||
"""A rebuilt database imports zims.yaml before any Zim is modeled, then saves the config (an import without a
|
||||
known version does). That save must keep the file's choices for Zims not yet in the database, or the refresh
|
||||
that follows models every Zim with the default."""
|
||||
config = lib.get_zims_config()
|
||||
config.write_config_data(dict(version=3, auto_search={'wikiversity_en_all_maxi': False, 'ham': True}),
|
||||
config.get_file())
|
||||
assert test_session.query(Zim).count() == 0, 'The database is empty, as after a rebuild'
|
||||
|
||||
config.import_config()
|
||||
config.dump_config()
|
||||
assert config.read_config_file()['auto_search'] == {'ham': True, 'wikiversity_en_all_maxi': False}, \
|
||||
'The dump kept the file entries for Zims the database does not have'
|
||||
|
||||
# The refresh models the Zims afterward; the choice is applied.
|
||||
file_group = FileGroup.from_paths(test_session, zim_path_factory('wikiversity_en_all_maxi_2026-05.zim'))
|
||||
zim = lib.model_zim(file_group, test_session)
|
||||
test_session.commit()
|
||||
assert zim.auto_search is False
|
||||
|
||||
# A Zim in the database overrides the file's stale value for its name.
|
||||
zim.auto_search = True
|
||||
test_session.commit()
|
||||
config.dump_config()
|
||||
assert config.read_config_file()['auto_search'] == {'ham': True, 'wikiversity_en_all_maxi': True}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue