Exemplo n.º 1
0
 def test_stop_no_pid(self):
     tunnel = Tunnel(
         'server',
         123,
     )
     tunnel.stop()
     assert not tunnel.is_alive()
Exemplo n.º 2
0
 def test_start_exit(self, mock_popen):
     proc = MockProcess(2, 'ssh test')
     mock_popen.return_value = proc
     proc.returncode = 1
     tunnel = Tunnel('host', 5000)
     tunnel.start()
     assert tunnel.pid is None
Exemplo n.º 3
0
 def test_eq(self):
     tunnel = Tunnel('host1', 8080, 8080, pid=1234)
     tunnel2 = Tunnel('host2', 8180, 8180, pid=2345)
     tunnel3 = Tunnel('host1', 8080, 8080, pid=1234)
     assert tunnel == tunnel
     assert tunnel != tunnel2
     assert tunnel != list()
     assert tunnel == tunnel3
Exemplo n.º 4
0
    def test_is_alive(self, mock_process):
        tunnel = Tunnel('server', 123, 456, pid=12345)
        proc = MockProcess(tunnel.pid, "ssh")
        mock_process.return_value = proc

        assert tunnel.is_alive()
        proc.running = False
        assert not tunnel.is_alive()
        proc.running = True
        mock_process.side_effect = psutil.NoSuchProcess(tunnel.pid)
        assert not tunnel.is_alive()
Exemplo n.º 5
0
    def test_start(self, mock_popen, mock_process):
        proc = MockProcess(2, 'ssh')
        mock_popen.return_value = proc
        mock_process.return_value = proc

        tunnel = Tunnel('host', 8080)
        tunnel.start()
        assert tunnel.is_alive()
        mock_popen.assert_called_once_with(
            ['ssh', '-NL', '8080:localhost:8080', 'host'],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        mock_process.assert_called()
Exemplo n.º 6
0
    def test_init(self):
        tunnel = Tunnel('host1', 8000, 8000, name='clown', pid=1234)
        assert tunnel.server == 'host1'
        assert tunnel.remote == 8000
        assert tunnel.local == 8000
        assert tunnel.name == 'clown'
        assert tunnel.pid == 1234

        tunnel2 = Tunnel('host2', 9000)
        assert tunnel2.server == 'host2'
        assert tunnel2.remote == 9000
        assert tunnel2.local == 9000
        assert tunnel2.name == 'localhost'
        assert tunnel2.pid is None
Exemplo n.º 7
0
    def test_stop(self, mock_process):
        tunnel = Tunnel('server', 123, 456, pid=12345)
        proc = MockProcess(tunnel.pid, "ssh")
        mock_process.return_value = proc

        assert tunnel.is_alive()
        tunnel.stop()
        assert proc.terminate_called
        assert not proc.kill_called
        assert not tunnel.is_alive()
Exemplo n.º 8
0
 def test_start_fail(self, mock_popen):
     mock_popen.side_effect = OSError("no such file")
     tunnel = Tunnel('host', 8080)
     tunnel.start()
     assert not tunnel.is_alive()
     assert tunnel.pid is None
Exemplo n.º 9
0
 def test_stop_no_proc(self, mock_process):
     tunnel = Tunnel('server', 123, 456, pid=12345)
     mock_process.side_effect = psutil.NoSuchProcess(tunnel.pid)
     tunnel.stop()
     assert not tunnel.is_alive()