| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 | 
							- import pytest
 
- from flexmock import flexmock
 
- from borgmatic.config import normalize as module
 
- @pytest.mark.parametrize(
 
-     'config,expected_config,produces_logs',
 
-     (
 
-         (
 
-             {'location': {'foo': 'bar', 'baz': 'quux'}},
 
-             {'foo': 'bar', 'baz': 'quux'},
 
-             True,
 
-         ),
 
-         (
 
-             {'retention': {'foo': 'bar', 'baz': 'quux'}},
 
-             {'foo': 'bar', 'baz': 'quux'},
 
-             True,
 
-         ),
 
-         (
 
-             {'consistency': {'foo': 'bar', 'baz': 'quux'}},
 
-             {'foo': 'bar', 'baz': 'quux'},
 
-             True,
 
-         ),
 
-         (
 
-             {'output': {'foo': 'bar', 'baz': 'quux'}},
 
-             {'foo': 'bar', 'baz': 'quux'},
 
-             True,
 
-         ),
 
-         (
 
-             {'hooks': {'foo': 'bar', 'baz': 'quux'}},
 
-             {'foo': 'bar', 'baz': 'quux'},
 
-             True,
 
-         ),
 
-         (
 
-             {'location': {'foo': 'bar'}, 'storage': {'baz': 'quux'}},
 
-             {'foo': 'bar', 'baz': 'quux'},
 
-             True,
 
-         ),
 
-         (
 
-             {'foo': 'bar', 'baz': 'quux'},
 
-             {'foo': 'bar', 'baz': 'quux'},
 
-             False,
 
-         ),
 
-         (
 
-             {'location': {'prefix': 'foo'}, 'consistency': {'prefix': 'foo'}},
 
-             {'prefix': 'foo'},
 
-             True,
 
-         ),
 
-         (
 
-             {'location': {'prefix': 'foo'}, 'consistency': {'prefix': 'foo'}},
 
-             {'prefix': 'foo'},
 
-             True,
 
-         ),
 
-         (
 
-             {'location': {'prefix': 'foo'}, 'consistency': {'bar': 'baz'}},
 
-             {'prefix': 'foo', 'bar': 'baz'},
 
-             True,
 
-         ),
 
-         (
 
-             {'storage': {'umask': 'foo'}, 'hooks': {'umask': 'foo'}},
 
-             {'umask': 'foo'},
 
-             True,
 
-         ),
 
-         (
 
-             {'storage': {'umask': 'foo'}, 'hooks': {'umask': 'foo'}},
 
-             {'umask': 'foo'},
 
-             True,
 
-         ),
 
-         (
 
-             {'storage': {'umask': 'foo'}, 'hooks': {'bar': 'baz'}},
 
-             {'umask': 'foo', 'bar': 'baz'},
 
-             True,
 
-         ),
 
-         (
 
-             {'location': {'bar': 'baz'}, 'consistency': {'prefix': 'foo'}},
 
-             {'bar': 'baz', 'prefix': 'foo'},
 
-             True,
 
-         ),
 
-         (
 
-             {'location': {}, 'consistency': {'prefix': 'foo'}},
 
-             {'prefix': 'foo'},
 
-             True,
 
-         ),
 
-         (
 
-             {},
 
-             {},
 
-             False,
 
-         ),
 
-     ),
 
- )
 
- def test_normalize_sections_moves_section_options_to_global_scope(
 
-     config, expected_config, produces_logs
 
- ):
 
-     logs = module.normalize_sections('test.yaml', config)
 
-     assert config == expected_config
 
-     if produces_logs:
 
-         assert logs
 
-     else:
 
-         assert logs == []
 
- def test_normalize_sections_with_different_prefix_values_raises():
 
-     config = {'location': {'prefix': 'foo'}, 'consistency': {'prefix': 'bar'}}
 
-     with pytest.raises(ValueError):
 
-         module.normalize_sections('test.yaml', config)
 
- def test_normalize_sections_with_different_umask_values_raises():
 
-     config = {'storage': {'umask': 'foo'}, 'hooks': {'umask': 'bar'}}
 
-     with pytest.raises(ValueError):
 
-         module.normalize_sections('test.yaml', config)
 
- def test_normalize_sections_with_only_scalar_raises():
 
-     config = 33
 
-     with pytest.raises(ValueError):
 
-         module.normalize_sections('test.yaml', config)
 
