Exemplo n.º 1
0
 def setUp(self):
     self.client_sock, self.server_sock = socket.socketpair()
     self.mock_socket = mock.Mock()
     self.mock_server = mock.create_autospec(PailgunServer, spec_set=True)
     self.handler = PailgunHandler(self.server_sock,
                                   self.client_sock.getsockname()[:2],
                                   self.mock_server)
Exemplo n.º 2
0
 def setUp(self):
   self.client_sock, self.server_sock = socket.socketpair()
   self.mock_socket = mock.Mock()
   self.mock_server = mock.create_autospec(PailgunServer, spec_set=True)
   self.handler = PailgunHandler(
     self.server_sock,
     self.client_sock.getsockname()[:2],
     self.mock_server
   )
Exemplo n.º 3
0
class TestPailgunHandler(unittest.TestCase):
    def setUp(self):
        self.client_sock, self.server_sock = socket.socketpair()
        self.mock_socket = unittest.mock.Mock()
        self.mock_server = unittest.mock.create_autospec(PailgunServer, spec_set=True)
        self.handler = PailgunHandler(
            self.server_sock, self.client_sock.getsockname()[:2], self.mock_server
        )

    def test_handle_error(self):
        self.handler.handle_error()
        maybe_shutdown_socket = MaybeShutdownSocket(self.client_sock)
        last_chunk_type, last_payload = list(NailgunProtocol.iter_chunks(maybe_shutdown_socket))[-1]
        self.assertEqual(last_chunk_type, ChunkType.EXIT)
        self.assertEqual(last_payload, "1")

    @unittest.mock.patch.object(PailgunHandler, "_run_pants", **PATCH_OPTS)
    def test_handle_request(self, mock_run_pants):
        NailgunProtocol.send_request(self.client_sock, "/test", "./pants", "help-advanced")
        self.handler.handle_request()
        self.assertIs(mock_run_pants.called, True)
Exemplo n.º 4
0
class TestPailgunHandler(unittest.TestCase):
  def setUp(self):
    self.client_sock, self.server_sock = socket.socketpair()
    self.mock_socket = mock.Mock()
    self.mock_server = mock.create_autospec(PailgunServer, spec_set=True)
    self.handler = PailgunHandler(
      self.server_sock,
      self.client_sock.getsockname()[:2],
      self.mock_server
    )

  def test_handle_error(self):
    self.handler.handle_error()
    last_chunk_type, last_payload = list(NailgunProtocol.iter_chunks(self.client_sock))[-1]
    self.assertEquals(last_chunk_type, ChunkType.EXIT)
    self.assertEquals(bytes(last_payload), '1')

  @mock.patch.object(PailgunHandler, '_run_pants', **PATCH_OPTS)
  def test_handle_request(self, mock_run_pants):
    NailgunProtocol.send_request(self.client_sock, '/test', './pants', 'help-advanced')
    self.handler.handle_request()
    self.assertIs(mock_run_pants.called, True)