2
0

test_recreate.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import pytest
  2. from flexmock import flexmock
  3. from borgmatic.actions import recreate as module
  4. def test_run_recreate_does_not_raise():
  5. flexmock(module.logger).answer = lambda message: None
  6. flexmock(module.borgmatic.config.validate).should_receive('repositories_match').and_return(True)
  7. flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(
  8. flexmock()
  9. )
  10. flexmock(module.borgmatic.borg.repo_list).should_receive('resolve_archive_name').and_return(
  11. None
  12. )
  13. flexmock(module.borgmatic.borg.recreate).should_receive('recreate_archive')
  14. module.run_recreate(
  15. repository={'path': 'repo'},
  16. config={},
  17. local_borg_version=None,
  18. recreate_arguments=flexmock(repository=flexmock(), archive=None),
  19. global_arguments=flexmock(),
  20. local_path=None,
  21. remote_path=None,
  22. )
  23. def test_run_recreate_with_archive_does_not_raise():
  24. flexmock(module.logger).answer = lambda message: None
  25. flexmock(module.borgmatic.config.validate).should_receive('repositories_match').and_return(True)
  26. flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(
  27. flexmock()
  28. )
  29. flexmock(module.borgmatic.borg.repo_list).should_receive('resolve_archive_name').and_return(
  30. 'test-archive'
  31. )
  32. flexmock(module.borgmatic.borg.recreate).should_receive('recreate_archive')
  33. module.run_recreate(
  34. repository={'path': 'repo'},
  35. config={},
  36. local_borg_version=None,
  37. recreate_arguments=flexmock(repository=flexmock(), archive='test-archive'),
  38. global_arguments=flexmock(),
  39. local_path=None,
  40. remote_path=None,
  41. )
  42. def test_run_recreate_with_leftover_recreate_archive_raises():
  43. flexmock(module.logger).answer = lambda message: None
  44. flexmock(module.borgmatic.config.validate).should_receive('repositories_match').and_return(True)
  45. flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(
  46. flexmock()
  47. )
  48. flexmock(module.borgmatic.borg.repo_list).should_receive('resolve_archive_name').and_return(
  49. 'test-archive.recreate'
  50. )
  51. flexmock(module.borgmatic.borg.recreate).should_receive('recreate_archive')
  52. with pytest.raises(ValueError):
  53. module.run_recreate(
  54. repository={'path': 'repo'},
  55. config={},
  56. local_borg_version=None,
  57. recreate_arguments=flexmock(repository=flexmock(), archive='test-archive.recreate'),
  58. global_arguments=flexmock(),
  59. local_path=None,
  60. remote_path=None,
  61. )
  62. def test_run_recreate_with_latest_archive_resolving_to_leftover_recreate_archive_raises():
  63. flexmock(module.logger).answer = lambda message: None
  64. flexmock(module.borgmatic.config.validate).should_receive('repositories_match').and_return(True)
  65. flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(
  66. flexmock()
  67. )
  68. flexmock(module.borgmatic.borg.repo_list).should_receive('resolve_archive_name').and_return(
  69. 'test-archive.recreate'
  70. )
  71. flexmock(module.borgmatic.borg.recreate).should_receive('recreate_archive')
  72. with pytest.raises(ValueError):
  73. module.run_recreate(
  74. repository={'path': 'repo'},
  75. config={},
  76. local_borg_version=None,
  77. recreate_arguments=flexmock(repository=flexmock(), archive='latest'),
  78. global_arguments=flexmock(),
  79. local_path=None,
  80. remote_path=None,
  81. )