def test_simple_invocation(self, popen, pipe_processor_loop, caplog): ret = 0 out = 'out' err = 'err' pipe = _mock_pipe(popen, pipe_processor_loop, ret, out, err) connection_mock = mock.MagicMock() connection_mock.get_connection_string.return_value = 'fake_connstring' cmd = command_wrappers.PgReceiveXlog(destination='/fake/target', connection=connection_mock, version='9.4', app_name='fake_app_name') result = cmd.execute() popen.assert_called_with([ 'pg_receivexlog', "--dbname=fake_connstring", '--verbose', '--no-loop', "--no-password", '--directory=/fake/target' ], close_fds=True, shell=False, env=None, stdout=PIPE, stderr=PIPE, stdin=PIPE, preexec_fn=mock.ANY) assert not pipe.stdin.write.called pipe.stdin.close.assert_called_once_with() assert result == ret assert cmd.ret == ret assert cmd.out is None assert cmd.err is None assert ('PgReceiveXlog', INFO, out) in caplog.record_tuples assert ('PgReceiveXlog', WARNING, err) in caplog.record_tuples
def test_init_args(self): """ Test class build """ connection_mock = mock.MagicMock() connection_mock.get_connection_string.return_value = 'test_connstring' receivexlog = command_wrappers.PgReceiveXlog( destination='/dest/dir', command='/path/to/pg_receivexlog', connection=connection_mock, version='9.4', args=['a', 'b']) assert receivexlog.args == [ "--dbname=test_connstring", "--verbose", "--no-loop", "--no-password", "--directory=/dest/dir", "a", "b", ] assert receivexlog.cmd == '/path/to/pg_receivexlog' assert receivexlog.check is True assert receivexlog.close_fds is True assert receivexlog.allowed_retval == (0, ) assert receivexlog.err_handler assert receivexlog.out_handler
def test_simple_invocation(self, popen, pipe_processor_loop, caplog): ret = 0 out = 'out' err = 'err' pipe = _mock_pipe(popen, pipe_processor_loop, ret, out, err) cmd = command_wrappers.PgReceiveXlog( host='host', port='1234', user='******') result = cmd.execute() popen.assert_called_with( [ 'pg_receivexlog', '--verbose', '--no-loop', '--directory=None', '--host=host', '--port=1234', '--username=user' ], shell=False, env=None, stdout=PIPE, stderr=PIPE, stdin=PIPE, preexec_fn=mock.ANY, close_fds=True ) assert not pipe.stdin.write.called pipe.stdin.close.assert_called_once_with() assert result == ret assert cmd.ret == ret assert cmd.out is None assert cmd.err is None assert ('PgReceiveXlog', INFO, out) in caplog.record_tuples assert ('PgReceiveXlog', WARNING, err) in caplog.record_tuples
def test_init_simple(self): """ Test class build """ connection_mock = mock.MagicMock() connection_mock.get_connection_string.return_value = 'test_conn' receivexlog = command_wrappers.PgReceiveXlog( destination='/fake/target', command='/usr/bin/pg_receivexlog', connection=connection_mock, version='9.3', app_name='fake_app_name') assert receivexlog.args == [ "--dbname=test_conn", "--verbose", "--no-loop", "--no-password", "--directory=/fake/target" ] assert receivexlog.cmd == '/usr/bin/pg_receivexlog' assert receivexlog.check is True assert receivexlog.close_fds is True assert receivexlog.allowed_retval == (0,) assert receivexlog.err_handler assert receivexlog.out_handler connection_mock.conn_parameters = {'host': 'fake host', 'port': 'fake_port', 'user': '******'} receivexlog = command_wrappers.PgReceiveXlog( destination='/fake/target', command=connection_mock, connection=connection_mock, version='9.2', app_name='fake_app_name') assert receivexlog.args == [ "--host=fake host", "--port=fake_port", "--username=fake_user", "--verbose", "--no-loop", "--no-password", "--directory=/fake/target" ]
def test_init(self): """ Test class build """ receivexlog = command_wrappers.PgReceiveXlog() assert receivexlog.args == [ "--verbose", "--no-loop", "--directory=None" ] assert receivexlog.cmd == 'pg_receivexlog' assert receivexlog.check is True assert receivexlog.close_fds is True assert receivexlog.allowed_retval == (0,) assert receivexlog.debug is False assert receivexlog.err_handler assert receivexlog.out_handler
def test_init_args(self): """ Test class build """ receivexlog = command_wrappers.PgReceiveXlog( '/path/to/pg_receivexlog', conn_string='co=nn str=ing', dest='/dest/dir', args=['a', 'b']) assert receivexlog.args == [ "--verbose", "--no-loop", "--directory=/dest/dir", "--dbname=co=nn str=ing", "a", "b", ] assert receivexlog.cmd == '/path/to/pg_receivexlog' assert receivexlog.check is True assert receivexlog.close_fds is True assert receivexlog.allowed_retval == (0,) assert receivexlog.debug is False assert receivexlog.err_handler assert receivexlog.out_handler