mirror of
https://github.com/calibrain/shelfmark.git
synced 2026-11-16 22:08:13 +00:00
This replaces #1047, which @InfiniteAvenger opened and calibrain offered to re-review. It is Caleb's feature commit with his authorship kept, rebased onto current main, with small fixes, tests and a docs page on top. Everything is opt-in and off by default, so nothing changes for anyone who doesn't turn it on. What it adds is a **Settings, Hardcover Sync** tab with three parts that can be switched on separately: - **Shelf sync**: a Hardcover shelf (Want to Read by default) is pulled into requests on a schedule, or with a Sync now button. Requests carry the Hardcover metadata and cover. - **Automatic downloads**: synced requests are approved and a release is picked from a source priority list. A strict title, author and format match (plus a seeder minimum for torrents) decides, so anything without a confident match stays pending for manual review. - **Skip books you already own**: sync and automatic downloads ask whichever libraries are enabled under Library Check (Calibre today) and skip a book that is already there. On top of Caleb's commit I made the request owner a lookup instead of assuming user id 1, sent synced cover URLs through the proxy when the request is created, got ruff and basedpyright clean, and added tests and `docs/hardcover-sync.md`. His commit also had its own Audiobookshelf settings and a Test library connection button, written before the library check was split into providers. The button would have raised a TypeError against the current `test_connection`, so those settings are gone from this tab and an Audiobookshelf provider comes as a separate PR, which is the part of #1047 that is missing here (for now anyways...). I've run this daily for about a couple of weeks. Ruff, basedpyright and the backend suite pass (4426 passed). This is 1 of 5. As calibrain suggested, the rest are stacked on this one, each saying which number it is. Closes https://github.com/calibrain/shelfmark/pull/1047#issuecomment-6302071588 --------- Co-authored-by: InfiniteAvenger <calebewest02@gmail.com> Co-authored-by: CaliBrain <calibrain@l4n.xyz>
72 lines
2.2 KiB
Python
72 lines
2.2 KiB
Python
"""Tests for the Hardcover Sync settings tab registration and action buttons."""
|
|
|
|
import shelfmark.config.hardcover_sync_settings # noqa: F401 - registers the tab
|
|
from shelfmark.core import settings_registry
|
|
|
|
|
|
def _field_map():
|
|
tab = settings_registry.get_settings_tab("hardcover_sync")
|
|
assert tab is not None
|
|
return {field.key: field for field in tab.fields if hasattr(field, "key")}
|
|
|
|
|
|
def test_tab_is_registered():
|
|
tab = settings_registry.get_settings_tab("hardcover_sync")
|
|
|
|
assert tab is not None
|
|
assert tab.display_name == "Hardcover Sync"
|
|
|
|
|
|
def test_everything_is_off_by_default():
|
|
fields = _field_map()
|
|
|
|
assert fields["HARDCOVER_SYNC_ENABLED"].default is False
|
|
assert fields["AUTO_DOWNLOAD_ENABLED"].default is False
|
|
|
|
|
|
def test_schedule_and_content_type_defaults():
|
|
fields = _field_map()
|
|
|
|
assert fields["HARDCOVER_SYNC_INTERVAL"].default == 6
|
|
assert fields["HARDCOVER_SYNC_INTERVAL"].min_value == 1
|
|
assert fields["HARDCOVER_SYNC_INTERVAL_UNIT"].default == "hours"
|
|
assert fields["HARDCOVER_SYNC_CONTENT_TYPE"].default == "audiobook"
|
|
assert fields["HARDCOVER_SYNC_STATUSES"].default == "1"
|
|
assert fields["AUTO_DOWNLOAD_SOURCE_PRIORITY"].default == []
|
|
|
|
|
|
def test_shelf_options_come_from_hardcover_statuses():
|
|
options = _field_map()["HARDCOVER_SYNC_STATUSES"].options()
|
|
|
|
assert {"value": "1", "label": "Want to Read"} in options
|
|
|
|
|
|
def test_action_buttons_are_registered():
|
|
fields = _field_map()
|
|
|
|
assert fields["sync_now"].callback is not None
|
|
|
|
|
|
def test_sync_now_reports_busy_when_a_run_is_active(monkeypatch):
|
|
monkeypatch.setattr("shelfmark.core.hardcover_scheduler.trigger_async", lambda **_: False)
|
|
|
|
result = settings_registry.execute_action("hardcover_sync", "sync_now")
|
|
|
|
assert result["success"] is False
|
|
assert "already running" in result["message"]
|
|
|
|
|
|
def test_sync_now_starts_a_forced_run(monkeypatch):
|
|
seen = []
|
|
|
|
def _trigger(**kwargs):
|
|
seen.append(kwargs)
|
|
return True
|
|
|
|
monkeypatch.setattr("shelfmark.core.hardcover_scheduler.trigger_async", _trigger)
|
|
|
|
result = settings_registry.execute_action("hardcover_sync", "sync_now")
|
|
|
|
assert result["success"] is True
|
|
assert seen == [{"force": True}]
|