test_install.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/usr/bin/env python3
  2. """Integration tests for archivebox install command."""
  3. import os
  4. import subprocess
  5. import sqlite3
  6. import pytest
  7. from .fixtures import process, disable_extractors_dict
  8. class TestInstallDryRun:
  9. """Test the dry-run mode of install command."""
  10. def test_dry_run_prints_message(self, tmp_path, process):
  11. """Test that dry-run mode prints appropriate message."""
  12. os.chdir(tmp_path)
  13. result = subprocess.run(
  14. ['archivebox', 'install', '--dry-run'],
  15. capture_output=True,
  16. text=True,
  17. )
  18. assert result.returncode == 0
  19. assert 'Dry run' in result.stdout
  20. def test_dry_run_does_not_create_crawl(self, tmp_path, process):
  21. """Test that dry-run mode doesn't create a crawl."""
  22. os.chdir(tmp_path)
  23. # Get initial crawl count
  24. conn = sqlite3.connect('index.sqlite3')
  25. c = conn.cursor()
  26. c.execute("SELECT COUNT(*) FROM crawls_crawl")
  27. initial_count = c.fetchone()[0]
  28. conn.close()
  29. # Run install with dry-run
  30. result = subprocess.run(
  31. ['archivebox', 'install', '--dry-run'],
  32. capture_output=True,
  33. text=True,
  34. )
  35. assert result.returncode == 0
  36. # Check crawl count unchanged
  37. conn = sqlite3.connect('index.sqlite3')
  38. c = conn.cursor()
  39. c.execute("SELECT COUNT(*) FROM crawls_crawl")
  40. final_count = c.fetchone()[0]
  41. conn.close()
  42. assert final_count == initial_count
  43. class TestInstallOutput:
  44. """Test the output/messages from install command."""
  45. def test_install_prints_detecting_message(self, tmp_path, process, disable_extractors_dict):
  46. """Test that install prints detecting dependencies message."""
  47. os.chdir(tmp_path)
  48. result = subprocess.run(
  49. ['archivebox', 'install', '--dry-run'],
  50. capture_output=True,
  51. text=True,
  52. env=disable_extractors_dict,
  53. )
  54. assert result.returncode == 0
  55. # Should mention detecting or dependencies
  56. output = result.stdout.lower()
  57. assert 'detect' in output or 'dependenc' in output or 'dry run' in output
  58. class TestInstallCLI:
  59. """Test the CLI interface for install command."""
  60. def test_cli_help(self, tmp_path):
  61. """Test that --help works for install command."""
  62. os.chdir(tmp_path)
  63. result = subprocess.run(
  64. ['archivebox', 'install', '--help'],
  65. capture_output=True,
  66. text=True,
  67. )
  68. assert result.returncode == 0
  69. assert '--dry-run' in result.stdout or '-d' in result.stdout
  70. def test_cli_invalid_option(self, tmp_path):
  71. """Test that invalid options are handled."""
  72. os.chdir(tmp_path)
  73. result = subprocess.run(
  74. ['archivebox', 'install', '--invalid-option'],
  75. capture_output=True,
  76. text=True,
  77. )
  78. # Should fail with non-zero exit code
  79. assert result.returncode != 0
  80. class TestInstallInitialization:
  81. """Test that install initializes the data directory if needed."""
  82. def test_install_from_empty_dir(self, tmp_path):
  83. """Test that install from empty dir initializes first."""
  84. os.chdir(tmp_path)
  85. # Don't use process fixture - start from empty dir
  86. result = subprocess.run(
  87. ['archivebox', 'install', '--dry-run'],
  88. capture_output=True,
  89. text=True,
  90. )
  91. # Should either initialize or show dry run message
  92. output = result.stdout
  93. assert 'Initializing' in output or 'Dry run' in output or 'init' in output.lower()
  94. if __name__ == '__main__':
  95. pytest.main([__file__, '-v'])