Exemplo n.º 1
0
  def test_remove_async_file_after_failed_request(self):
      # Even if the request failed, wsgid must remove the temporary file.
       with patch('zmq.Context'):
          with patch('os.unlink') as mock_unlink:
            def _serve_request(wsgid, m2message):
                with patch.object(wsgid, '_create_wsgi_environ'):
                    wsgid._create_wsgi_environ.return_value = {}
                    with patch("__builtin__.open"):
                        wsgid._call_wsgi_app(message, Mock())

            wsgid = Wsgid(app = Mock(side_effect = Exception("Failed")))
            wsgid.log = Mock()
            message = self._create_fake_m2message('/uploads/m2.84Yet4')
            _serve_request(wsgid, message)
            mock_unlink.assert_called_with('/uploads/m2.84Yet4')
Exemplo n.º 2
0
  def test_protect_against_exception_on_file_removal(self):
        with patch('zmq.Context'):
          with patch('os.unlink') as mock_unlink:
            mock_unlink.side_effect = OSError("File does not exist")
            def _serve_request(wsgid, m2message):
                with patch.object(wsgid, '_create_wsgi_environ'):
                    wsgid._create_wsgi_environ.return_value = {}
                    with patch("__builtin__.open"):
                        wsgid._call_wsgi_app(message, Mock())

            wsgid = Wsgid(app = Mock(return_value = ['body response']))
            wsgid.log = Mock()
            message = self._create_fake_m2message('/uploads/m2.84Yet4')
            _serve_request(wsgid, message)
            self.assertEquals(1, wsgid.log.exception.call_count)
Exemplo n.º 3
0
  def test_do_not_try_to_remove_if_not_upload_request(self):
         with patch('zmq.Context'):
          with patch('os.unlink') as mock_unlink:
            def _serve_request(wsgid, m2message):
                with patch.object(wsgid, '_create_wsgi_environ'):
                    wsgid._create_wsgi_environ.return_value = {}
                    with patch("__builtin__.open"):
                        wsgid._call_wsgi_app(message, Mock())

            wsgid = Wsgid(app = Mock(return_value = ['body response']))
            wsgid.log = Mock()
            message = Mock()
            message.headers = [] #It's not an upload message
            message.client_id = 'uuid'
            message.server_id = '1'
            message.is_upload_done.return_value = False
            _serve_request(wsgid, message)
            self.assertEquals(0, mock_unlink.call_count)
Exemplo n.º 4
0
 def _serve(app):
   w = Wsgid(app, 
       'tcp://127.0.0.1:8889', 
       'tcp://127.0.0.1:8890')
   w.log = logging
   w.serve()
Exemplo n.º 5
0
 def _serve(app):
     w = Wsgid(app, 'tcp://127.0.0.1:8889', 'tcp://127.0.0.1:8890')
     w.log = logging
     w.serve()