mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-04-06 07:47:53 +10:00
Avoid filesystem lookups in snapshot admin list
This commit is contained in:
@@ -11,6 +11,8 @@ from typing import List, Dict, Any, Optional, Tuple
|
||||
|
||||
import pytest
|
||||
|
||||
from archivebox.uuid_compat import uuid7
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# CLI Helpers (defined before fixtures that use them)
|
||||
@@ -399,8 +401,7 @@ def assert_record_has_fields(record: Dict[str, Any], required_fields: List[str])
|
||||
|
||||
def create_test_url(domain: str = 'example.com', path: str = None) -> str:
|
||||
"""Generate unique test URL."""
|
||||
import uuid
|
||||
path = path or uuid.uuid4().hex[:8]
|
||||
path = path or uuid7().hex[:8]
|
||||
return f'https://{domain}/{path}'
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,8 @@ import subprocess
|
||||
from pathlib import Path
|
||||
from datetime import datetime, timezone
|
||||
from typing import Dict, List, Tuple
|
||||
from uuid import uuid4
|
||||
|
||||
from archivebox.uuid_compat import uuid7
|
||||
|
||||
|
||||
# =============================================================================
|
||||
@@ -495,7 +496,7 @@ INSERT INTO django_content_type (app_label, model) VALUES
|
||||
|
||||
def generate_uuid() -> str:
|
||||
"""Generate a UUID string without dashes for SQLite."""
|
||||
return uuid4().hex
|
||||
return uuid7().hex
|
||||
|
||||
|
||||
def generate_timestamp() -> str:
|
||||
|
||||
@@ -135,6 +135,44 @@ class TestAdminSnapshotListView:
|
||||
assert response.status_code == 200
|
||||
assert b'example.com' in response.content
|
||||
|
||||
def test_list_view_avoids_legacy_title_fallbacks(self, client, admin_user, snapshot, monkeypatch):
|
||||
"""Title-less snapshots should render without touching history-based fallback paths."""
|
||||
from archivebox.core.models import Snapshot
|
||||
|
||||
Snapshot.objects.filter(pk=snapshot.pk).update(title='')
|
||||
|
||||
def _latest_title_should_not_be_used(self):
|
||||
raise AssertionError('admin changelist should not access Snapshot.latest_title')
|
||||
|
||||
def _history_should_not_be_used(self):
|
||||
raise AssertionError('admin changelist should not access Snapshot.history')
|
||||
|
||||
monkeypatch.setattr(Snapshot, 'latest_title', property(_latest_title_should_not_be_used), raising=False)
|
||||
monkeypatch.setattr(Snapshot, 'history', property(_history_should_not_be_used), raising=False)
|
||||
|
||||
client.login(username='testadmin', password='testpassword')
|
||||
url = reverse('admin:core_snapshot_changelist')
|
||||
response = client.get(url, HTTP_HOST=ADMIN_HOST)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert b'example.com' in response.content
|
||||
|
||||
def test_list_view_avoids_output_dir_lookups(self, client, admin_user, snapshot, monkeypatch):
|
||||
"""Changelist links should render without probing snapshot paths on disk."""
|
||||
from archivebox.core.models import Snapshot
|
||||
|
||||
def _output_dir_should_not_be_used(self):
|
||||
raise AssertionError('admin changelist should not access Snapshot.output_dir')
|
||||
|
||||
monkeypatch.setattr(Snapshot, 'output_dir', property(_output_dir_should_not_be_used), raising=False)
|
||||
|
||||
client.login(username='testadmin', password='testpassword')
|
||||
url = reverse('admin:core_snapshot_changelist')
|
||||
response = client.get(url, HTTP_HOST=ADMIN_HOST)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert b'example.com' in response.content
|
||||
|
||||
def test_grid_view_renders(self, client, admin_user):
|
||||
"""Test that the grid view renders successfully."""
|
||||
client.login(username='testadmin', password='testpassword')
|
||||
|
||||
Reference in New Issue
Block a user