Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Run make pr on Python3.8 #1519

Merged
merged 9 commits into from
Dec 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,23 @@ environment:
PYTHON_ARCH: '64'
NOSE_PARAMETERIZED_NO_WARN: 1
INSTALL_PY_37_PIP: 1
INSTALL_PY_38_PIP: 1

- PYTHON_HOME: "C:\\Python37-x64"
PYTHON_VERSION: '3.7.4'
PYTHON_ARCH: '64'
RUN_SMOKE: 1
NOSE_PARAMETERIZED_NO_WARN: 1
INSTALL_PY_36_PIP: 1
INSTALL_PY_38_PIP: 1

- PYTHON_HOME: "C:\\Python38-x64"
PYTHON_VERSION: '3.8.0'
PYTHON_ARCH: '64'
RUN_SMOKE: 1
NOSE_PARAMETERIZED_NO_WARN: 1
INSTALL_PY_36_PIP: 1
INSTALL_PY_37_PIP: 1

for:
-
Expand Down Expand Up @@ -102,7 +112,7 @@ for:
- sh: "curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py"

- sh: "sudo apt-get -y install python3-distutils"
- sh: "python3.8 get-pip.py --user"
- ps: "If ($env:INSTALL_PY_38_PIP) {python3.8 get-pip.py --user}"
- ps: "If ($env:INSTALL_PY_37_PIP) {python3.7 get-pip.py --user}"
- ps: "If ($env:INSTALL_PY_36_PIP) {python3.6 get-pip.py --user}"

Expand Down
2 changes: 0 additions & 2 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ python-dateutil~=2.6, <2.8.1
requests==2.22.0
serverlessrepo==0.1.9
aws_lambda_builders==0.6.0
# https://github.com/mhammond/pywin32/issues/1439
pywin32 < 226; sys_platform == 'win32'
tomlkit==0.5.8
1 change: 0 additions & 1 deletion samcli/settings/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# flake8: noqa
"""
Default Settings used by the CLI.

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def read_version():
"Programming Language :: Python",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Topic :: Internet",
"Topic :: Software Development :: Build Tools",
"Topic :: Utilities",
Expand Down
14 changes: 4 additions & 10 deletions tests/unit/local/apigw/test_local_apigw_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,10 @@ def test_request_handler_errors_when_unable_to_read_binary_data(self, service_er
result = self.service._request_handler()
self.assertEqual(result, failure_mock)

@patch("samcli.local.apigw.local_apigw_service.request")
def test_get_current_route(self, request_patch):
def test_get_current_route(self):
request_mock = Mock()
request_mock.endpoint = "path"
request_mock.method = "method"

request_patch.return_value = request_mock
request_mock.return_value.endpoint = "path"
request_mock.return_value.method = "method"

route_key_method_mock = Mock()
route_key_method_mock.return_value = "method:path"
Expand All @@ -241,8 +238,7 @@ def test_get_current_route(self, request_patch):

self.assertEqual(self.service._get_current_route(request_mock), "function")

@patch("samcli.local.apigw.local_apigw_service.request")
def test_get_current_route_keyerror(self, request_patch):
def test_get_current_route_keyerror(self):
"""
When the a HTTP request for given method+path combination is allowed by Flask but not in the list of routes,
something is messed up. Flask should be configured only from the list of routes.
Expand All @@ -252,8 +248,6 @@ def test_get_current_route_keyerror(self, request_patch):
request_mock.endpoint = "path"
request_mock.method = "method"

request_patch.return_value = request_mock

route_key_method_mock = Mock()
route_key_method_mock.return_value = "method:path"
self.service._route_key = route_key_method_mock
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest import TestCase
from unittest.mock import Mock, patch, ANY, call

from samcli.local.lambda_service import local_lambda_invoke_service
from samcli.local.lambda_service.local_lambda_invoke_service import LocalLambdaInvokeService
from samcli.local.lambdafn.exceptions import FunctionNotFound

Expand Down Expand Up @@ -46,12 +47,15 @@ def test_create_service_endpoints(self, flask_mock, error_handling_mock):

