test_status.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #!/usr/bin/env python3
  2. """Integration tests for archivebox status command."""
  3. import os
  4. import subprocess
  5. import sqlite3
  6. import pytest
  7. from .fixtures import process, disable_extractors_dict
  8. def test_status_shows_index_info(tmp_path, process):
  9. """Test that status shows index information."""
  10. os.chdir(tmp_path)
  11. result = subprocess.run(
  12. ['archivebox', 'status'],
  13. capture_output=True,
  14. text=True,
  15. )
  16. # Should show index scanning info
  17. assert 'index' in result.stdout.lower() or 'Index' in result.stdout
  18. def test_status_shows_snapshot_count(tmp_path, process, disable_extractors_dict):
  19. """Test that status shows snapshot count."""
  20. os.chdir(tmp_path)
  21. # Add some snapshots
  22. subprocess.run(
  23. ['archivebox', 'add', '--index-only', 'https://example.com'],
  24. capture_output=True,
  25. env=disable_extractors_dict,
  26. )
  27. subprocess.run(
  28. ['archivebox', 'add', '--index-only', 'https://iana.org'],
  29. capture_output=True,
  30. env=disable_extractors_dict,
  31. )
  32. result = subprocess.run(
  33. ['archivebox', 'status'],
  34. capture_output=True,
  35. text=True,
  36. )
  37. # Should show link/snapshot count
  38. assert '2' in result.stdout or 'links' in result.stdout.lower()
  39. def test_status_shows_archive_size(tmp_path, process, disable_extractors_dict):
  40. """Test that status shows archive size information."""
  41. os.chdir(tmp_path)
  42. subprocess.run(
  43. ['archivebox', 'add', '--index-only', 'https://example.com'],
  44. capture_output=True,
  45. env=disable_extractors_dict,
  46. )
  47. result = subprocess.run(
  48. ['archivebox', 'status'],
  49. capture_output=True,
  50. text=True,
  51. )
  52. # Should show size info (bytes, KB, MB, etc)
  53. assert 'Size' in result.stdout or 'size' in result.stdout or 'B' in result.stdout
  54. def test_status_shows_indexed_count(tmp_path, process, disable_extractors_dict):
  55. """Test that status shows indexed folder count."""
  56. os.chdir(tmp_path)
  57. subprocess.run(
  58. ['archivebox', 'add', '--index-only', 'https://example.com'],
  59. capture_output=True,
  60. env=disable_extractors_dict,
  61. )
  62. result = subprocess.run(
  63. ['archivebox', 'status'],
  64. capture_output=True,
  65. text=True,
  66. )
  67. # Should show indexed count
  68. assert 'indexed' in result.stdout.lower()
  69. def test_status_shows_archived_vs_unarchived(tmp_path, process, disable_extractors_dict):
  70. """Test that status shows archived vs unarchived counts."""
  71. os.chdir(tmp_path)
  72. # Add index-only snapshot (unarchived)
  73. subprocess.run(
  74. ['archivebox', 'add', '--index-only', 'https://example.com'],
  75. capture_output=True,
  76. env=disable_extractors_dict,
  77. )
  78. result = subprocess.run(
  79. ['archivebox', 'status'],
  80. capture_output=True,
  81. text=True,
  82. )
  83. # Should show archived/unarchived categories
  84. assert 'archived' in result.stdout.lower() or 'unarchived' in result.stdout.lower()
  85. def test_status_shows_data_directory_info(tmp_path, process):
  86. """Test that status shows data directory path."""
  87. os.chdir(tmp_path)
  88. result = subprocess.run(
  89. ['archivebox', 'status'],
  90. capture_output=True,
  91. text=True,
  92. )
  93. # Should show data directory or archive path
  94. assert 'archive' in result.stdout.lower() or str(tmp_path) in result.stdout
  95. def test_status_shows_user_info(tmp_path, process):
  96. """Test that status shows user information."""
  97. os.chdir(tmp_path)
  98. result = subprocess.run(
  99. ['archivebox', 'status'],
  100. capture_output=True,
  101. text=True,
  102. )
  103. # Should show user info section
  104. assert 'user' in result.stdout.lower() or 'login' in result.stdout.lower()
  105. def test_status_empty_archive(tmp_path, process):
  106. """Test status on empty archive shows zero counts."""
  107. os.chdir(tmp_path)
  108. result = subprocess.run(
  109. ['archivebox', 'status'],
  110. capture_output=True,
  111. text=True,
  112. )
  113. # Should still run successfully
  114. assert result.returncode == 0 or 'index' in result.stdout.lower()
  115. # Should show 0 links
  116. assert '0' in result.stdout or 'links' in result.stdout.lower()
  117. def test_status_shows_valid_vs_invalid(tmp_path, process, disable_extractors_dict):
  118. """Test that status shows valid vs invalid folder counts."""
  119. os.chdir(tmp_path)
  120. subprocess.run(
  121. ['archivebox', 'add', '--index-only', 'https://example.com'],
  122. capture_output=True,
  123. env=disable_extractors_dict,
  124. )
  125. result = subprocess.run(
  126. ['archivebox', 'status'],
  127. capture_output=True,
  128. text=True,
  129. )
  130. # Should show valid/invalid categories
  131. assert 'valid' in result.stdout.lower() or 'present' in result.stdout.lower()
  132. class TestStatusCLI:
  133. """Test the CLI interface for status command."""
  134. def test_cli_help(self, tmp_path, process):
  135. """Test that --help works for status command."""
  136. os.chdir(tmp_path)
  137. result = subprocess.run(
  138. ['archivebox', 'status', '--help'],
  139. capture_output=True,
  140. text=True,
  141. )
  142. assert result.returncode == 0
  143. # Help should show some info about the command
  144. assert 'status' in result.stdout.lower() or 'statistic' in result.stdout.lower()
  145. if __name__ == '__main__':
  146. pytest.main([__file__, '-v'])