test: create extract snapshots via cli

This commit is contained in:
Nick Sweeting 2026-06-02 19:56:25 -07:00
parent 9b5aa6861d
commit f4ec16c3c8
No known key found for this signature in database

View File

@ -4,30 +4,39 @@ Tests for archivebox extract command.
Verify extract re-runs extractors on existing snapshots.
"""
import json
import pytest
from archivebox.core.models import Snapshot
from archivebox.tests.conftest import run_queued_crawls, run_archivebox_cmd, cli_env
from archivebox.tests.conftest import run_archivebox_cmd, cli_env
from archivebox.tests.test_orm_helpers import use_archivebox_db
pytestmark = pytest.mark.django_db(transaction=True)
def _create_snapshot(data_dir, env, url="https://example.com"):
record = json.dumps({"type": "Snapshot", "url": url})
run_archivebox_cmd(
["snapshot", "create"],
cwd=data_dir,
stdin=f"{record}\n",
env=env,
check=True,
)
def test_extract_runs_on_existing_snapshots(initialized_archive):
"""Test that extract command runs on existing snapshots."""
env = cli_env(disable_extractors=True)
# Add a snapshot first
run_archivebox_cmd(
["add", "--index-only", "--depth=0", "https://example.com"],
env=env,
)
run_queued_crawls(initialized_archive, env)
_create_snapshot(initialized_archive, env)
# Run extract
result = run_archivebox_cmd(
["extract"],
cwd=initialized_archive,
env=env,
timeout=30,
)
@ -40,12 +49,7 @@ def test_extract_preserves_snapshot_count(initialized_archive):
"""Test that extract doesn't change snapshot count."""
env = cli_env(disable_extractors=True)
# Add snapshot
run_archivebox_cmd(
["add", "--index-only", "--depth=0", "https://example.com"],
env=env,
)
run_queued_crawls(initialized_archive, env)
_create_snapshot(initialized_archive, env)
with use_archivebox_db(initialized_archive):
count_before = Snapshot.objects.count()
@ -53,6 +57,7 @@ def test_extract_preserves_snapshot_count(initialized_archive):
# Run extract
run_archivebox_cmd(
["extract", "--overwrite"],
cwd=initialized_archive,
env=env,
timeout=30,
)