forked from retoor/devplacepy
Add personal notes, DeepSearch history, backup offload, and gateway auth throttling
Also streamline the top navigation: drop the Tools dropdown, make Quizzes and Battles icon-only entries, and remove the Workspace, Containers and Editor entry points from the project detail page.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
# retoor <retoor@molodetz.nl>
|
||||
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
from tests.conftest import run_async
|
||||
from devplacepy.services.backup import offload, store
|
||||
|
||||
|
||||
def _make_backup(target):
|
||||
job_uid = f"job-{store.generate_uid()}"
|
||||
uid = store.create_backup(target=target, created_by="test", job_uid=job_uid)
|
||||
path = Path(tempfile.gettempdir()) / f"backup-offload-test-{uid}.tar.gz"
|
||||
path.write_bytes(b"x" * 10)
|
||||
store.finalize_backup(
|
||||
uid,
|
||||
filename=path.name,
|
||||
local_path=str(path),
|
||||
stats={
|
||||
"bytes_out": 10,
|
||||
"bytes_in": 10,
|
||||
"file_count": 1,
|
||||
"dir_count": 0,
|
||||
"sha256": "abc",
|
||||
},
|
||||
)
|
||||
return uid, path
|
||||
|
||||
|
||||
def test_upload_pending_stops_after_auth_error(local_db, monkeypatch):
|
||||
first_uid, first_path = _make_backup("database")
|
||||
second_uid, second_path = _make_backup("uploads")
|
||||
calls = []
|
||||
|
||||
async def fake_rclone(*args, timeout=1800.0):
|
||||
calls.append(args)
|
||||
return 1, "", "401 Unauthorized from Apache"
|
||||
|
||||
monkeypatch.setattr(offload, "_run_rclone", fake_rclone)
|
||||
logs = []
|
||||
try:
|
||||
uploaded = run_async(offload.upload_pending(log=logs.append))
|
||||
assert uploaded == 0
|
||||
assert len(calls) == 1
|
||||
assert any("halted" in line.lower() for line in logs)
|
||||
finally:
|
||||
first_path.unlink(missing_ok=True)
|
||||
second_path.unlink(missing_ok=True)
|
||||
store.delete_backup(first_uid)
|
||||
store.delete_backup(second_uid)
|
||||
|
||||
|
||||
def test_is_auth_error_detects_rclone_html_401():
|
||||
assert offload._is_auth_error(
|
||||
'read metadata failed: <title>401 Unauthorized</title>: 401 Unauthorized'
|
||||
)
|
||||
assert offload._is_auth_error("didn't find section in config file")
|
||||
assert not offload._is_auth_error("connection timed out")
|
||||
Reference in New Issue
Block a user