def test_sockets(self): """``dockerpty.pty`` PseudoTerminal 'sockets' proxies to the RunOperation object""" fake_client = MagicMock() fake_run_operation = MagicMock() pty.PseudoTerminal(fake_client, fake_run_operation).sockets() self.assertTrue(fake_run_operation.sockets.called)
def test_init(self): """``dockerpty.pty`` PseudoTerminal init takes the docker client and RunOperation object""" fake_client = MagicMock() fake_run_operation = MagicMock() pterminal = pty.PseudoTerminal(fake_client, fake_run_operation) self.assertTrue(isinstance(pterminal, pty.PseudoTerminal))
def test_resize_ignore_ioerror(self): """``dockerpty.pty`` PseudoTerminal 'resize' ignores IOErrors""" fake_client = MagicMock() fake_run_operation = MagicMock() fake_run_operation.resize.side_effect = IOError('testing') fake_run_operation.israw.return_value = True pty.PseudoTerminal(fake_client, fake_run_operation).resize(size=(300, 400))
def test_resize_israw(self): """``dockerpty.pty`` PseudoTerminal 'resize' doesn't resize anything if the local TTY is raw""" fake_client = MagicMock() fake_run_operation = MagicMock() fake_run_operation.israw.return_value = False pty.PseudoTerminal(fake_client, fake_run_operation).resize(size=(300, 400)) self.assertFalse(fake_run_operation.resize.called)
def test_resize(self): """``dockerpty.pty`` PseudoTerminal 'resize' adjusts the containers PTY""" fake_client = MagicMock() fake_run_operation = MagicMock() fake_run_operation.israw.return_value = True pty.PseudoTerminal(fake_client, fake_run_operation).resize(size=(300, 400)) self.assertTrue(fake_run_operation.resize.called)
def test_hijack_tty(self, fake_Terminal, fake_get_stdin_pump, fake_select): """``dockerpty.pty`` PseudoTerminal '_hijack_tty' runs until all Pumps are done""" fake_select.return_value = ([], []) fake_client = MagicMock() fake_run_operation = MagicMock() fake_pump = MagicMock() fake_pumps = [fake_pump] fake_select.return_value = ([fake_pump], [fake_pump]) pty.PseudoTerminal(fake_client, fake_run_operation)._hijack_tty(fake_pumps)
def test_start(self, fake_WINCHHandler, fake_hijack_tty, fake_set_blocking): """``dockerpty.pty`` PseudoTerminal 'start' hijacks the current TTY""" fake_client = MagicMock() fake_run_operation = MagicMock() fake_pump = MagicMock() fake_run_operation.start.return_value = [fake_pump] pty.PseudoTerminal(fake_client, fake_run_operation).start() self.assertTrue(fake_hijack_tty.called)
def test_hijack_tty_not_tty(self, fake_Terminal, fake_get_stdin_pump, fake_select, fake_isatty): """``dockerpty.pty`` PseudoTerminal '_hijack_tty' terminates in non-TTY runtimes""" fake_select.return_value = ([], []) fake_client = MagicMock() fake_run_operation = MagicMock() fake_pump = MagicMock() fake_pumps = [fake_pump] fake_select.return_value = ([fake_pump], [fake_pump]) fake_isatty.return_value = False pty.PseudoTerminal(fake_client, fake_run_operation)._hijack_tty(fake_pumps)
def test_hijack_tty_ok_ssl_error(self, fake_Terminal, fake_get_stdin_pump, fake_select): """``dockerpty.pty`` PseudoTerminal '_hijack_tty' can handle some SSL errors""" fake_select.return_value = ([], []) fake_client = MagicMock() fake_run_operation = MagicMock() fake_pump = MagicMock() ssl_error = SSLError() ssl_error.strerror = 'The operation did not complete' fake_pump.do_write.side_effect = [ssl_error, MagicMock()] fake_pumps = [fake_pump] fake_select.return_value = ([fake_pump], [fake_pump]) pty.PseudoTerminal(fake_client, fake_run_operation)._hijack_tty(fake_pumps)
def test_hijack_tty_bad_ssl_error(self, fake_Terminal, fake_get_stdin_pump, fake_select): """``dockerpty.pty`` PseudoTerminal '_hijack_tty' raises if it catches an expected SSL error""" fake_select.return_value = ([], []) fake_client = MagicMock() fake_run_operation = MagicMock() fake_pump = MagicMock() ssl_error = SSLError() ssl_error.strerror = 'doh' fake_pump.do_write.side_effect = [ssl_error, MagicMock()] fake_pumps = [fake_pump] fake_select.return_value = ([fake_pump], [fake_pump]) with self.assertRaises(SSLError): pty.PseudoTerminal(fake_client, fake_run_operation)._hijack_tty(fake_pumps)