コード例 #1
0
ファイル: wsgid_test.py プロジェクト: ildus/wsgid
  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") as mock_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)
コード例 #2
0
ファイル: wsgid_test.py プロジェクト: ildus/wsgid
  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") as mock_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')
コード例 #3
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") as mock_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)
コード例 #4
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") as mock_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')
コード例 #5
0
ファイル: wsgid_test.py プロジェクト: ildus/wsgid
  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") as mock_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)
コード例 #6
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") as mock_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)