A wrapper script for Borg backup software that creates and prunes backups
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_borgmatic.py 5.3KB

  1. from flexmock import flexmock
  2. import pytest
  3. from borgmatic.commands import borgmatic as module
  4. def test_parse_arguments_with_no_arguments_uses_defaults():
  5. config_paths = ['default']
  6. flexmock(module.collect).should_receive('get_default_config_paths').and_return(config_paths)
  7. parser = module.parse_arguments()
  8. assert parser.config_paths == config_paths
  9. assert parser.excludes_filename is None
  10. assert parser.verbosity is 0
  11. assert parser.json is False
  12. def test_parse_arguments_with_multiple_config_paths_parses_as_list():
  13. flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
  14. parser = module.parse_arguments('--config', 'myconfig', 'otherconfig')
  15. assert parser.config_paths == ['myconfig', 'otherconfig']
  16. assert parser.verbosity is 0
  17. def test_parse_arguments_with_verbosity_overrides_default():
  18. config_paths = ['default']
  19. flexmock(module.collect).should_receive('get_default_config_paths').and_return(config_paths)
  20. parser = module.parse_arguments('--verbosity', '1')
  21. assert parser.config_paths == config_paths
  22. assert parser.excludes_filename is None
  23. assert parser.verbosity == 1
  24. def test_parse_arguments_with_json_overrides_default():
  25. parser = module.parse_arguments('--list', '--json')
  26. assert parser.json is True
  27. def test_parse_arguments_with_no_actions_defaults_to_all_actions_enabled():
  28. flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
  29. parser = module.parse_arguments()
  30. assert parser.prune is True
  31. assert parser.create is True
  32. assert parser.check is True
  33. def test_parse_arguments_with_prune_action_leaves_other_actions_disabled():
  34. flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
  35. parser = module.parse_arguments('--prune')
  36. assert parser.prune is True
  37. assert parser.create is False
  38. assert parser.check is False
  39. def test_parse_arguments_with_multiple_actions_leaves_other_action_disabled():
  40. flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
  41. parser = module.parse_arguments('--create', '--check')
  42. assert parser.prune is False
  43. assert parser.create is True
  44. assert parser.check is True
  45. def test_parse_arguments_with_invalid_arguments_exits():
  46. flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
  47. with pytest.raises(SystemExit):
  48. module.parse_arguments('--posix-me-harder')
  49. def test_parse_arguments_disallows_deprecated_excludes_option():
  50. flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
  51. with pytest.raises(ValueError):
  52. module.parse_arguments('--config', 'myconfig', '--excludes', 'myexcludes')
  53. def test_parse_arguments_disallows_encryption_mode_without_init():
  54. flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
  55. with pytest.raises(ValueError):
  56. module.parse_arguments('--config', 'myconfig', '--encryption', 'repokey')
  57. def test_parse_arguments_requires_encryption_mode_with_init():
  58. flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
  59. with pytest.raises(ValueError):
  60. module.parse_arguments('--config', 'myconfig', '--init')
  61. def test_parse_arguments_disallows_append_only_without_init():
  62. flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
  63. with pytest.raises(ValueError):
  64. module.parse_arguments('--config', 'myconfig', '--append-only')
  65. def test_parse_arguments_disallows_storage_quota_without_init():
  66. flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
  67. with pytest.raises(ValueError):
  68. module.parse_arguments('--config', 'myconfig', '--storage-quota', '5G')
  69. def test_parse_arguments_disallows_init_and_prune():
  70. flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
  71. with pytest.raises(ValueError):
  72. module.parse_arguments('--config', 'myconfig', '--init', '--prune')
  73. def test_parse_arguments_disallows_init_and_create():
  74. flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
  75. with pytest.raises(ValueError):
  76. module.parse_arguments('--config', 'myconfig', '--init', '--create')
  77. def test_parse_arguments_disallows_init_and_dry_run():
  78. flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
  79. with pytest.raises(ValueError):
  80. module.parse_arguments('--config', 'myconfig', '--init', '--dry-run')
  81. def test_parse_arguments_allows_progress_and_create():
  82. module.parse_arguments('--progress', '--create', '--list')
  83. def test_parse_arguments_disallows_progress_without_create():
  84. with pytest.raises(ValueError):
  85. module.parse_arguments('--progress', '--list')
  86. def test_parse_arguments_allows_json_with_list_or_info():
  87. module.parse_arguments('--list', '--json')
  88. module.parse_arguments('--info', '--json')
  89. def test_parse_arguments_disallows_json_without_list_or_info():
  90. with pytest.raises(ValueError):
  91. module.parse_arguments('--json')
  92. def test_parse_arguments_disallows_json_with_both_list_and_info():
  93. with pytest.raises(ValueError):
  94. module.parse_arguments('--list', '--info', '--json')