-
Notifications
You must be signed in to change notification settings - Fork 2.4k
test: First pass of migration of combination integration tests #1970
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
2aacd6d
change yaml.load to yaml.safe_load for the security best practice
mingkun2020 060102c
use yaml_parse for consistant style
mingkun2020 938ff8d
migrate integration tests part 1
mingkun2020 2ae0175
remove todo comment
mingkun2020 7ff9841
address comment and fix
mingkun2020 639aafe
add customized exception class
mingkun2020 d352e97
add integration tests part 2, need some refactoring for base_test.py
mingkun2020 e8f6e82
fix typo and remove test print statement
mingkun2020 f9e389c
add tests for deployment preferences
mingkun2020 7e39741
add deployment test for global
mingkun2020 ee0be87
remove all debug print statements
mingkun2020 11c4f5e
change assert method to make it compatible with python2
mingkun2020 6c40955
fix a typo
mingkun2020 54a4418
fix time module name conflict
mingkun2020 b9634ff
remove first if in client provider, concanated folder and file name t…
mingkun2020 5279e78
change file_name to file_path and added docstring
mingkun2020 b38513f
change method to static
mingkun2020 a6ec11e
Merge branch 'develop' of https://github.com/aws/serverless-applicati…
mingkun2020 a93d7e2
Merge branch 'develop' into foss-migrate
mingkun2020 abba29c
solve some errors after merge
mingkun2020 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| from io import BytesIO | ||
|
|
||
| try: | ||
| from pathlib import Path | ||
| except ImportError: | ||
| from pathlib2 import Path | ||
|
|
||
| import requests | ||
| from parameterized import parameterized | ||
|
|
||
| from integration.helpers.base_test import BaseTest | ||
|
|
||
| from PIL import Image | ||
|
|
||
|
|
||
| class TestApiSettings(BaseTest): | ||
| def test_method_settings(self): | ||
| self.create_and_verify_stack("combination/api_with_method_settings") | ||
|
|
||
| rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi") | ||
| apigw_client = self.client_provider.api_client | ||
| response = apigw_client.get_stage(restApiId=rest_api_id, stageName="Prod") | ||
|
|
||
| wildcard_path = "*/*" | ||
|
|
||
| method_settings = response["methodSettings"] | ||
| self.assertTrue(wildcard_path in method_settings, "MethodSettings for the wildcard path must be present") | ||
|
|
||
| wildcard_path_setting = method_settings[wildcard_path] | ||
|
|
||
| self.assertTrue(wildcard_path_setting["metricsEnabled"], "Metrics must be enabled") | ||
| self.assertTrue(wildcard_path_setting["dataTraceEnabled"], "DataTrace must be enabled") | ||
| self.assertEqual(wildcard_path_setting["loggingLevel"], "INFO", "LoggingLevel must be INFO") | ||
|
|
||
| @parameterized.expand( | ||
| [ | ||
| "combination/api_with_binary_media_types", | ||
| "combination/api_with_binary_media_types_with_definition_body", | ||
| ] | ||
| ) | ||
| def test_binary_media_types(self, file_name): | ||
| self.create_and_verify_stack(file_name, self.get_default_test_template_parameters()) | ||
|
|
||
| rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi") | ||
| apigw_client = self.client_provider.api_client | ||
|
|
||
| response = apigw_client.get_rest_api(restApiId=rest_api_id) | ||
| self.assertEqual(set(response["binaryMediaTypes"]), {"image/jpg", "image/png", "image/gif"}) | ||
|
|
||
| @parameterized.expand( | ||
| [ | ||
| "combination/api_with_request_models", | ||
| "combination/api_with_request_models_openapi", | ||
| ] | ||
| ) | ||
| def test_request_models(self, file_name): | ||
| self.create_and_verify_stack(file_name) | ||
|
|
||
| rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi") | ||
| apigw_client = self.client_provider.api_client | ||
|
|
||
| response = apigw_client.get_models(restApiId=rest_api_id) | ||
| request_models = response["items"] | ||
|
|
||
| self.assertEqual(request_models[0]["name"], "user") | ||
| self.assertEqual( | ||
| request_models[0]["schema"], | ||
| '{\n "type" : "object",\n' | ||
| + ' "properties" : {\n "username" : {\n "type" : "string"\n }\n' | ||
| + " }\n}", | ||
| ) | ||
|
|
||
| def test_request_parameters_open_api(self): | ||
| self.create_and_verify_stack("combination/api_with_request_parameters_openapi") | ||
|
|
||
| rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi") | ||
| apigw_client = self.client_provider.api_client | ||
|
|
||
| # Test if the request parameters got set on the method | ||
| resources_response = apigw_client.get_resources(restApiId=rest_api_id) | ||
| resources = resources_response["items"] | ||
|
|
||
| resource = get_resource_by_path(resources, "/one") | ||
| method = apigw_client.get_method(restApiId=rest_api_id, resourceId=resource["id"], httpMethod="GET") | ||
| expected = {"method.request.querystring.type": True} | ||
| self.assertEqual(expected, method["requestParameters"]) | ||
|
|
||
| # Test that the method settings got applied on the method | ||
| stage_response = apigw_client.get_stage(restApiId=rest_api_id, stageName="Prod") | ||
| method_settings = stage_response["methodSettings"] | ||
|
|
||
| path = "one/GET" | ||
| self.assertTrue(path in method_settings, "MethodSettings for the path must be present") | ||
|
|
||
| path_settings = method_settings[path] | ||
| self.assertEqual(path_settings["cacheTtlInSeconds"], 15) | ||
| self.assertTrue(path_settings["cachingEnabled"], "Caching must be enabled") | ||
|
|
||
| def test_binary_media_types_with_definition_body_openapi(self): | ||
| parameters = self.get_default_test_template_parameters() | ||
| binary_media = { | ||
| "ParameterKey": "BinaryMediaCodeKey", | ||
| "ParameterValue": "binary-media.zip", | ||
| "UsePreviousValue": False, | ||
| "ResolvedValue": "string", | ||
| } | ||
| parameters.append(binary_media) | ||
|
|
||
| self.create_and_verify_stack("combination/api_with_binary_media_types_with_definition_body_openapi", parameters) | ||
|
|
||
| rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi") | ||
| apigw_client = self.client_provider.api_client | ||
|
|
||
| response = apigw_client.get_rest_api(restApiId=rest_api_id) | ||
| self.assertEqual( | ||
| set(response["binaryMediaTypes"]), {"image/jpg", "image/png", "image/gif", "application/octet-stream"} | ||
| ) | ||
| base_url = self.get_stack_output("ApiUrl")["OutputValue"] | ||
| self.verify_binary_media_request(base_url + "none", 200) | ||
|
|
||
| @parameterized.expand( | ||
| [ | ||
| "combination/api_with_endpoint_configuration", | ||
| "combination/api_with_endpoint_configuration_dict", | ||
| ] | ||
| ) | ||
| def test_end_point_configuration(self, file_name): | ||
| self.create_and_verify_stack(file_name, self.get_default_test_template_parameters()) | ||
|
|
||
| rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi") | ||
| apigw_client = self.client_provider.api_client | ||
|
|
||
| response = apigw_client.get_rest_api(restApiId=rest_api_id) | ||
| endpoint_config = response["endpointConfiguration"] | ||
| self.assertEqual(endpoint_config["types"], ["REGIONAL"]) | ||
|
|
||
| def test_implicit_api_settings(self): | ||
| self.create_and_verify_stack("combination/implicit_api_with_settings") | ||
|
|
||
| rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi") | ||
| apigw_client = self.client_provider.api_client | ||
|
|
||
| response = apigw_client.get_stage(restApiId=rest_api_id, stageName="Prod") | ||
|
|
||
| wildcard_path = "*/*" | ||
|
|
||
| method_settings = response["methodSettings"] | ||
| self.assertTrue(wildcard_path in method_settings, "MethodSettings for the wildcard path must be present") | ||
|
|
||
| wildcard_path_setting = method_settings[wildcard_path] | ||
| print(wildcard_path_setting) | ||
| self.assertTrue(wildcard_path_setting["metricsEnabled"], "Metrics must be enabled") | ||
| self.assertTrue(wildcard_path_setting["dataTraceEnabled"], "DataTrace must be enabled") | ||
| self.assertEqual(wildcard_path_setting["loggingLevel"], "INFO", "LoggingLevel must be INFO") | ||
|
|
||
| response = apigw_client.get_rest_api(restApiId=rest_api_id) | ||
| endpoint_config = response["endpointConfiguration"] | ||
| self.assertEqual(endpoint_config["types"], ["REGIONAL"]) | ||
| self.assertEqual(set(response["binaryMediaTypes"]), {"image/jpg", "image/png"}) | ||
|
|
||
| def verify_binary_media_request(self, url, expected_status_code): | ||
| print("Making request to " + url) | ||
| headers = {"accept": "image/png"} | ||
| response = requests.get(url, headers=headers) | ||
|
|
||
| status = response.status_code | ||
| expected = Image.open(Path(self.code_dir, "AWS_logo_RGB.png")) | ||
|
|
||
| if 200 <= status <= 299: | ||
| actual = Image.open(BytesIO(response.content)) | ||
| self.assertEqual(expected, actual) | ||
|
|
||
| self.assertEqual(status, expected_status_code, " must return HTTP " + str(expected_status_code)) | ||
|
|
||
|
|
||
| def get_resource_by_path(resources, path): | ||
| for resource in resources: | ||
| if resource["path"] == path: | ||
| return resource | ||
| return None | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.