@patch("samcli.local.lambda_service.local_lambda_invoke_service.LocalLambdaInvokeService.service_response")
@patch("samcli.local.lambda_service.local_lambda_invoke_service.LambdaOutputParser")
@patch("samcli.local.lambda_service.local_lambda_invoke_service.request")
def test_invoke_request_handler(self, request_mock, lambda_output_parser_mock, service_response_mock):
def test_invoke_request_handler(self, lambda_output_parser_mock, service_response_mock):
lambda_output_parser_mock.get_lambda_output.return_value = "hello world", None, False
service_response_mock.return_value = "request response"

request_mock = Mock()
request_mock.get_data.return_value = b"{}"

local_lambda_invoke_service.request = request_mock

lambda_runner_mock = Mock()
service = LocalLambdaInvokeService(lambda_runner=lambda_runner_mock, port=3000, host="localhost")

Expand All @@ -63,9 +67,11 @@ def test_invoke_request_handler(self, request_mock, lambda_output_parser_mock, s
service_response_mock.assert_called_once_with("hello world", {"Content-Type": "application/json"}, 200)

@patch("samcli.local.lambda_service.local_lambda_invoke_service.LambdaErrorResponses")
@patch("samcli.local.lambda_service.local_lambda_invoke_service.request")
def test_invoke_request_handler_on_incorrect_path(self, request_mock, lambda_error_responses_mock):
def test_invoke_request_handler_on_incorrect_path(self, lambda_error_responses_mock):
request_mock = Mock()
request_mock.get_data.return_value = b"{}"
local_lambda_invoke_service.request = request_mock

lambda_runner_mock = Mock()
lambda_runner_mock.invoke.side_effect = FunctionNotFound

Expand All @@ -83,11 +89,12 @@ def test_invoke_request_handler_on_incorrect_path(self, request_mock, lambda_err

@patch("samcli.local.lambda_service.local_lambda_invoke_service.LocalLambdaInvokeService.service_response")
@patch("samcli.local.lambda_service.local_lambda_invoke_service.LambdaOutputParser")
@patch("samcli.local.lambda_service.local_lambda_invoke_service.request")
def test_request_handler_returns_process_stdout_when_making_response(
self, request_mock, lambda_output_parser_mock, service_response_mock
self, lambda_output_parser_mock, service_response_mock
):
request_mock = Mock()
request_mock.get_data.return_value = b"{}"
local_lambda_invoke_service.request = request_mock

lambda_logs = "logs"
lambda_response = "response"
Expand Down Expand Up @@ -128,13 +135,12 @@ def test_construct_error_handling(self, lambda_error_response_mock):

@patch("samcli.local.lambda_service.local_lambda_invoke_service.LocalLambdaInvokeService.service_response")
@patch("samcli.local.lambda_service.local_lambda_invoke_service.LambdaOutputParser")
@patch("samcli.local.lambda_service.local_lambda_invoke_service.request")
def test_invoke_request_handler_with_lambda_that_errors(
self, request_mock, lambda_output_parser_mock, service_response_mock
):
def test_invoke_request_handler_with_lambda_that_errors(self, lambda_output_parser_mock, service_response_mock):
lambda_output_parser_mock.get_lambda_output.return_value = "hello world", None, True
service_response_mock.return_value = "request response"
request_mock = Mock()
request_mock.get_data.return_value = b"{}"
local_lambda_invoke_service.request = request_mock

lambda_runner_mock = Mock()
service = LocalLambdaInvokeService(lambda_runner=lambda_runner_mock, port=3000, host="localhost")
Expand All @@ -150,11 +156,13 @@ def test_invoke_request_handler_with_lambda_that_errors(

@patch("samcli.local.lambda_service.local_lambda_invoke_service.LocalLambdaInvokeService.service_response")
@patch("samcli.local.lambda_service.local_lambda_invoke_service.LambdaOutputParser")
@patch("samcli.local.lambda_service.local_lambda_invoke_service.request")
def test_invoke_request_handler_with_no_data(self, request_mock, lambda_output_parser_mock, service_response_mock):
def test_invoke_request_handler_with_no_data(self, lambda_output_parser_mock, service_response_mock):
lambda_output_parser_mock.get_lambda_output.return_value = "hello world", None, False
service_response_mock.return_value = "request response"

request_mock = Mock()
request_mock.get_data.return_value = None
local_lambda_invoke_service.request = request_mock

lambda_runner_mock = Mock()
service = LocalLambdaInvokeService(lambda_runner=lambda_runner_mock, port=3000, host="localhost")
Expand All @@ -169,12 +177,13 @@ def test_invoke_request_handler_with_no_data(self, request_mock, lambda_output_p

class TestValidateRequestHandling(TestCase):
@patch("samcli.local.lambda_service.local_lambda_invoke_service.LambdaErrorResponses")
@patch("samcli.local.lambda_service.local_lambda_invoke_service.request")
def test_request_with_non_json_data(self, flask_request, lambda_error_responses_mock):
def test_request_with_non_json_data(self, lambda_error_responses_mock):
flask_request = Mock()
flask_request.get_data.return_value = b"notat:asdfasdf"
flask_request.headers = {}
flask_request.content_type = "application/json"
flask_request.args = {}
local_lambda_invoke_service.request = flask_request

lambda_error_responses_mock.invalid_request_content.return_value = "InvalidRequestContent"

Expand All @@ -187,12 +196,13 @@ def test_request_with_non_json_data(self, flask_request, lambda_error_responses_
lambda_error_responses_mock.invalid_request_content.assert_called_once_with(expected_called_with)

@patch("samcli.local.lambda_service.local_lambda_invoke_service.LambdaErrorResponses")
@patch("samcli.local.lambda_service.local_lambda_invoke_service.request")
def test_request_with_query_strings(self, flask_request, lambda_error_responses_mock):
def test_request_with_query_strings(self, lambda_error_responses_mock):
flask_request = Mock()
flask_request.get_data.return_value = None
flask_request.headers = {}
flask_request.content_type = "application/json"
flask_request.args = {"key": "value"}
local_lambda_invoke_service.request = flask_request

lambda_error_responses_mock.invalid_request_content.return_value = "InvalidRequestContent"

Expand All @@ -205,12 +215,13 @@ def test_request_with_query_strings(self, flask_request, lambda_error_responses_
)

@patch("samcli.local.lambda_service.local_lambda_invoke_service.LambdaErrorResponses")
@patch("samcli.local.lambda_service.local_lambda_invoke_service.request")
def test_request_log_type_not_None(self, flask_request, lambda_error_responses_mock):
def test_request_log_type_not_None(self, lambda_error_responses_mock):
flask_request = Mock()
flask_request.get_data.return_value = None
flask_request.headers = {"X-Amz-Log-Type": "Tail"}
flask_request.content_type = "application/json"
flask_request.args = {}
local_lambda_invoke_service.request = flask_request

lambda_error_responses_mock.not_implemented_locally.return_value = "NotImplementedLocally"

Expand All @@ -223,12 +234,13 @@ def test_request_log_type_not_None(self, flask_request, lambda_error_responses_m
)

@patch("samcli.local.lambda_service.local_lambda_invoke_service.LambdaErrorResponses")
@patch("samcli.local.lambda_service.local_lambda_invoke_service.request")
def test_request_invocation_type_not_ResponseRequest(self, flask_request, lambda_error_responses_mock):
def test_request_invocation_type_not_ResponseRequest(self, lambda_error_responses_mock):
flask_request = Mock()
flask_request.get_data.return_value = None
flask_request.headers = {"X-Amz-Invocation-Type": "DryRun"}
flask_request.content_type = "application/json"
flask_request.args = {}
local_lambda_invoke_service.request = flask_request

lambda_error_responses_mock.not_implemented_locally.return_value = "NotImplementedLocally"

Expand All @@ -246,6 +258,7 @@ def test_request_with_no_data(self, flask_request):
flask_request.headers = {}
flask_request.content_type = "application/json"
flask_request.args = {}
local_lambda_invoke_service.request = flask_request

response = LocalLambdaInvokeService.validate_request()

Expand Down