test_oneshot.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from pathlib import Path
  2. from .fixtures import *
  3. def test_oneshot_command_exists(tmp_path, disable_extractors_dict):
  4. os.chdir(tmp_path)
  5. process = subprocess.run(['archivebox', 'oneshot'], capture_output=True, env=disable_extractors_dict)
  6. assert not "invalid choice: 'oneshot'" in process.stderr.decode("utf-8")
  7. def test_oneshot_command_saves_page_in_right_folder(tmp_path, disable_extractors_dict):
  8. disable_extractors_dict.update({"SAVE_DOM": "true"})
  9. process = subprocess.run(
  10. [
  11. "archivebox",
  12. "oneshot",
  13. f"--out-dir={tmp_path}",
  14. "--extract=title,favicon,dom",
  15. "http://127.0.0.1:8080/static/example.com.html",
  16. ],
  17. capture_output=True,
  18. env=disable_extractors_dict,
  19. )
  20. items = ' '.join([str(x) for x in tmp_path.iterdir()])
  21. current_path = ' '.join([str(x) for x in Path.cwd().iterdir()])
  22. assert "index.json" in items
  23. assert not "index.sqlite3" in current_path
  24. assert "output.html" in items
  25. def test_oneshot_command_succeeds(tmp_path, disable_extractors_dict):
  26. disable_extractors_dict.update({"SAVE_DOM": "true"})
  27. process = subprocess.run(
  28. [
  29. "archivebox",
  30. "oneshot",
  31. f"--out-dir={tmp_path}",
  32. "--extract=title,favicon,dom",
  33. "http://127.0.0.1:8080/static/example.com.html",
  34. ],
  35. capture_output=True,
  36. env=disable_extractors_dict,
  37. )
  38. assert process.returncode == 0
  39. def test_oneshot_command_logs_archiving_finished(tmp_path, disable_extractors_dict):
  40. disable_extractors_dict.update({"SAVE_DOM": "true"})
  41. process = subprocess.run(
  42. [
  43. "archivebox",
  44. "oneshot",
  45. f"--out-dir={tmp_path}",
  46. "--extract=title,favicon,dom",
  47. "http://127.0.0.1:8080/static/example.com.html",
  48. ],
  49. capture_output=True,
  50. env=disable_extractors_dict,
  51. )
  52. output_str = process.stdout.decode("utf-8")
  53. assert "4 files" in output_str