test_config.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/usr/bin/env python3
  2. """Integration tests for archivebox config command."""
  3. import os
  4. import subprocess
  5. import pytest
  6. from .fixtures import process, disable_extractors_dict
  7. def test_config_shows_all_config_values(tmp_path, process):
  8. """Test that config without args shows all config values."""
  9. os.chdir(tmp_path)
  10. result = subprocess.run(
  11. ['archivebox', 'config'],
  12. capture_output=True,
  13. text=True,
  14. )
  15. # Should show various config sections
  16. assert 'TIMEOUT' in result.stdout or 'timeout' in result.stdout.lower()
  17. # Config should show some output
  18. assert len(result.stdout) > 100
  19. def test_config_get_specific_key(tmp_path, process):
  20. """Test that --get retrieves a specific config value."""
  21. os.chdir(tmp_path)
  22. result = subprocess.run(
  23. ['archivebox', 'config', '--get', 'TIMEOUT'],
  24. capture_output=True,
  25. text=True,
  26. )
  27. # Should show the TIMEOUT value
  28. assert 'TIMEOUT' in result.stdout or result.returncode == 0
  29. def test_config_set_value_writes_to_config_file(tmp_path, process):
  30. """Test that --set writes config value to ArchiveBox.conf file."""
  31. os.chdir(tmp_path)
  32. # Set a config value
  33. result = subprocess.run(
  34. ['archivebox', 'config', '--set', 'TIMEOUT=120'],
  35. capture_output=True,
  36. text=True,
  37. )
  38. # Read the config file directly to verify it was written
  39. config_file = tmp_path / 'ArchiveBox.conf'
  40. if config_file.exists():
  41. config_content = config_file.read_text()
  42. # Config should contain the set value
  43. assert 'TIMEOUT' in config_content or 'timeout' in config_content.lower()
  44. def test_config_set_and_get_roundtrip(tmp_path, process):
  45. """Test that a value set with --set can be retrieved with --get."""
  46. os.chdir(tmp_path)
  47. # Set a value
  48. set_result = subprocess.run(
  49. ['archivebox', 'config', '--set', 'TIMEOUT=999'],
  50. capture_output=True,
  51. text=True,
  52. )
  53. # Verify set was successful
  54. assert set_result.returncode == 0 or '999' in set_result.stdout
  55. # Read the config file directly to verify
  56. config_file = tmp_path / 'ArchiveBox.conf'
  57. if config_file.exists():
  58. config_content = config_file.read_text()
  59. assert '999' in config_content or 'TIMEOUT' in config_content
  60. def test_config_search_finds_matching_keys(tmp_path, process):
  61. """Test that --search finds config keys matching a pattern."""
  62. os.chdir(tmp_path)
  63. result = subprocess.run(
  64. ['archivebox', 'config', '--search', 'TIMEOUT'],
  65. capture_output=True,
  66. text=True,
  67. )
  68. # Should find TIMEOUT-related config
  69. assert 'TIMEOUT' in result.stdout or result.returncode == 0
  70. def test_config_invalid_key_fails(tmp_path, process):
  71. """Test that setting an invalid config key fails."""
  72. os.chdir(tmp_path)
  73. result = subprocess.run(
  74. ['archivebox', 'config', '--set', 'INVALID_KEY_THAT_DOES_NOT_EXIST=value'],
  75. capture_output=True,
  76. text=True,
  77. )
  78. # Should fail
  79. assert result.returncode != 0 or 'failed' in result.stdout.lower()
  80. def test_config_set_requires_equals_sign(tmp_path, process):
  81. """Test that --set requires KEY=VALUE format."""
  82. os.chdir(tmp_path)
  83. result = subprocess.run(
  84. ['archivebox', 'config', '--set', 'TIMEOUT'],
  85. capture_output=True,
  86. text=True,
  87. )
  88. # Should fail because there's no = sign
  89. assert result.returncode != 0
  90. class TestConfigCLI:
  91. """Test the CLI interface for config command."""
  92. def test_cli_help(self, tmp_path, process):
  93. """Test that --help works for config command."""
  94. os.chdir(tmp_path)
  95. result = subprocess.run(
  96. ['archivebox', 'config', '--help'],
  97. capture_output=True,
  98. text=True,
  99. )
  100. assert result.returncode == 0
  101. assert '--get' in result.stdout
  102. assert '--set' in result.stdout
  103. if __name__ == '__main__':
  104. pytest.main([__file__, '-v'])