mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-09-12 19:50:57 +05:00
test: require success in cli workflows
This commit is contained in:
parent
acc830d30f
commit
9f0544857c
@ -12,9 +12,10 @@ from archivebox.misc.util import docstring
|
||||
def shell(args: Iterable[str] = ()) -> None:
|
||||
"""Enter an interactive ArchiveBox Django shell"""
|
||||
|
||||
from django.core.management import call_command
|
||||
from django.core.management import call_command, get_commands
|
||||
|
||||
call_command("shell_plus", *args)
|
||||
shell_command = "shell_plus" if "shell_plus" in get_commands() else "shell"
|
||||
call_command(shell_command, *args)
|
||||
|
||||
|
||||
@click.command(add_help_option=False, context_settings=dict(ignore_unknown_options=True))
|
||||
|
||||
@ -614,10 +614,12 @@ def test_cli_add_real_urls_with_options_writes_inspectable_outputs(initialized_a
|
||||
by_url_plugin = {(url, plugin): status for url, plugin, status, _files, _size, _output in archive_results}
|
||||
assert by_url_plugin[("https://example.com", "wget")] == "succeeded"
|
||||
assert by_url_plugin[("https://pirate.github.io/stress-tests/challenge.html", "wget")] == "succeeded"
|
||||
assert (chrome_url, "headers") in by_url_plugin
|
||||
assert (chrome_url, "title") in by_url_plugin
|
||||
failed_results = [(url, plugin, output) for url, plugin, status, _files, _size, output in archive_results if status == "failed"]
|
||||
assert len(failed_results) <= 2, failed_results
|
||||
assert by_url_plugin[(chrome_url, "headers")] == "succeeded"
|
||||
assert by_url_plugin[(chrome_url, "title")] == "succeeded"
|
||||
unexpected_results = [
|
||||
(url, plugin, status, output) for url, plugin, status, _files, _size, output in archive_results if status != "succeeded"
|
||||
]
|
||||
assert not unexpected_results
|
||||
|
||||
snapshot_root = initialized_archive / "archive/users/system/snapshots"
|
||||
html_outputs = [path for path in snapshot_root.rglob("wget/**/*.html") if path.is_file()]
|
||||
@ -625,11 +627,10 @@ def test_cli_add_real_urls_with_options_writes_inspectable_outputs(initialized_a
|
||||
title_outputs = [path for path in snapshot_root.rglob("title/title.txt") if path.is_file() and path.stat().st_size > 0]
|
||||
index_outputs = [path for path in snapshot_root.rglob("index.jsonl") if path.is_file()]
|
||||
assert html_outputs
|
||||
if by_url_plugin[(chrome_url, "headers")] == "succeeded":
|
||||
assert header_outputs
|
||||
if by_url_plugin[(chrome_url, "title")] == "succeeded":
|
||||
assert title_outputs
|
||||
assert any("Example Domain" in path.read_text(errors="ignore") for path in title_outputs)
|
||||
assert header_outputs
|
||||
assert any("example.com" in path.read_text(errors="ignore").lower() for path in header_outputs)
|
||||
assert title_outputs
|
||||
assert any("Example Domain" in path.read_text(errors="ignore") for path in title_outputs)
|
||||
assert len(index_outputs) >= len(wget_urls) + 1
|
||||
|
||||
combined_html = "\n".join(path.read_text(errors="ignore") for path in html_outputs)
|
||||
|
||||
@ -6,6 +6,7 @@ Verify install detects and records binary dependencies in DB.
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from archivebox.tests.conftest import run_archivebox_cmd
|
||||
|
||||
import pytest
|
||||
@ -25,20 +26,21 @@ def test_install_runs_successfully(initialized_archive):
|
||||
timeout=60,
|
||||
)
|
||||
|
||||
# Dry run should complete quickly
|
||||
assert result.returncode in [0, 1] # May return 1 if binaries missing
|
||||
assert result.returncode == 0, result.stderr or result.stdout
|
||||
assert "Dry run - would detect ArchiveBox dependencies" in result.stdout
|
||||
|
||||
|
||||
def test_install_creates_binary_records_in_db(initialized_archive):
|
||||
"""Test that install creates Binary records in database."""
|
||||
"""Test that install --dry-run does not create Binary records in database."""
|
||||
|
||||
run_archivebox_cmd(
|
||||
result = run_archivebox_cmd(
|
||||
["install", "--dry-run"],
|
||||
timeout=60,
|
||||
)
|
||||
assert result.returncode == 0, result.stderr or result.stdout
|
||||
|
||||
with use_archivebox_db(initialized_archive):
|
||||
Binary.objects.count()
|
||||
assert Binary.objects.count() == 0
|
||||
|
||||
|
||||
def test_install_dry_run_does_not_install(initialized_archive):
|
||||
@ -49,8 +51,8 @@ def test_install_dry_run_does_not_install(initialized_archive):
|
||||
timeout=60,
|
||||
)
|
||||
|
||||
# Should complete without actually installing
|
||||
assert "dry" in result.stdout.lower() or result.returncode in [0, 1]
|
||||
assert result.returncode == 0, result.stderr or result.stdout
|
||||
assert result.stdout.strip() == "Dry run - would detect ArchiveBox dependencies and run the abx-dl install flow"
|
||||
|
||||
|
||||
def test_install_detects_system_binaries(initialized_archive):
|
||||
@ -61,8 +63,8 @@ def test_install_detects_system_binaries(initialized_archive):
|
||||
timeout=60,
|
||||
)
|
||||
|
||||
# Should detect at least some common binaries (python, curl, etc)
|
||||
assert result.returncode in [0, 1]
|
||||
assert result.returncode == 0, result.stderr or result.stdout
|
||||
assert "ArchiveBox dependencies" in result.stdout
|
||||
|
||||
|
||||
def test_install_shows_binary_status(initialized_archive):
|
||||
@ -73,9 +75,8 @@ def test_install_shows_binary_status(initialized_archive):
|
||||
timeout=60,
|
||||
)
|
||||
|
||||
output = result.stdout + result.stderr
|
||||
# Should show some binary information
|
||||
assert len(output) > 50
|
||||
assert result.returncode == 0, result.stderr or result.stdout
|
||||
assert result.stdout.strip() == "Dry run - would detect ArchiveBox dependencies and run the abx-dl install flow"
|
||||
|
||||
|
||||
def test_install_dry_run_prints_dry_run_message(initialized_archive):
|
||||
|
||||
@ -53,5 +53,5 @@ def test_manage_check_works(initialized_archive):
|
||||
timeout=30,
|
||||
)
|
||||
|
||||
# Check should complete
|
||||
assert result.returncode in [0, 1]
|
||||
assert result.returncode == 0, result.stderr or result.stdout
|
||||
assert "System check identified no issues" in result.stdout
|
||||
|
||||
@ -219,20 +219,29 @@ def test_remove_reports_remaining_link_count_correctly(initialized_archive):
|
||||
|
||||
def test_remove_after_flag(initialized_archive):
|
||||
"""Test remove --after flag removes snapshots after date."""
|
||||
env = cli_env(disable_extractors=True)
|
||||
env = cli_env()
|
||||
|
||||
run_archivebox_cmd(
|
||||
["add", "--index-only", "--depth=0", "https://example.com"],
|
||||
env=env,
|
||||
check=True,
|
||||
)
|
||||
run_queued_crawls(initialized_archive, env)
|
||||
|
||||
# Try remove with --after flag (should work or show usage)
|
||||
rows = _snapshot_rows(initialized_archive, env)
|
||||
assert len(rows) == 1
|
||||
snapshot_dir = find_snapshot_dir(initialized_archive, rows[0]["id"])
|
||||
assert snapshot_dir is not None, f"Snapshot output directory not found for {rows[0]['id']}"
|
||||
|
||||
result = run_archivebox_cmd(
|
||||
["remove", "--after=2020-01-01", "--yes"],
|
||||
["remove", "--after=1577836800", "--yes"],
|
||||
env=env,
|
||||
timeout=30,
|
||||
check=True,
|
||||
)
|
||||
|
||||
# Should complete
|
||||
assert result.returncode in [0, 1, 2]
|
||||
output = result.stdout + result.stderr
|
||||
assert "Removed 1 out of 1 links" in output
|
||||
assert "Index now contains 0 links." in output
|
||||
assert len(_snapshot_rows(initialized_archive, env)) == 0
|
||||
assert not snapshot_dir.exists()
|
||||
|
||||
@ -10,14 +10,14 @@ from archivebox.tests.conftest import run_archivebox_cmd
|
||||
def test_shell_command_exists(initialized_archive):
|
||||
"""Test that shell command is recognized."""
|
||||
|
||||
# Test that the command exists (will fail without input but should recognize command)
|
||||
result = run_archivebox_cmd(
|
||||
["shell", "--help"],
|
||||
timeout=10,
|
||||
)
|
||||
|
||||
# Should show shell help or recognize command
|
||||
assert result.returncode in [0, 1, 2]
|
||||
assert result.returncode == 0, result.stderr or result.stdout
|
||||
assert "usage:" in result.stdout
|
||||
assert "shell" in result.stdout
|
||||
|
||||
|
||||
def test_shell_c_executes_python(initialized_archive):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user