Exemplo n.º 1
0
 def test_finish_wrapper_exception(self, mock_logger):
     """Assert that if ``finish`` raises a RuntimeError, it's logged."""
     responder = Responder(Mock())
     responder.request.finish.side_effect = RuntimeError("Womp womp")
     responder.finish_wrapper()
     responder.request.finish.assert_called_once_with()
     mock_logger.debug.assert_called_once_with("Womp womp")
Exemplo n.º 2
0
 def test_write(self, mock_reactor):
     """
     `write` forwards all data to the `request.write` method.
     """
     responder = Responder(Mock())
     responder.write("some data")
     mock_reactor.callFromThread.assert_called_once_with(responder.request.write, "some data")
Exemplo n.º 3
0
 def test_close(self, mock_reactor):
     """
     `close` invokes the request.finish method on the Twisted request.
     """
     responder = Responder(Mock())
     responder.close()
     mock_reactor.callFromThread.assert_called_once_with(responder.finish_wrapper)
Exemplo n.º 4
0
 def test_enter(self):
     """
     `__enter__` returns the instance of the class.
     """
     responder = Responder(Mock())
     result = responder.__enter__()
     self.assertTrue(responder is result)
Exemplo n.º 5
0
 def test_finish_wrapper_exception(self, mock_logger):
     """Assert that if ``finish`` raises a RuntimeError, it's logged."""
     responder = Responder(Mock())
     responder.request.finish.side_effect = RuntimeError('Womp womp')
     responder.finish_wrapper()
     responder.request.finish.assert_called_once_with()
     mock_logger.debug.assert_called_once_with('Womp womp')
Exemplo n.º 6
0
 def test_close(self, mock_reactor):
     """
     `close` invokes the request.finish method on the Twisted request.
     """
     responder = Responder(Mock())
     responder.close()
     mock_reactor.callFromThread.assert_called_once_with(responder.finish_wrapper)
Exemplo n.º 7
0
 def test_enter(self):
     """
     `__enter__` returns the instance of the class.
     """
     responder = Responder(Mock())
     result = responder.__enter__()
     self.assertTrue(responder is result)
Exemplo n.º 8
0
 def test_write(self, mock_reactor):
     """
     `write` forwards all data to the `request.write` method.
     """
     responder = Responder(Mock())
     responder.write('some data')
     mock_reactor.callFromThread.assert_called_once_with(responder.request.write,
                                                         'some data')
Exemplo n.º 9
0
    def test_exit(self):
        """
        `__exit__` invokes the `close` method on the instance.
        """
        responder = Responder(Mock())
        responder.close = Mock()

        responder.__exit__(None, None, None)
        responder.close.assert_called_once_with()
Exemplo n.º 10
0
    def test_exit(self):
        """
        `__exit__` invokes the `close` method on the instance.
        """
        responder = Responder(Mock())
        responder.close = Mock()

        responder.__exit__(None, None, None)
        responder.close.assert_called_once_with()
Exemplo n.º 11
0
    def test_with(self, mock_reactor):
        """
        The Responder class supports context managers.
        """
        mock_request = Mock()
        with Responder(mock_request) as r:
            r.write('some data')

        mock_calls = mock_reactor.callFromThread.call_args_list
        self.assertEqual((mock_request.write, 'some data'), mock_calls[0][0])
        self.assertEqual((r.finish_wrapper,), mock_calls[1][0])
Exemplo n.º 12
0
 def test_finish_wrapper(self):
     """Assert the ``finish`` method is called by its wrapper"""
     responder = Responder(Mock())
     responder.finish_wrapper()
     responder.request.finish.assert_called_once_with()
Exemplo n.º 13
0
 def test_finish_wrapper(self):
     """Assert the ``finish`` method is called by its wrapper"""
     responder = Responder(Mock())
     responder.finish_wrapper()
     responder.request.finish.assert_called_once_with()