mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-09-14 11:06:13 +05:00
test: make extract cli setup deterministic
This commit is contained in:
parent
f4ec16c3c8
commit
cd7e7cd132
@ -1,15 +1,10 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Tests for archivebox extract command.
|
||||
Verify extract re-runs extractors on existing snapshots.
|
||||
"""
|
||||
|
||||
import json
|
||||
"""Tests for archivebox extract command."""
|
||||
|
||||
import pytest
|
||||
|
||||
from archivebox.core.models import Snapshot
|
||||
from archivebox.tests.conftest import run_archivebox_cmd, cli_env
|
||||
from archivebox.core.models import ArchiveResult, Snapshot
|
||||
from archivebox.tests.conftest import cli_env, parse_jsonl_output, run_archivebox_cmd
|
||||
|
||||
from archivebox.tests.test_orm_helpers import use_archivebox_db
|
||||
|
||||
@ -17,50 +12,56 @@ 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"],
|
||||
result = run_archivebox_cmd(
|
||||
["snapshot", "create", url],
|
||||
cwd=data_dir,
|
||||
stdin=f"{record}\n",
|
||||
env=env,
|
||||
check=True,
|
||||
)
|
||||
snapshot = next(record for record in parse_jsonl_output(result.stdout) if record.get("type") == "Snapshot")
|
||||
return snapshot
|
||||
|
||||
|
||||
def test_extract_runs_on_existing_snapshots(initialized_archive):
|
||||
"""Test that extract command runs on existing snapshots."""
|
||||
"""Extract queues a requested plugin for an existing snapshot."""
|
||||
env = cli_env(disable_extractors=True)
|
||||
|
||||
_create_snapshot(initialized_archive, env)
|
||||
snapshot = _create_snapshot(initialized_archive, env)
|
||||
snapshot_id = snapshot["id"]
|
||||
|
||||
# Run extract
|
||||
result = run_archivebox_cmd(
|
||||
["extract"],
|
||||
["extract", "--plugin=title", "--no-wait", snapshot_id],
|
||||
cwd=initialized_archive,
|
||||
env=env,
|
||||
timeout=30,
|
||||
)
|
||||
|
||||
# Should complete
|
||||
assert result.returncode in [0, 1]
|
||||
assert result.returncode == 0, result.stderr or result.stdout
|
||||
|
||||
with use_archivebox_db(initialized_archive):
|
||||
archiveresult = ArchiveResult.objects.get(snapshot_id=snapshot_id, plugin="title")
|
||||
extracted_snapshot = Snapshot.objects.get(id=snapshot_id)
|
||||
|
||||
assert archiveresult.status == ArchiveResult.StatusChoices.QUEUED
|
||||
assert extracted_snapshot.retry_at is not None
|
||||
|
||||
|
||||
def test_extract_preserves_snapshot_count(initialized_archive):
|
||||
"""Test that extract doesn't change snapshot count."""
|
||||
"""Extract queues work without creating duplicate snapshots."""
|
||||
env = cli_env(disable_extractors=True)
|
||||
|
||||
_create_snapshot(initialized_archive, env)
|
||||
snapshot = _create_snapshot(initialized_archive, env)
|
||||
|
||||
with use_archivebox_db(initialized_archive):
|
||||
count_before = Snapshot.objects.count()
|
||||
|
||||
# Run extract
|
||||
run_archivebox_cmd(
|
||||
["extract", "--overwrite"],
|
||||
result = run_archivebox_cmd(
|
||||
["extract", "--plugin=title", "--no-wait", snapshot["id"]],
|
||||
cwd=initialized_archive,
|
||||
env=env,
|
||||
timeout=30,
|
||||
)
|
||||
assert result.returncode == 0, result.stderr or result.stdout
|
||||
|
||||
with use_archivebox_db(initialized_archive):
|
||||
count_after = Snapshot.objects.count()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user