def test_get_server_with_conflicts(self, monkeypatch, capsys): """ Test get_server method using a configuration containing errors :param monkeypatch monkeypatch: pytest patcher """ # Mock the args from argparse args = Mock() # conflicting directories monkeypatch.setattr(barman, '__config__', build_config_from_dicts( main_conf={ 'wals_directory': '/some/barman/home/main/wals', 'basebackups_directory': '/some/barman/home/main/wals', })) args.server_name = 'main' with pytest.raises(SystemExit): get_server(args, True) out, err = capsys.readouterr() assert err assert "ERROR: Conflicting path:" in err # conflicting directories with on_error_stop=False monkeypatch.setattr(barman, '__config__', build_config_from_dicts( main_conf={ 'wals_directory': '/some/barman/home/main/wals', 'basebackups_directory': '/some/barman/home/main/wals', })) args.server_name = 'main' get_server(args, on_error_stop=False) # In this case the server is returned and a warning message is emitted out, err = capsys.readouterr() assert err assert "ERROR: Conflicting path:" in err
def test_get_server_global_error_list(self, monkeypatch, capsys): """ Test the management of multiple servers and the presence of global errors :param monkeypatch monkeypatch: pytest patcher """ args = Mock() args.server_name = "main" # Build 2 servers with shared path. monkeypatch.setattr( barman, "__config__", build_config_from_dicts( global_conf=None, main_conf={ "basebackups_directory": "/some/barman/home/main/base", "incoming_wals_directory": "/some/barman/home/main/incoming", "wals_directory": "/some/barman/home/main/wals", "backup_directory": "/some/barman/home/main", "archiver": "on", }, test_conf={ "basebackups_directory": "/some/barman/home/test/wals", "incoming_wals_directory": "/some/barman/home/main/incoming", "wals_directory": "/some/barman/home/main/wals", "backup_directory": "/some/barman/home/main", "archiver": "on", }, ), ) # Expect a conflict because of the shared paths with pytest.raises(SystemExit): get_server(args) out, err = capsys.readouterr() # Check for the presence of error messages assert err # Check paths in error messages assert ( "Conflicting path: " "basebackups_directory=/some/barman/home/main/base" in err ) assert ( "Conflicting path: " "incoming_wals_directory=/some/barman/home/main/incoming" in err ) assert "Conflicting path: wals_directory=/some/barman/home/main/wals" in err assert "Conflicting path: backup_directory=/some/barman/home/main" in err
def test_get_server_global_error_list(self, monkeypatch, capsys): """ Test the management of multiple servers and the presence of global errors :param monkeypatch monkeypatch: pytest patcher """ args = Mock() args.server_name = 'main' # Build 2 servers with shared path. monkeypatch.setattr( barman, '__config__', build_config_from_dicts( global_conf=None, main_conf={ 'basebackups_directory': '/some/barman/home/main/base', 'incoming_wals_directory': '/some/barman/home/main/incoming', 'wals_directory': '/some/barman/home/main/wals', 'backup_directory': '/some/barman/home/main', 'archiver': 'on', }, test_conf={ 'basebackups_directory': '/some/barman/home/test/wals', 'incoming_wals_directory': '/some/barman/home/main/incoming', 'wals_directory': '/some/barman/home/main/wals', 'backup_directory': '/some/barman/home/main', 'archiver': 'on', })) # Expect a conflict because of the shared paths with pytest.raises(SystemExit): get_server(args) out, err = capsys.readouterr() # Check for the presence of error messages assert err # Check paths in error messages assert 'Conflicting path: ' \ 'basebackups_directory=/some/barman/home/main/base' in err assert 'Conflicting path: ' \ 'incoming_wals_directory=/some/barman/home/main/incoming' in err assert 'Conflicting path: ' \ 'wals_directory=/some/barman/home/main/wals' in err assert 'Conflicting path: ' \ 'backup_directory=/some/barman/home/main' in err
def test_get_server_global_error_list(self, monkeypatch, capsys): """ Test the management of multiple servers and the presence of global errors :param monkeypatch monkeypatch: pytest patcher """ args = Mock() args.server_name = 'main' # Build 2 servers with shared path. monkeypatch.setattr(barman, '__config__', build_config_from_dicts( global_conf=None, main_conf={ 'basebackups_directory': '/some/barman/home/main/base', 'incoming_wals_directory': '/some/barman/home/main/incoming', 'wals_directory': '/some/barman/home/main/wals', 'backup_directory': '/some/barman/home/main', 'archiver': 'on', }, test_conf={ 'basebackups_directory': '/some/barman/home/test/wals', 'incoming_wals_directory': '/some/barman/home/main/incoming', 'wals_directory': '/some/barman/home/main/wals', 'backup_directory': '/some/barman/home/main', 'archiver': 'on', })) # Expect a conflict because of the shared paths with pytest.raises(SystemExit): get_server(args) out, err = capsys.readouterr() # Check for the presence of error messages assert err # Check paths in error messages assert 'Conflicting path: ' \ 'basebackups_directory=/some/barman/home/main/base' in err assert 'Conflicting path: ' \ 'incoming_wals_directory=/some/barman/home/main/incoming' in err assert 'Conflicting path: ' \ 'wals_directory=/some/barman/home/main/wals' in err assert 'Conflicting path: ' \ 'backup_directory=/some/barman/home/main' in err
def test_get_server(self, monkeypatch): """ Test the get_server method, providing a basic configuration :param monkeypatch monkeypatch: pytest patcher """ # Mock the args from argparse args = Mock() args.server_name = 'main' monkeypatch.setattr(barman, '__config__', build_config_from_dicts()) server_main = get_server(args) # Expect the server to exists assert server_main # Expect the name to be the right one assert server_main.config.name == 'main'