test_cli_snapshot.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env python3
  2. """
  3. Tests for archivebox snapshot command.
  4. Verify snapshot command works with snapshot IDs/URLs.
  5. """
  6. import os
  7. import subprocess
  8. import sqlite3
  9. from .fixtures import *
  10. def test_snapshot_command_works_with_url(tmp_path, process, disable_extractors_dict):
  11. """Test that snapshot command works with URL."""
  12. os.chdir(tmp_path)
  13. # Add a snapshot first
  14. subprocess.run(
  15. ['archivebox', 'add', '--index-only', '--depth=0', 'https://example.com'],
  16. capture_output=True,
  17. env=disable_extractors_dict,
  18. )
  19. # Try to view/interact with snapshot
  20. result = subprocess.run(
  21. ['archivebox', 'snapshot', 'https://example.com'],
  22. capture_output=True,
  23. text=True,
  24. env=disable_extractors_dict,
  25. timeout=30,
  26. )
  27. # Should complete (exit code depends on implementation)
  28. assert result.returncode in [0, 1, 2]
  29. def test_snapshot_command_with_timestamp(tmp_path, process, disable_extractors_dict):
  30. """Test snapshot command with timestamp ID."""
  31. os.chdir(tmp_path)
  32. # Add snapshot
  33. subprocess.run(
  34. ['archivebox', 'add', '--index-only', '--depth=0', 'https://example.com'],
  35. capture_output=True,
  36. env=disable_extractors_dict,
  37. )
  38. # Get snapshot timestamp
  39. conn = sqlite3.connect("index.sqlite3")
  40. c = conn.cursor()
  41. timestamp = c.execute("SELECT timestamp FROM core_snapshot").fetchone()[0]
  42. conn.close()
  43. # Try snapshot command with timestamp
  44. result = subprocess.run(
  45. ['archivebox', 'snapshot', str(timestamp)],
  46. capture_output=True,
  47. env=disable_extractors_dict,
  48. timeout=30,
  49. )
  50. assert result.returncode in [0, 1, 2]