Exemple #1
0
 def test_finish_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()
     responder.request.finish.assert_called_once_with()
     mock_logger.debug.assert_called_once_with('Womp womp')
Exemple #2
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)
Exemple #3
0
 def test_enter(self):
     """
     `__enter__` returns the instance of the class.
     """
     responder = Responder(Mock())
     result = responder.__enter__()
     self.assertTrue(responder is result)
Exemple #4
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')
Exemple #5
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()
Exemple #6
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,), mock_calls[1][0])
Exemple #7
0
 def test_finish(self):
     """Assert the ``finish`` method is called by its wrapper"""
     responder = Responder(Mock())
     responder.finish()
     responder.request.finish.assert_called_once_with()