test_create.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. from flexmock import flexmock
  2. from borgmatic.actions import create as module
  3. def test_run_create_executes_and_calls_hooks_for_configured_repository():
  4. flexmock(module.logger).answer = lambda message: None
  5. flexmock(module.borgmatic.config.validate).should_receive('repositories_match').never()
  6. flexmock(module.borgmatic.borg.create).should_receive('create_archive').once()
  7. flexmock(module.borgmatic.hooks.command).should_receive('execute_hook').times(2)
  8. flexmock(module.borgmatic.hooks.dispatch).should_receive('call_hooks').and_return({})
  9. flexmock(module.borgmatic.hooks.dispatch).should_receive(
  10. 'call_hooks_even_if_unconfigured'
  11. ).and_return({})
  12. create_arguments = flexmock(
  13. repository=None,
  14. progress=flexmock(),
  15. stats=flexmock(),
  16. json=flexmock(),
  17. list_files=flexmock(),
  18. )
  19. global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
  20. list(
  21. module.run_create(
  22. config_filename='test.yaml',
  23. repository={'path': 'repo'},
  24. location={},
  25. storage={},
  26. hooks={},
  27. hook_context={},
  28. local_borg_version=None,
  29. create_arguments=create_arguments,
  30. global_arguments=global_arguments,
  31. dry_run_label='',
  32. local_path=None,
  33. remote_path=None,
  34. )
  35. )
  36. def test_run_create_runs_with_selected_repository():
  37. flexmock(module.logger).answer = lambda message: None
  38. flexmock(module.borgmatic.config.validate).should_receive(
  39. 'repositories_match'
  40. ).once().and_return(True)
  41. flexmock(module.borgmatic.borg.create).should_receive('create_archive').once()
  42. create_arguments = flexmock(
  43. repository=flexmock(),
  44. progress=flexmock(),
  45. stats=flexmock(),
  46. json=flexmock(),
  47. list_files=flexmock(),
  48. )
  49. global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
  50. list(
  51. module.run_create(
  52. config_filename='test.yaml',
  53. repository={'path': 'repo'},
  54. location={},
  55. storage={},
  56. hooks={},
  57. hook_context={},
  58. local_borg_version=None,
  59. create_arguments=create_arguments,
  60. global_arguments=global_arguments,
  61. dry_run_label='',
  62. local_path=None,
  63. remote_path=None,
  64. )
  65. )
  66. def test_run_create_bails_if_repository_does_not_match():
  67. flexmock(module.logger).answer = lambda message: None
  68. flexmock(module.borgmatic.config.validate).should_receive(
  69. 'repositories_match'
  70. ).once().and_return(False)
  71. flexmock(module.borgmatic.borg.create).should_receive('create_archive').never()
  72. create_arguments = flexmock(
  73. repository=flexmock(),
  74. progress=flexmock(),
  75. stats=flexmock(),
  76. json=flexmock(),
  77. list_files=flexmock(),
  78. )
  79. global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
  80. list(
  81. module.run_create(
  82. config_filename='test.yaml',
  83. repository='repo',
  84. location={},
  85. storage={},
  86. hooks={},
  87. hook_context={},
  88. local_borg_version=None,
  89. create_arguments=create_arguments,
  90. global_arguments=global_arguments,
  91. dry_run_label='',
  92. local_path=None,
  93. remote_path=None,
  94. )
  95. )