✨ qBittorrent: cle API native (>= 5.2, Bearer) + compatibilite login 204 + suppression torrent en bypass/port separe
This commit is contained in:
1 parent
c7344f8988
commit
8e76fb7112
8 files changed
+143
-15
No files matched your search
@@ -230,6 +230,58 @@ def test_qbittorrent_connection_without_credentials() -> None:
|
||||
assert test.json()["version"] == "v5.0.2"
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_qbittorrent_login_204_modern() -> None:
|
||||
"""qBittorrent >= 5.2: le login repond 204 sans corps (plus "200 Ok.")."""
|
||||
respx.post("http://192.168.1.50:8080/api/v2/auth/login").mock(
|
||||
return_value=Response(204)
|
||||
)
|
||||
respx.get("http://192.168.1.50:8080/api/v2/app/version").mock(
|
||||
return_value=Response(200, text="v5.2.0")
|
||||
)
|
||||
with TestClient(app) as client:
|
||||
client.put(
|
||||
"/api/settings/qbittorrent",
|
||||
json={
|
||||
"url": "192.168.1.50",
|
||||
"port": 8080,
|
||||
"username": "admin",
|
||||
"password": "pass",
|
||||
},
|
||||
)
|
||||
test = client.post("/api/settings/qbittorrent/test")
|
||||
assert test.status_code == 200
|
||||
assert test.json()["version"] == "v5.2.0"
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_qbittorrent_api_key_mode() -> None:
|
||||
"""Cle API native (qBittorrent >= 5.2): en-tete Authorization: Bearer sur
|
||||
chaque appel, aucun login."""
|
||||
login_route = respx.post("http://192.168.1.50:8080/api/v2/auth/login").mock(
|
||||
return_value=Response(404)
|
||||
)
|
||||
version_route = respx.get("http://192.168.1.50:8080/api/v2/app/version").mock(
|
||||
return_value=Response(200, text="v5.2.0")
|
||||
)
|
||||
with TestClient(app) as client:
|
||||
put = client.put(
|
||||
"/api/settings/qbittorrent",
|
||||
json={"url": "192.168.1.50", "port": 8080, "api_key": "qbt_test_key"},
|
||||
)
|
||||
assert put.json()["api_key_configured"] is True
|
||||
test = client.post("/api/settings/qbittorrent/test")
|
||||
raw = json.loads(config_path().read_text(encoding="utf-8"))
|
||||
assert test.status_code == 200
|
||||
assert test.json()["version"] == "v5.2.0"
|
||||
assert not login_route.called
|
||||
assert version_route.called
|
||||
assert (
|
||||
version_route.calls.last.request.headers["authorization"] == "Bearer qbt_test_key"
|
||||
)
|
||||
assert raw["qbittorrent"]["api_key"] == "qbt_test_key"
|
||||
|
||||
|
||||
def test_settings_persist_to_conf_json() -> None:
|
||||
with TestClient(app) as client:
|
||||
put = client.put(
|
||||
@@ -293,7 +345,11 @@ def test_setup_link_only_without_existing_account() -> None:
|
||||
|
||||
def test_startup_logs_conf_json_summary(capsys) -> None:
|
||||
"""Au lancement, le log indique si conf.json est charge et ce qu'il contient."""
|
||||
from app.conf_store import AppConfig, write_config
|
||||
|
||||
with TestClient(app) as client:
|
||||
# Repart d'une conf vierge: les tests precedents remplissent conf.json.
|
||||
write_config(AppConfig())
|
||||
client.put(
|
||||
"/api/settings/qbittorrent",
|
||||
json={"url": "192.168.1.50", "port": 8555},
|
||||
|
||||
Reference in new issue
Block a user