- @pytest.mark.parametrize(
 
-     'config,expected_config,produces_logs',
 
-     (
 
-         (
 
-             {'exclude_if_present': '.nobackup'},
 
-             {'exclude_if_present': ['.nobackup']},
 
-             True,
 
-         ),
 
-         (
 
-             {'exclude_if_present': ['.nobackup']},
 
-             {'exclude_if_present': ['.nobackup']},
 
-             False,
 
-         ),
 
-         (
 
-             {'source_directories': ['foo', 'bar']},
 
-             {'source_directories': ['foo', 'bar']},
 
-             False,
 
-         ),
 
-         (
 
-             {'compression': 'yes_please'},
 
-             {'compression': 'yes_please'},
 
-             False,
 
-         ),
 
-         (
 
-             {'healthchecks': 'https://example.com'},
 
-             {'healthchecks': {'ping_url': 'https://example.com'}},
 
-             True,
 
-         ),
 
-         (
 
-             {'cronitor': 'https://example.com'},
 
-             {'cronitor': {'ping_url': 'https://example.com'}},
 
-             True,
 
-         ),
 
-         (
 
-             {'pagerduty': 'https://example.com'},
 
-             {'pagerduty': {'integration_key': 'https://example.com'}},
 
-             True,
 
-         ),
 
-         (
 
-             {'cronhub': 'https://example.com'},
 
-             {'cronhub': {'ping_url': 'https://example.com'}},
 
-             True,
 
-         ),
 
-         (
 
-             {'checks': ['archives']},
 
-             {'checks': [{'name': 'archives'}]},
 
-             True,
 
-         ),
 
-         (
 
-             {'checks': ['archives']},
 
-             {'checks': [{'name': 'archives'}]},
 
-             True,
 
-         ),
 
-         (
 
-             {'numeric_owner': False},
 
-             {'numeric_ids': False},
 
-             True,
 
-         ),
 
-         (
 
-             {'bsd_flags': False},
 
-             {'flags': False},
 
-             True,
 
-         ),
 
-         (
 
-             {'remote_rate_limit': False},
 
-             {'upload_rate_limit': False},
 
-             True,
 
-         ),
 
-         (
 
-             {'repositories': ['foo@bar:/repo']},
 
-             {'repositories': [{'path': 'ssh://foo@bar/repo'}]},
 
-             True,
 
-         ),
 
-         (
 
-             {'repositories': ['foo@bar:repo']},
 
-             {'repositories': [{'path': 'ssh://foo@bar/./repo'}]},
 
-             True,
 
-         ),
 
-         (
 
-             {'repositories': ['foo@bar:~/repo']},
 
-             {'repositories': [{'path': 'ssh://foo@bar/~/repo'}]},
 
-             True,
 
-         ),
 
-         (
 
-             {'repositories': ['ssh://foo@bar:1234/repo']},
 
-             {'repositories': [{'path': 'ssh://foo@bar:1234/repo'}]},
 
-             True,
 
-         ),
 
-         (
 
-             {'repositories': ['file:///repo']},
 
-             {'repositories': [{'path': '/repo'}]},
 
-             True,
 
-         ),
 
-         (
 
-             {'repositories': [{'path': 'first'}, 'file:///repo']},
 
-             {'repositories': [{'path': 'first'}, {'path': '/repo'}]},
 
-             True,
 
-         ),
 
-         (
 
-             {'repositories': [{'path': 'foo@bar:/repo', 'label': 'foo'}]},
 
-             {'repositories': [{'path': 'ssh://foo@bar/repo', 'label': 'foo'}]},
 
-             True,
 
-         ),
 
-         (
 
-             {'repositories': [{'path': 'file:///repo', 'label': 'foo'}]},
 
-             {'repositories': [{'path': '/repo', 'label': 'foo'}]},
 
-             False,
 
-         ),
 
-         (
 
-             {'repositories': [{'path': '/repo', 'label': 'foo'}]},
 
-             {'repositories': [{'path': '/repo', 'label': 'foo'}]},
 
-             False,
 
-         ),
 
-         (
 
-             {'prefix': 'foo'},
 
-             {'prefix': 'foo'},
 
-             True,
 
-         ),
 
-     ),
 
- )
 
- def test_normalize_applies_hard_coded_normalization_to_config(
 
-     config, expected_config, produces_logs
 
- ):
 
-     flexmock(module).should_receive('normalize_sections').and_return([])
 
-     logs = module.normalize('test.yaml', config)
 
-     assert config == expected_config
 
-     if produces_logs:
 
-         assert logs
 
-     else:
 
-         assert logs == []
 
 
  |