Пример #1
0
def test_no_telnet():
    parser = setup_parser()
    args = parser.parse_args(['backdoor', '0'])
    with patch('nameko.cli.backdoor.os') as mock_os:
        mock_os.system.return_value = -1
        with pytest.raises(CommandError) as exc:
            main(args)
    assert 'Could not find an installed telnet' in str(exc)
Пример #2
0
def test_stop(running_backdoor):
    _, port = running_backdoor
    parser = setup_parser()
    args = parser.parse_args(['backdoor', str(port)])
    with patch.multiple(
        'nameko.cli.backdoor', call=DEFAULT, os=DEFAULT
    ) as mocks:
        # choose telnet (skip nc and netcat) and find rlwrap
        mocks['os'].system.side_effect = [-1, -1, 0, 0]
        mocks['call'].side_effect = [KeyboardInterrupt, 0]
        main(args)
Пример #3
0
def test_no_running_backdoor():
    parser = setup_parser()
    args = parser.parse_args(['backdoor', '0'])
    with patch.multiple(
        'nameko.cli.backdoor', call=DEFAULT, os=DEFAULT
    ) as mocks:
        mocks['os'].system.return_value = 0
        mocks['call'].return_value = -1
        with pytest.raises(CommandError) as exc:
            main(args)
    assert 'Backdoor unreachable' in str(exc)
Пример #4
0
def test_default_host(running_backdoor):
    _, port = running_backdoor
    parser = setup_parser()
    args = parser.parse_args(['backdoor', str(port)])
    with patch.multiple(
        'nameko.cli.backdoor', call=DEFAULT, os=DEFAULT
    ) as mocks:
        mock_call = mocks['call']
        mocks['os'].system.return_value = 0
        mock_call.return_value = 0
        main(args)
    (cmd, ), _ = mock_call.call_args
    expected = ['rlwrap', 'netcat', 'localhost'] + [str(port)] + ['--close']
    assert cmd == expected
Пример #5
0
def test_basic(running_backdoor):
    socket_arg = '{}:{}'.format(*running_backdoor)
    parser = setup_parser()
    args = parser.parse_args(['backdoor', socket_arg])
    with patch.multiple(
        'nameko.cli.backdoor', call=DEFAULT, os=DEFAULT
    ) as mocks:
        mock_call = mocks['call']
        mocks['os'].system.return_value = 0
        mock_call.return_value = 0
        main(args)
    (cmd, ), _ = mock_call.call_args
    expected = (
        ['rlwrap', 'netcat'] +
        list(map(str, running_backdoor)) +
        ['--close']
    )
    assert cmd == expected