Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,7 @@ venv.bak/
.vscode

# PyCharm
.idea
.idea

# Companion stack config
integration/config/file_to_s3_map_modified.json
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
Expand Down
2 changes: 1 addition & 1 deletion integration/combination/test_api_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
4 changes: 2 additions & 2 deletions integration/combination/test_api_with_authorizer_apikey.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion integration/config/logger_configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 16 additions & 8 deletions integration/helpers/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
22 changes: 11 additions & 11 deletions integration/single/test_function_with_http_api_and_auth.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
2 changes: 0 additions & 2 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down