Search the library in the import section

The search shows the matches from a story site that Bindery does not track yet. The button that lists every such book stays.
This commit is contained in:
tim
2026-10-04 02:04:16 +02:00
parent d28f69d93a
commit b73b2808ca
6 changed files with 117 additions and 15 deletions
+13
View File
@@ -92,11 +92,24 @@ def test_library_search_link_import_and_unlink(client, story, monkeypatch):
monkeypatch.setattr(o, "cwa", lambda: cwa)
monkeypatch.setattr(config, "CWA_URL", "https://cwa.example")
assert client.get("/api/library/candidates").json[0]["id"] == 7
cwa.search.assert_not_called()
# A search for candidates shows only the story-site books that have an ePub.
cwa.search.return_value = [
book,
Book(8, "book-8", "Title in PDF", ["Writer"], "www.royalroad.com", {"pdf": "/book.pdf"}),
Book(9, "book-9", "Title of a novel", ["Writer"], "A Publisher", {"epub": "/novel.epub"}),
]
assert [b["id"] for b in client.get("/api/library/candidates?q=Title").json] == [7]
cwa.search.assert_called_once_with("Title")
assert cwa.site_books.call_count == 1
cwa.search.reset_mock()
cwa.search.return_value = [book]
assert client.get("/api/library/search?q=Title").json[0]["tracked_as"] is None
cwa.search.assert_called_once_with("Title")
linked = client.post(f"/api/stories/{sid}/link", json={"uuid": "book-7"}, headers=H)
assert linked.json["calibre_id"] == 7
assert client.get("/api/library/candidates").json == []
assert client.get("/api/library/candidates?q=Title").json == []
assert client.get("/api/library/search?q=Title").json[0]["tracked_as"] == "Story"
cwa.get_book.side_effect = CwaError("offline")
assert client.get(f"/api/stories/{sid}").json["library_error"] == "offline"