forked from aws/serverless-application-model
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'aws:develop' into develop
- Loading branch information
Showing
188 changed files
with
25,783 additions
and
1,167 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
27 changes: 27 additions & 0 deletions
27
integration/combination/test_api_and_http_api_with_propagate_tags.py
This file contains 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,27 @@ | ||
from unittest.case import skipIf | ||
|
||
from integration.config.service_names import HTTP_API, REST_API | ||
from integration.helpers.base_test import BaseTest | ||
from integration.helpers.resource import current_region_does_not_support | ||
|
||
|
||
@skipIf( | ||
current_region_does_not_support([HTTP_API, REST_API]), | ||
"REST_API or HTTP_API is not supported in this testing region", | ||
) | ||
class TestApiAndHttpiWithPropagateTags(BaseTest): | ||
def test_api_and_httpapi_with_propagate_tags(self): | ||
self.create_and_verify_stack("combination/api_with_propagate_tags") | ||
|
||
outputs = self.get_stack_outputs() | ||
|
||
api_client = self.client_provider.api_client | ||
api_v2_client = self.client_provider.api_v2_client | ||
|
||
tags = api_client.get_tags(resourceArn=outputs["ApiArn"]) | ||
self.assertEqual(tags["tags"]["Key1"], "Value1") | ||
self.assertEqual(tags["tags"]["Key2"], "Value2") | ||
|
||
tags = api_v2_client.get_tags(ResourceArn=outputs["HttpApiArn"]) | ||
self.assertEqual(tags["Tags"]["Tag1"], "value1") | ||
self.assertEqual(tags["Tags"]["Tag2"], "value2") |
101 changes: 101 additions & 0 deletions
101
integration/combination/test_graphqlapi_lambda_resolver.py
This file contains 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,101 @@ | ||
import json | ||
from unittest.case import skipIf | ||
|
||
import requests | ||
|
||
from integration.config.service_names import APP_SYNC | ||
from integration.helpers.base_test import BaseTest | ||
from integration.helpers.resource import current_region_does_not_support | ||
|
||
|
||
def execute_and_verify_appsync_query(url, api_key, query): | ||
""" | ||
Executes a query to an AppSync GraphQLApi. | ||
Also checks that the response is 200 and does not contain errors before returning. | ||
""" | ||
headers = { | ||
"Content-Type": "application/json", | ||
"x-api-key": api_key, | ||
} | ||
payload = {"query": query} | ||
|
||
response = requests.post(url, json=payload, headers=headers) | ||
response.raise_for_status() | ||
data = response.json() | ||
if "errors" in data: | ||
raise Exception(json.dumps(data["errors"])) | ||
|
||
return data | ||
|
||
|
||
@skipIf(current_region_does_not_support([APP_SYNC]), "AppSync is not supported in this testing region") | ||
class TestGraphQLApiPipelineResolver(BaseTest): | ||
def test_api(self): | ||
file_name = "combination/graphqlapi_lambda_resolver" | ||
self.create_and_verify_stack(file_name) | ||
|
||
outputs = self.get_stack_outputs() | ||
|
||
author = "AUTHORNAME" | ||
title = "Our first post!" | ||
content = "This is our first post." | ||
|
||
query = f""" | ||
mutation addPost {{ | ||
addPost( | ||
id: 100 | ||
author: "{author}" | ||
title: "{title}" | ||
content: "{content}" | ||
) {{ | ||
id | ||
author | ||
title | ||
content | ||
}} | ||
}} | ||
""" | ||
|
||
url = outputs["SuperCoolAPI"] | ||
api_key = outputs["SuperCoolAPIMyApiKey"] | ||
|
||
response = execute_and_verify_appsync_query(url, api_key, query) | ||
|
||
add_post = response["data"]["addPost"] | ||
|
||
self.assertEqual(add_post["id"], "100") | ||
self.assertEqual(add_post["author"], author) | ||
self.assertEqual(add_post["title"], title) | ||
self.assertEqual(add_post["content"], content) | ||
|
||
query = """ | ||
query getPost { | ||
getPost(id:"1") { | ||
id | ||
author | ||
title | ||
content | ||
ups | ||
downs | ||
} | ||
} | ||
""" | ||
|
||
response = execute_and_verify_appsync_query(url, api_key, query) | ||
|
||
get_post = response["data"]["getPost"] | ||
|
||
# These values are hardcoded inside the Lambda function for a post with id "1". | ||
author = "Author1" | ||
title = "First book" | ||
content = "Book 1 has this content" | ||
ups = 100 | ||
downs = 10 | ||
|
||
self.assertEqual(get_post["id"], "1") | ||
self.assertEqual(get_post["author"], author) | ||
self.assertEqual(get_post["title"], title) | ||
self.assertEqual(get_post["content"], content) | ||
self.assertEqual(get_post["ups"], ups) | ||
self.assertEqual(get_post["downs"], downs) |
101 changes: 101 additions & 0 deletions
101
integration/combination/test_graphqlapi_pipeline_resolver.py
This file contains 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,101 @@ | ||
import json | ||
from unittest.case import skipIf | ||
|
||
import requests | ||
|
||
from integration.config.service_names import APP_SYNC | ||
from integration.helpers.base_test import BaseTest | ||
from integration.helpers.resource import current_region_does_not_support | ||
|
||
|
||
def execute_and_verify_appsync_query(url, api_key, query): | ||
""" | ||
Executes a query to an AppSync GraphQLApi. | ||
Also checks that the response is 200 and does not contain errors before returning. | ||
""" | ||
headers = { | ||
"Content-Type": "application/json", | ||
"x-api-key": api_key, | ||
} | ||
payload = {"query": query} | ||
|
||
response = requests.post(url, json=payload, headers=headers) | ||
response.raise_for_status() | ||
data = response.json() | ||
if "errors" in data: | ||
raise Exception(json.dumps(data["errors"])) | ||
|
||
return data | ||
|
||
|
||
@skipIf(current_region_does_not_support([APP_SYNC]), "AppSync is not supported in this testing region") | ||
class TestGraphQLApiPipelineResolver(BaseTest): | ||
def test_api(self): | ||
file_name = "combination/graphqlapi_pipeline_resolver" | ||
self.create_and_verify_stack(file_name) | ||
|
||
outputs = self.get_stack_outputs() | ||
|
||
author = "AUTHORNAME" | ||
title = "Our first post!" | ||
content = "This is our first post." | ||
|
||
query = f""" | ||
mutation addPost {{ | ||
addPost( | ||
author: "{author}" | ||
title: "{title}" | ||
content: "{content}" | ||
) {{ | ||
id | ||
author | ||
title | ||
content | ||
ups | ||
downs | ||
version | ||
}} | ||
}} | ||
""" | ||
|
||
url = outputs["SuperCoolAPI"] | ||
api_key = outputs["MyApiKey"] | ||
|
||
response = execute_and_verify_appsync_query(url, api_key, query) | ||
|
||
add_post = response["data"]["addPost"] | ||
|
||
self.assertEqual(add_post["author"], author) | ||
self.assertEqual(add_post["title"], title) | ||
self.assertEqual(add_post["content"], content) | ||
self.assertEqual(add_post["ups"], 1) | ||
self.assertEqual(add_post["downs"], 0) | ||
self.assertEqual(add_post["version"], 1) | ||
|
||
post_id = add_post["id"] | ||
query = f""" | ||
query getPost {{ | ||
getPost(id:"{post_id}") {{ | ||
id | ||
author | ||
title | ||
content | ||
ups | ||
downs | ||
version | ||
}} | ||
}} | ||
""" | ||
|
||
response = execute_and_verify_appsync_query(url, api_key, query) | ||
|
||
get_post = response["data"]["getPost"] | ||
|
||
self.assertEqual(get_post["author"], author) | ||
self.assertEqual(get_post["title"], title) | ||
self.assertEqual(get_post["content"], content) | ||
self.assertEqual(get_post["ups"], 1) | ||
self.assertEqual(get_post["downs"], 0) | ||
self.assertEqual(get_post["version"], 1) | ||
self.assertEqual(get_post["id"], post_id) |
This file contains 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
This file contains 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
Oops, something went wrong.