add(ui/ux): show file formats in the scan and filter by them
This commit is contained in:
@@ -6,6 +6,8 @@ from pathlib import Path
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from wordarr import config as config_module
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(tmp_path, monkeypatch):
|
||||
@@ -1093,3 +1095,43 @@ def test_scan_does_not_loop_on_a_symlink_cycle(client):
|
||||
(d / "back").symlink_to(client.downloads, target_is_directory=True)
|
||||
items = scanner.scan(client.downloads)
|
||||
assert [i["name"] for i in items] == ["book"]
|
||||
|
||||
|
||||
def test_scan_reports_the_format_of_every_ebook(client):
|
||||
"""A Calibre export is the same book a dozen times; the rows differ only in
|
||||
their extension, so the scan has to name it."""
|
||||
book = "Der Lehrer - Will er dir helfen - McFadden, Freida"
|
||||
for ext, size in ((".epub", 1200), (".azw3", 1300), (".pdf", 2100)):
|
||||
(client.downloads / f"{book}{ext}").write_bytes(b"x" * size)
|
||||
|
||||
items = client.get("/api/import/scan").json()["items"]
|
||||
assert {i["formats"][0]: i["size"] for i in items} == {
|
||||
"epub": 1200, "azw3": 1300, "pdf": 2100,
|
||||
}
|
||||
assert all(len(i["formats"]) == 1 for i in items)
|
||||
|
||||
|
||||
def test_scan_lists_every_format_of_an_audiobook_folder(client):
|
||||
got = client.downloads / "Ein Hoerbuch"
|
||||
got.mkdir()
|
||||
(got / "01 Teil.mp3").write_bytes(b"x" * 10)
|
||||
(got / "02 Teil.m4b").write_bytes(b"x" * 20)
|
||||
|
||||
item = client.get("/api/import/scan").json()["items"][0]
|
||||
assert item["formats"] == ["m4b", "mp3"]
|
||||
assert item["size"] == 30
|
||||
|
||||
|
||||
def test_extra_ebook_extensions_are_configurable(client, monkeypatch):
|
||||
"""The exotic Calibre formats stay out of the scan until they are asked for."""
|
||||
(client.downloads / "Der Lehrer.kepub").write_bytes(b"x")
|
||||
assert client.get("/api/import/scan").json()["items"] == []
|
||||
|
||||
monkeypatch.setenv("WORDARR_EXTRA_EBOOK_EXTENSIONS", ".kepub")
|
||||
importlib.reload(config_module)
|
||||
try:
|
||||
items = client.get("/api/import/scan").json()["items"]
|
||||
assert [i["formats"] for i in items] == [["kepub"]]
|
||||
finally:
|
||||
monkeypatch.delenv("WORDARR_EXTRA_EBOOK_EXTENSIONS")
|
||||
importlib.reload(config_module)
|
||||
|
||||
Reference in New Issue
Block a user