diff --git a/.gitignore b/.gitignore index d0aa7bd6eb..229672107a 100644 --- a/.gitignore +++ b/.gitignore @@ -113,4 +113,7 @@ venv.bak/ .vscode # PyCharm -.idea \ No newline at end of file +.idea + +# Companion stack config +integration/config/file_to_s3_map_modified.json \ No newline at end of file diff --git a/Makefile b/Makefile index c10a3e1ab2..eba770f597 100755 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ init: pip install -e '.[dev]' test: - pytest --cov samtranslator --cov-report term-missing --cov-fail-under 95 -n auto tests/* + AWS_DEFAULT_REGION=us-east-1 pytest --cov samtranslator --cov-report term-missing --cov-fail-under 95 -n auto tests/* test-fast: pytest -x --cov samtranslator --cov-report term-missing --cov-fail-under 95 -n auto tests/* diff --git a/integration/combination/test_api_settings.py b/integration/combination/test_api_settings.py index 70fc599018..c789480745 100644 --- a/integration/combination/test_api_settings.py +++ b/integration/combination/test_api_settings.py @@ -162,7 +162,7 @@ def test_implicit_api_settings(self): def verify_binary_media_request(self, url, expected_status_code): headers = {"accept": "image/png"} - response = BaseTest.do_get_request_with_logging(url, headers) + response = self.do_get_request_with_logging(url, headers) status = response.status_code expected_file_path = str(Path(self.code_dir, "AWS_logo_RGB.png")) diff --git a/integration/combination/test_api_with_authorizer_apikey.py b/integration/combination/test_api_with_authorizer_apikey.py index 5f0190e2bd..8f8f04aa1b 100644 --- a/integration/combination/test_api_with_authorizer_apikey.py +++ b/integration/combination/test_api_with_authorizer_apikey.py @@ -80,10 +80,10 @@ def verify_authorized_request( header_value=None, ): if not header_key or not header_value: - response = BaseTest.do_get_request_with_logging(url) + response = self.do_get_request_with_logging(url) else: headers = {header_key: header_value} - response = BaseTest.do_get_request_with_logging(url, headers) + response = self.do_get_request_with_logging(url, headers) status = response.status_code if status != expected_status_code: raise StatusCodeError( diff --git a/integration/config/logger_configurations.py b/integration/config/logger_configurations.py index d51f988852..75869f25ce 100644 --- a/integration/config/logger_configurations.py +++ b/integration/config/logger_configurations.py @@ -8,7 +8,9 @@ def configure_request_logger(logger): console_handler = logging.StreamHandler() console_handler.setLevel(logging.INFO) console_handler.setFormatter( - logging.Formatter("%(asctime)s %(message)s | Status: %(status)s | Headers: %(headers)s ") + logging.Formatter( + "\nREQUEST LOG [%(test)s] | Time: %(asctime)s %(message)s | Status: %(status)s | Headers: %(headers)s" + ) ) logger.addHandler(console_handler) logger.propagate = False diff --git a/integration/helpers/base_test.py b/integration/helpers/base_test.py index b462639482..c741639a93 100644 --- a/integration/helpers/base_test.py +++ b/integration/helpers/base_test.py @@ -60,6 +60,10 @@ def stage(self, get_stage): def s3_bucket(self, get_s3): self.s3_bucket_name = get_s3 + @pytest.fixture(autouse=True) + def case_name(self, request): + self.testcase = request.node.name + @classmethod @pytest.mark.usefixtures("get_prefix", "get_stage", "check_internal", "parameter_values", "get_s3") def setUpClass(cls): @@ -470,7 +474,7 @@ def verify_get_request_response(self, url, expected_status_code, headers=None): headers : dict headers to use in request """ - response = BaseTest.do_get_request_with_logging(url, headers) + response = self.do_get_request_with_logging(url, headers) if response.status_code != expected_status_code: raise StatusCodeError( "Request to {} failed with status: {}, expected status: {}".format( @@ -499,7 +503,7 @@ def verify_options_request(self, url, expected_status_code, headers=None): headers : dict headers to use in request """ - response = BaseTest.do_options_request_with_logging(url, headers) + response = self.do_options_request_with_logging(url, headers) if response.status_code != expected_status_code: raise StatusCodeError( "Request to {} failed with status: {}, expected status: {}".format( @@ -544,8 +548,7 @@ def generate_parameter(key, value, previous_value=False, resolved_value="string" } return parameter - @staticmethod - def do_get_request_with_logging(url, headers=None): + def do_get_request_with_logging(self, url, headers=None): """ Perform a get request to an APIGW endpoint and log relevant info Parameters @@ -557,11 +560,13 @@ def do_get_request_with_logging(url, headers=None): """ response = requests.get(url, headers=headers) if headers else requests.get(url) amazon_headers = RequestUtils(response).get_amazon_headers() - REQUEST_LOGGER.info("Request made to " + url, extra={"status": response.status_code, "headers": amazon_headers}) + REQUEST_LOGGER.info( + "Request made to " + url, + extra={"test": self.testcase, "status": response.status_code, "headers": amazon_headers}, + ) return response - @staticmethod - def do_options_request_with_logging(url, headers=None): + def do_options_request_with_logging(self, url, headers=None): """ Perform a options request to an APIGW endpoint and log relevant info Parameters @@ -573,5 +578,8 @@ def do_options_request_with_logging(url, headers=None): """ response = requests.options(url, headers=headers) if headers else requests.options(url) amazon_headers = RequestUtils(response).get_amazon_headers() - REQUEST_LOGGER.info("Request made to " + url, extra={"status": response.status_code, "headers": amazon_headers}) + REQUEST_LOGGER.info( + "Request made to " + url, + extra={"test": self.testcase, "status": response.status_code, "headers": amazon_headers}, + ) return response diff --git a/integration/single/test_function_with_http_api_and_auth.py b/integration/single/test_function_with_http_api_and_auth.py index b7f27da9bf..2dc8c7bb38 100644 --- a/integration/single/test_function_with_http_api_and_auth.py +++ b/integration/single/test_function_with_http_api_and_auth.py @@ -1,6 +1,7 @@ from unittest.case import skipIf import pytest +import time from integration.helpers.base_test import BaseTest from integration.helpers.resource import current_region_does_not_support @@ -21,23 +22,22 @@ def test_function_with_http_api_and_auth(self): self.create_and_verify_stack("single/function_with_http_api_events_and_auth") + # This will be changed according to APIGW suggested wait time + time.sleep(10) + implicitEndpoint = self.get_api_v2_endpoint("ServerlessHttpApi") self.assertEqual( - BaseTest.do_get_request_with_logging(implicitEndpoint + "/default-auth").text, self.FUNCTION_OUTPUT + self.do_get_request_with_logging(implicitEndpoint + "/default-auth").text, self.FUNCTION_OUTPUT ) - self.assertEqual(BaseTest.do_get_request_with_logging(implicitEndpoint + "/iam-auth").text, IAM_AUTH_OUTPUT) + self.assertEqual(self.do_get_request_with_logging(implicitEndpoint + "/iam-auth").text, IAM_AUTH_OUTPUT) defaultIamEndpoint = self.get_api_v2_endpoint("MyDefaultIamAuthHttpApi") - self.assertEqual( - BaseTest.do_get_request_with_logging(defaultIamEndpoint + "/no-auth").text, self.FUNCTION_OUTPUT - ) - self.assertEqual( - BaseTest.do_get_request_with_logging(defaultIamEndpoint + "/default-auth").text, IAM_AUTH_OUTPUT - ) - self.assertEqual(BaseTest.do_get_request_with_logging(defaultIamEndpoint + "/iam-auth").text, IAM_AUTH_OUTPUT) + self.assertEqual(self.do_get_request_with_logging(defaultIamEndpoint + "/no-auth").text, self.FUNCTION_OUTPUT) + self.assertEqual(self.do_get_request_with_logging(defaultIamEndpoint + "/default-auth").text, IAM_AUTH_OUTPUT) + self.assertEqual(self.do_get_request_with_logging(defaultIamEndpoint + "/iam-auth").text, IAM_AUTH_OUTPUT) iamEnabledEndpoint = self.get_api_v2_endpoint("MyIamAuthEnabledHttpApi") self.assertEqual( - BaseTest.do_get_request_with_logging(iamEnabledEndpoint + "/default-auth").text, self.FUNCTION_OUTPUT + self.do_get_request_with_logging(iamEnabledEndpoint + "/default-auth").text, self.FUNCTION_OUTPUT ) - self.assertEqual(BaseTest.do_get_request_with_logging(iamEnabledEndpoint + "/iam-auth").text, IAM_AUTH_OUTPUT) + self.assertEqual(self.do_get_request_with_logging(iamEnabledEndpoint + "/iam-auth").text, IAM_AUTH_OUTPUT) diff --git a/pytest.ini b/pytest.ini index d567f28ac8..1f21a32e8d 100644 --- a/pytest.ini +++ b/pytest.ini @@ -3,8 +3,6 @@ # NOTE: If debug breakpoints aren't working, comment out the code coverage line below addopts = --cov samtranslator --cov-report term-missing --cov-fail-under 95 testpaths = tests -env = - AWS_DEFAULT_REGION = ap-southeast-1 markers = slow: marks tests as slow (deselect with '-m "not slow"') log_cli = 1