Add settings and live sidebar counts

This commit is contained in:
Abel Luck 2026-03-30 18:26:02 +02:00
parent 2a99edeec3
commit a809bde16c
16 changed files with 696 additions and 51 deletions

View file

@ -7,11 +7,14 @@ import pytest
from peewee import IntegrityError
from repub.model import (
AppSetting,
Job,
Source,
database,
initialize_database,
load_max_concurrent_jobs,
resolve_database_path,
save_setting,
)
@ -51,6 +54,7 @@ def test_initialize_database_bootstraps_schema_from_sql_files(tmp_path: Path) ->
)
}
assert table_names == {
"app_setting",
"job",
"job_execution",
"source",
@ -59,17 +63,10 @@ def test_initialize_database_bootstraps_schema_from_sql_files(tmp_path: Path) ->
}
defaults = {
row[1]: row[4]
for row in connection.execute("PRAGMA table_info('source_pangea')")
row[1]: row[4] for row in connection.execute("PRAGMA table_info('job')")
}
assert defaults["content_type"] is None
assert defaults["only_newest"] is None
assert defaults["max_articles"] is None
assert defaults["oldest_article"] is None
assert defaults["include_authors"] is None
assert defaults["exclude_media"] is None
assert defaults["include_content"] is None
assert defaults["content_format"] is None
assert defaults["convert_images"] == "1"
assert defaults["convert_video"] == "1"
finally:
connection.close()
@ -168,3 +165,20 @@ def test_job_table_allows_exactly_one_job_per_source(tmp_path: Path) -> None:
cron_day_of_week="*",
cron_month="*",
)
def test_load_max_concurrent_jobs_defaults_to_one(tmp_path: Path) -> None:
initialize_database(tmp_path / "settings-defaults.db")
assert load_max_concurrent_jobs() == 1
def test_save_setting_persists_json_value(tmp_path: Path) -> None:
initialize_database(tmp_path / "settings-roundtrip.db")
save_setting("max_concurrent_jobs", 4)
row = AppSetting.get(AppSetting.key == "max_concurrent_jobs")
assert row.value == "4"
assert load_max_concurrent_jobs() == 4