fix(metadata): keep hardcover books whose editions carry no language
This commit is contained in:
1 parent
91ad7ff98b
commit
b51d5754e0
2 files changed
+95
-13
No files matched your search
+54
-1
@@ -25,6 +25,7 @@ GERMAN_EDITION = {
|
||||
"isbn_10": None,
|
||||
"release_date": "1957-03-01",
|
||||
"cached_image": "https://example.invalid/hobbit-de.jpg",
|
||||
"language": {"code2": "de"},
|
||||
}
|
||||
|
||||
|
||||
@@ -83,6 +84,38 @@ def test_hardcover_drops_books_without_an_edition_in_that_language(monkeypatch):
|
||||
assert asyncio.run(hardcover.search("hobbit", "german")) == []
|
||||
|
||||
|
||||
def test_hardcover_keeps_a_book_whose_editions_carry_no_language(monkeypatch):
|
||||
"""German translations are often their own book row with untagged editions."""
|
||||
def handler(request: httpx.Request) -> httpx.Response:
|
||||
import json
|
||||
if "editions" in json.loads(request.content)["query"]:
|
||||
return httpx.Response(200, json={"data": {
|
||||
"editions": [{"book_id": 42, "title": "Der Hobbit", "language": None}],
|
||||
"other": [],
|
||||
}})
|
||||
return httpx.Response(200, json={"data": {"search": {"results": {"hits": [HARDCOVER_HIT]}}}})
|
||||
|
||||
monkeypatch.setattr(hardcover, "TOKEN", "test-token")
|
||||
mock_client(monkeypatch, hardcover, handler)
|
||||
hit = asyncio.run(hardcover.search("hobbit", "german"))[0]
|
||||
assert (hit.title, hit.language) == ("Der Hobbit", "")
|
||||
|
||||
|
||||
def test_hardcover_drops_an_untagged_edition_of_a_foreign_book(monkeypatch):
|
||||
def handler(request: httpx.Request) -> httpx.Response:
|
||||
import json
|
||||
if "editions" in json.loads(request.content)["query"]:
|
||||
return httpx.Response(200, json={"data": {
|
||||
"editions": [{"book_id": 42, "title": "The Hobbit", "language": None}],
|
||||
"other": [{"book_id": 42}],
|
||||
}})
|
||||
return httpx.Response(200, json={"data": {"search": {"results": {"hits": [HARDCOVER_HIT]}}}})
|
||||
|
||||
monkeypatch.setattr(hardcover, "TOKEN", "test-token")
|
||||
mock_client(monkeypatch, hardcover, handler)
|
||||
assert asyncio.run(hardcover.search("hobbit", "german")) == []
|
||||
|
||||
|
||||
SERIES_ROWS = {
|
||||
"name": "Die drei Fragezeichen",
|
||||
"book_series": [
|
||||
@@ -129,7 +162,8 @@ def test_hardcover_series_sorts_by_volume_and_keeps_the_first_row(monkeypatch):
|
||||
def test_hardcover_series_prefers_the_row_with_an_edition_in_the_language(monkeypatch):
|
||||
calls = series_client(monkeypatch, [
|
||||
{"book_id": 3, "title": "Der Phantomsee", "isbn_13": "9783440032251",
|
||||
"release_date": "1969-01-01", "cached_image": None},
|
||||
"release_date": "1969-01-01", "cached_image": None,
|
||||
"language": {"code2": "de"}},
|
||||
])
|
||||
books = asyncio.run(hardcover.series_books("10146", "german"))
|
||||
assert calls[1] == {"ids": [1, 2, 3, 4], "lang": "de"}
|
||||
@@ -280,3 +314,22 @@ def test_automatic_search_asks_only_the_best_provider(monkeypatch):
|
||||
monkeypatch.setattr(openlibrary, "search", lambda q, lang="", fb=True: record("ol", q, lang))
|
||||
asyncio.run(metadata.ebook_search("hobbit", "german", fallback=False))
|
||||
assert called == ["gb"] # no token, so Google Books stands in for Hardcover
|
||||
|
||||
|
||||
def test_hardcover_puts_hits_of_unknown_language_last(monkeypatch):
|
||||
untagged = {"document": {**HARDCOVER_HIT["document"], "id": "7", "title": "Bundle"}}
|
||||
|
||||
def handler(request: httpx.Request) -> httpx.Response:
|
||||
import json
|
||||
if "editions" in json.loads(request.content)["query"]:
|
||||
return httpx.Response(200, json={"data": {"editions": [
|
||||
{"book_id": 7, "title": "Bundle", "language": None},
|
||||
GERMAN_EDITION,
|
||||
]}})
|
||||
return httpx.Response(200, json={"data": {"search": {"results": {
|
||||
"hits": [untagged, HARDCOVER_HIT]}}}})
|
||||
|
||||
monkeypatch.setattr(hardcover, "TOKEN", "test-token")
|
||||
mock_client(monkeypatch, hardcover, handler)
|
||||
hits = asyncio.run(hardcover.search("hobbit", "german"))
|
||||
assert [h.title for h in hits] == ["Der Hobbit", "Bundle"]
|
||||
Reference in new issue
Block a user