test cleanup

This commit is contained in:
2026-05-05 15:28:31 -04:00
parent 1dc501f50f
commit 06eb00ab3e
2 changed files with 5 additions and 134 deletions
-128
View File
@@ -52,13 +52,6 @@ def test_update_settings(client):
assert response.json()["schedule_scan"] == "0 2 * * *" assert response.json()["schedule_scan"] == "0 2 * * *"
def test_list_jobs_empty(client):
"""Tests listing jobs when none exist."""
response = client.get("/system/jobs")
assert response.status_code == 200
assert response.json() == []
def test_trigger_scan(client): def test_trigger_scan(client):
"""Tests triggering a system scan.""" """Tests triggering a system scan."""
response = client.post("/system/scan") response = client.post("/system/scan")
@@ -104,127 +97,6 @@ def test_scan_status_includes_files_missing(client):
assert data["files_missing"] == 0 assert data["files_missing"] == 0
def test_list_discrepancies_empty(client):
"""Tests listing discrepancies when none exist."""
response = client.get("/system/discrepancies")
assert response.status_code == 200
assert response.json() == []
def test_list_discrepancies_deleted_file(client, db_session):
"""Tests listing a confirmed-deleted file in discrepancies."""
file_record = models.FilesystemState(
file_path="/data/old.txt",
size=100,
mtime=1000,
is_deleted=True,
is_ignored=False,
sha256_hash=None,
)
db_session.add(file_record)
db_session.commit()
response = client.get("/system/discrepancies")
assert response.status_code == 200
data = response.json()
assert len(data) == 1
assert data[0]["path"] == "/data/old.txt"
assert data[0]["is_deleted"] is True
def test_confirm_file_deleted(client, db_session):
"""Tests confirming a file as deleted."""
file_record = models.FilesystemState(
file_path="/data/verify.txt",
size=50,
mtime=2000,
is_deleted=False,
)
db_session.add(file_record)
db_session.commit()
response = client.post(f"/system/discrepancies/{file_record.id}/confirm")
assert response.status_code == 200
assert "marked as deleted" in response.json()["message"]
db_session.expire_all()
db_session.refresh(file_record)
assert file_record.is_deleted is True
def test_confirm_file_deleted_not_found(client):
"""Tests confirming a non-existent file returns 404."""
response = client.post("/system/discrepancies/9999/confirm")
assert response.status_code == 404
def test_dismiss_discrepancy(client, db_session):
"""Tests dismissing a deleted file."""
file_record = models.FilesystemState(
file_path="/data/dismiss.txt",
size=50,
mtime=2000,
is_deleted=True,
)
db_session.add(file_record)
db_session.commit()
response = client.post(f"/system/discrepancies/{file_record.id}/dismiss")
assert response.status_code == 200
assert "dismissed" in response.json()["message"]
db_session.expire_all()
db_session.refresh(file_record)
assert file_record.missing_acknowledged_at is not None
def test_delete_file_record(client, db_session):
"""Tests hard-deleting a file record and its versions."""
media = models.StorageMedia(
media_type="hdd", identifier="M1", capacity=1000, status="active"
)
db_session.add(media)
db_session.flush()
file_record = models.FilesystemState(
file_path="/data/hard_delete.txt",
size=100,
mtime=1000,
is_deleted=True,
)
db_session.add(file_record)
db_session.flush()
db_session.add(
models.FileVersion(
filesystem_state_id=file_record.id,
media_id=media.id,
file_number="1",
offset_start=0,
offset_end=100,
)
)
db_session.commit()
file_id = file_record.id
response = client.delete(f"/system/discrepancies/{file_id}")
assert response.status_code == 200
db_session.expire_all()
# Verify file and version are gone
assert (
db_session.query(models.FilesystemState).filter_by(id=file_id).first() is None
)
assert (
db_session.query(models.FileVersion)
.filter_by(filesystem_state_id=file_id)
.first()
is None
)
def test_dashboard_stats_excludes_failed_media(client, db_session): def test_dashboard_stats_excludes_failed_media(client, db_session):
"""Tests that dashboard stats do not count versions on failed or retired media.""" """Tests that dashboard stats do not count versions on failed or retired media."""
active_media = models.StorageMedia( active_media = models.StorageMedia(
+5 -6
View File
@@ -1,5 +1,7 @@
import hashlib import hashlib
from datetime import datetime, timezone from datetime import datetime, timezone
import pytest
from app.services.scanner import ( from app.services.scanner import (
ScannerService, ScannerService,
JobManager, JobManager,
@@ -146,8 +148,7 @@ def test_scan_sources_mocked(db_session, mocker):
def test_hash_file_batch_fast(tmp_path): def test_hash_file_batch_fast(tmp_path):
"""Tests native sha256sum/shasum batch hashing if available.""" """Tests native sha256sum/shasum batch hashing if available."""
if _FAST_HASH_BINARY is None: if _FAST_HASH_BINARY is None:
# Skip if no native hash binary is available pytest.skip("No native hash binary available")
return
# Create test files # Create test files
files = {} files = {}
@@ -168,7 +169,7 @@ def test_hash_file_batch_fast(tmp_path):
def test_hash_file_batch_fast_empty(): def test_hash_file_batch_fast_empty():
"""Tests that empty batch returns empty results.""" """Tests that empty batch returns empty results."""
if _FAST_HASH_BINARY is None: if _FAST_HASH_BINARY is None:
return pytest.skip("No native hash binary available")
results = _hash_file_batch_fast([], _FAST_HASH_BINARY) results = _hash_file_batch_fast([], _FAST_HASH_BINARY)
assert results == {} assert results == {}
@@ -177,7 +178,7 @@ def test_hash_file_batch_fast_empty():
def test_hash_file_batch_fast_nonexistent(): def test_hash_file_batch_fast_nonexistent():
"""Tests that non-existent files are gracefully handled.""" """Tests that non-existent files are gracefully handled."""
if _FAST_HASH_BINARY is None: if _FAST_HASH_BINARY is None:
return pytest.skip("No native hash binary available")
results = _hash_file_batch_fast(["/nonexistent/path"], _FAST_HASH_BINARY) results = _hash_file_batch_fast(["/nonexistent/path"], _FAST_HASH_BINARY)
# Non-existent files may or may not appear in results depending on binary behavior # Non-existent files may or may not appear in results depending on binary behavior
@@ -222,8 +223,6 @@ def test_missing_file_marked_deleted_at_end_of_scan(db_session, mocker):
def test_existing_file_not_marked_deleted(db_session, mocker): def test_existing_file_not_marked_deleted(db_session, mocker):
"""Tests that files found during scan retain is_deleted=False.""" """Tests that files found during scan retain is_deleted=False."""
scanner = ScannerService() scanner = ScannerService()
print(f"DEBUG test_existing: scanner.is_running = {scanner.is_running}")
print(f"DEBUG test_existing: scanner.is_hashing = {scanner.is_hashing}")
mocker.patch("app.services.scanner._FAST_FIND_BINARY", None) mocker.patch("app.services.scanner._FAST_FIND_BINARY", None)
mocker.patch("app.api.common.get_source_roots", return_value=["/mock_source"]) mocker.patch("app.api.common.get_source_roots", return_value=["/mock_source"])