Ejemplo n.º 1
0
    def test_post_init_error(self, MockHTTPConnection):
        mock_conn = MockHTTPConnection.return_value
        mock_response = MagicMock(autospec=http.client.HTTPResponse)
        mock_conn.getresponse.return_value = mock_response
        mock_response.read.return_value = b""
        mock_response.code = http.HTTPStatus.ACCEPTED

        runtime_client = LambdaRuntimeClient("localhost:1234")
        runtime_client.post_init_error("error_data")

        MockHTTPConnection.assert_called_with("localhost:1234")
        mock_conn.request.assert_called_once_with(
            "POST", "/2018-06-01/runtime/init/error", "error_data")
        mock_response.read.assert_called_once()
Ejemplo n.º 2
0
    def test_post_init_error_non_accepted_status_code(self,
                                                      MockHTTPConnection):
        mock_conn = MockHTTPConnection.return_value
        mock_response = MagicMock(autospec=http.client.HTTPResponse)
        mock_conn.getresponse.return_value = mock_response
        mock_response.read.return_value = b""
        mock_response.code = http.HTTPStatus.IM_USED

        runtime_client = LambdaRuntimeClient("localhost:1234")

        with self.assertRaises(LambdaRuntimeClientError) as cm:
            runtime_client.post_init_error("error_data")
        returned_exception = cm.exception

        self.assertEqual(returned_exception.endpoint,
                         "/2018-06-01/runtime/init/error")
        self.assertEqual(returned_exception.response_code,
                         http.HTTPStatus.IM_USED)
Ejemplo n.º 3
0
 def test_invalid_addr(self):
     with self.assertRaises(OSError):
         runtime_client = LambdaRuntimeClient("::::")
         runtime_client.post_init_error("error")
Ejemplo n.º 4
0
 def test_connection_refused(self):
     with self.assertRaises(ConnectionRefusedError):
         runtime_client = LambdaRuntimeClient("127.0.0.1:1")
         runtime_client.post_init_error("error")