mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-09-14 11:06:13 +05:00
67 lines
1.7 KiB
Python
67 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Tests for archivebox extract command.
|
|
Verify extract re-runs extractors on existing snapshots.
|
|
"""
|
|
|
|
import os
|
|
import subprocess
|
|
|
|
import pytest
|
|
|
|
from archivebox.core.models import Snapshot
|
|
from archivebox.tests.test_orm_helpers import use_archivebox_db
|
|
|
|
pytestmark = pytest.mark.django_db(transaction=True)
|
|
|
|
|
|
def test_extract_runs_on_existing_snapshots(tmp_path, process, disable_extractors_dict):
|
|
"""Test that extract command runs on existing snapshots."""
|
|
os.chdir(tmp_path)
|
|
|
|
# Add a snapshot first
|
|
subprocess.run(
|
|
["archivebox", "add", "--index-only", "--depth=0", "https://example.com"],
|
|
capture_output=True,
|
|
env=disable_extractors_dict,
|
|
)
|
|
|
|
# Run extract
|
|
result = subprocess.run(
|
|
["archivebox", "extract"],
|
|
capture_output=True,
|
|
env=disable_extractors_dict,
|
|
timeout=30,
|
|
)
|
|
|
|
# Should complete
|
|
assert result.returncode in [0, 1]
|
|
|
|
|
|
def test_extract_preserves_snapshot_count(tmp_path, process, disable_extractors_dict):
|
|
"""Test that extract doesn't change snapshot count."""
|
|
os.chdir(tmp_path)
|
|
|
|
# Add snapshot
|
|
subprocess.run(
|
|
["archivebox", "add", "--index-only", "--depth=0", "https://example.com"],
|
|
capture_output=True,
|
|
env=disable_extractors_dict,
|
|
)
|
|
|
|
with use_archivebox_db(tmp_path):
|
|
count_before = Snapshot.objects.count()
|
|
|
|
# Run extract
|
|
subprocess.run(
|
|
["archivebox", "extract", "--overwrite"],
|
|
capture_output=True,
|
|
env=disable_extractors_dict,
|
|
timeout=30,
|
|
)
|
|
|
|
with use_archivebox_db(tmp_path):
|
|
count_after = Snapshot.objects.count()
|
|
|
|
assert count_after == count_before
|