feat(connect): scan audiobookshelf and call a webhook after changes
This commit is contained in:
1 parent
40a829c80c
commit
f7f89a3cc7
6 files changed
+144
-21
No files matched your search
@@ -1220,3 +1220,53 @@ def test_history_records_what_happened_to_a_request(client):
|
||||
assert rows[2]["dest"] == dest
|
||||
assert rows[3]["message"]
|
||||
assert rows[0]["at"].endswith("+00:00")
|
||||
|
||||
|
||||
def test_connections_hear_about_committed_rows(client, monkeypatch):
|
||||
import httpx
|
||||
|
||||
from wordarr import connect
|
||||
|
||||
calls = []
|
||||
|
||||
def handler(request):
|
||||
calls.append((request.method, str(request.url)))
|
||||
if request.url.path == "/api/libraries":
|
||||
return httpx.Response(200, json={"libraries": [
|
||||
{"id": "lib-audio", "name": "Audio",
|
||||
"folders": [{"fullPath": str(client.tmp_path / "library")}]},
|
||||
{"id": "lib-pod", "name": "Pod", "folders": [{"fullPath": "/podcasts"}]},
|
||||
]})
|
||||
if request.url.host == "hook":
|
||||
return httpx.Response(500) # a broken webhook must not stop the scan
|
||||
return httpx.Response(200)
|
||||
|
||||
real_client = httpx.Client
|
||||
monkeypatch.setattr(connect.httpx, "Client",
|
||||
lambda **kw: real_client(transport=httpx.MockTransport(handler), **kw))
|
||||
monkeypatch.setattr(connect, "WEBHOOK_URL", "http://hook/in")
|
||||
monkeypatch.setattr(connect, "ABS_URL", "http://abs")
|
||||
monkeypatch.setattr(connect, "ABS_TOKEN", "t")
|
||||
|
||||
root = client.tmp_path / "library" / "conn"
|
||||
lib_id = client.post("/api/libraries", json={
|
||||
"name": "conn", "media_type": "ebook", "root_path": str(root),
|
||||
"folder_template": "{Title}", "file_template": "{Title}",
|
||||
}).json()["id"]
|
||||
req_id = client.post("/api/requests", json={
|
||||
"library_id": lib_id, "title": "Momo"}).json()["id"]
|
||||
src = client.downloads / "Momo.epub"
|
||||
src.write_bytes(b"x")
|
||||
assert client.post("/api/import", json={"items": [{
|
||||
"path": str(src), "is_dir": False, "files": [str(src)], "request_id": req_id,
|
||||
}]}).json()["results"][0]["ok"]
|
||||
|
||||
assert calls == [
|
||||
("POST", "http://hook/in"),
|
||||
("GET", "http://abs/api/libraries"),
|
||||
("POST", "http://abs/api/libraries/lib-audio/scan"),
|
||||
]
|
||||
|
||||
calls.clear()
|
||||
client.delete(f"/api/requests/{req_id}")
|
||||
assert calls == [("POST", "http://hook/in")] # nothing new on disk, no scan
|
||||
Reference in new issue
Block a user