Ejemplo n.º 1
0
 def test_invoke_empty_plain_text_response(self, mock_run_lambda):
     with self.app.test_request_context() as context:
         self._request_response(context)
         mock_run_lambda.return_value = ''
         response = lambda_api.invoke_function(self.FUNCTION_NAME)
         self.assertEqual('', response[0])
         self.assertEqual(200, response[1])
         self._assert_contained({'Content-Type': 'text/plain'}, response[2])
Ejemplo n.º 2
0
 def test_invoke_null_json_response(self, mock_run_lambda):
     with self.app.test_request_context() as context:
         self._request_response(context)
         mock_run_lambda.return_value = 'null'
         response = lambda_api.invoke_function(self.FUNCTION_NAME)
         self.assertEqual(b'null\n', response[0].response[0])
         self.assertEqual(200, response[1])
         self.assertEqual({'Content-Type': 'application/json'}, response[2])
Ejemplo n.º 3
0
 def test_invoke_populated_map_json_response(self, mock_run_lambda):
     with self.app.test_request_context() as context:
         self._request_response(context)
         mock_run_lambda.return_value = '{"bool":true,"int":1}'
         response = lambda_api.invoke_function(self.FUNCTION_NAME)
         self.assertEqual(b'{"bool":true,"int":1}\n', response[0].response[0])
         self.assertEqual(200, response[1])
         self.assertEquals({'Content-Type': 'application/json'}, response[2])
Ejemplo n.º 4
0
 def test_invoke_populated_list_json_response(self, mock_run_lambda):
     with self.app.test_request_context() as context:
         self._request_response(context)
         mock_run_lambda.return_value = '[true,1,"thing"]'
         response = lambda_api.invoke_function(self.FUNCTION_NAME)
         self.assertEqual(b'[true,1,"thing"]\n', response[0].response[0])
         self.assertEqual(200, response[1])
         self._assert_contained({'Content-Type': 'application/json'}, response[2])
Ejemplo n.º 5
0
 def test_invoke_null_json_response(self, mock_run_lambda):
     with self.app.test_request_context() as context:
         self._request_response(context)
         mock_run_lambda.return_value = "null"
         response = lambda_api.invoke_function(self.FUNCTION_NAME)
         self.assertEqual(b"null\n", response[0].response[0])
         self.assertEqual(200, response[1])
         self._assert_contained({"Content-Type": "application/json"},
                                response[0].headers)
Ejemplo n.º 6
0
 def test_invoke_empty_map_json_response(self, mock_run_lambda):
     with self.app.test_request_context() as context:
         self._request_response(context)
         mock_run_lambda.return_value = "{}"
         response = lambda_api.invoke_function(self.FUNCTION_NAME)
         self.assertEqual(b"{}\n", response[0].response[0])
         self.assertEqual(200, response[1])
         self.assertEqual("application/json",
                          response[0].headers["Content-Type"])
Ejemplo n.º 7
0
 def test_invoke_boolean_json_response(self, mock_run_lambda):
     with self.app.test_request_context() as context:
         self._request_response(context)
         mock_run_lambda.return_value = 'true'
         response = lambda_api.invoke_function(self.FUNCTION_NAME)
         self.assertEqual(b'true\n', response[0].response[0])
         self.assertEqual(200, response[1])
         self._assert_contained({'Content-Type': 'application/json'},
                                response[0].headers)
Ejemplo n.º 8
0
    def test_invoke_empty_plain_text_response(self, mock_run_lambda):
        with self.app.test_request_context() as context:
            self._request_response(context)
            mock_run_lambda.return_value = ""
            response = lambda_api.invoke_function(self.FUNCTION_NAME)
            self.assertEqual("", response[0])
            self.assertEqual(200, response[1])

            headers = response[2]
            self.assertEqual("text/plain", headers["Content-Type"])
Ejemplo n.º 9
0
    def test_invoke_plain_text_response(self, mock_run_lambda):
        with self.app.test_request_context() as context:
            self._request_response(context)
            mock_run_lambda.return_value = '~notjsonresponse~'
            response = lambda_api.invoke_function(self.FUNCTION_NAME)
            self.assertEqual('~notjsonresponse~', response[0])
            self.assertEqual(200, response[1])

            headers = response[2]
            self.assertEqual('text/plain', headers['Content-Type'])
Ejemplo n.º 10
0
 def test_invoke_RETURNS_415_WHEN_not_json_input(self):
     with self.app.test_request_context() as context:
         context.request._cached_data = '~notjsonrequest~'
         response = lambda_api.invoke_function(self.FUNCTION_NAME)
         self.assertEqual('415 UNSUPPORTED MEDIA TYPE', response.status)