Skip to content

Commit 1ceecf7

Browse files
author
Michal Ploski
committed
Fix linter checks
1 parent 1937849 commit 1ceecf7

File tree

4 files changed

+30
-32
lines changed

4 files changed

+30
-32
lines changed

tests/e2e/event_handler/files/schema.graphql

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ schema {
33
}
44

55
type Query {
6-
getPost(id:ID!): Post
6+
getPost(post_id:ID!): Post
77
allPosts: [Post]
88
}
99

1010
type Post {
11-
id: ID!
11+
post_id: ID!
1212
author: String!
1313
title: String
1414
content: String

tests/e2e/event_handler/handlers/appsync_resolver_handler.py

+15-16
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
from typing import List
22

3+
from pydantic import BaseModel
34

45
from aws_lambda_powertools.event_handler import AppSyncResolver
56
from aws_lambda_powertools.utilities.typing import LambdaContext
6-
from pydantic import BaseModel
77

88
app = AppSyncResolver()
99

1010

1111
posts = {
1212
"1": {
13-
"id": "1",
13+
"post_id": "1",
1414
"title": "First book",
1515
"author": "Author1",
1616
"url": "https://amazon.com/",
17-
"content": "SAMPLE TEXT AUTHOR 1 SAMPLE TEXT AUTHOR 1 SAMPLE TEXT AUTHOR 1 SAMPLE TEXT AUTHOR 1 SAMPLE TEXT AUTHOR 1 SAMPLE TEXT AUTHOR 1",
17+
"content": "SAMPLE TEXT AUTHOR 1",
1818
"ups": "100",
1919
"downs": "10",
2020
},
2121
"2": {
22-
"id": "2",
22+
"post_id": "2",
2323
"title": "Second book",
2424
"author": "Author2",
2525
"url": "https://amazon.com",
26-
"content": "SAMPLE TEXT AUTHOR 2 SAMPLE TEXT AUTHOR 2 SAMPLE TEXT",
26+
"content": "SAMPLE TEXT AUTHOR 2",
2727
"ups": "100",
2828
"downs": "10",
2929
},
3030
"3": {
31-
"id": "3",
31+
"post_id": "3",
3232
"title": "Third book",
3333
"author": "Author3",
3434
"url": None,
@@ -37,20 +37,20 @@
3737
"downs": None,
3838
},
3939
"4": {
40-
"id": "4",
40+
"post_id": "4",
4141
"title": "Fourth book",
4242
"author": "Author4",
4343
"url": "https://www.amazon.com/",
44-
"content": "SAMPLE TEXT AUTHOR 4 SAMPLE TEXT AUTHOR 4 SAMPLE TEXT AUTHOR 4 SAMPLE TEXT AUTHOR 4 SAMPLE TEXT AUTHOR 4 SAMPLE TEXT AUTHOR 4 SAMPLE TEXT AUTHOR 4 SAMPLE TEXT AUTHOR 4",
44+
"content": "SAMPLE TEXT AUTHOR 4",
4545
"ups": "1000",
4646
"downs": "0",
4747
},
4848
"5": {
49-
"id": "5",
49+
"post_id": "5",
5050
"title": "Fifth book",
5151
"author": "Author5",
5252
"url": "https://www.amazon.com/",
53-
"content": "SAMPLE TEXT AUTHOR 5 SAMPLE TEXT AUTHOR 5 SAMPLE TEXT AUTHOR 5 SAMPLE TEXT AUTHOR 5 SAMPLE TEXT",
53+
"content": "SAMPLE TEXT AUTHOR 5",
5454
"ups": "50",
5555
"downs": "0",
5656
},
@@ -66,7 +66,7 @@
6666

6767

6868
class Post(BaseModel):
69-
id: str
69+
post_id: str
7070
author: str
7171
title: str
7272
url: str
@@ -76,23 +76,22 @@ class Post(BaseModel):
7676

7777

7878
@app.resolver(type_name="Query", field_name="getPost")
79-
def get_post(id: str = "") -> dict:
80-
post = Post(**posts[id]).dict()
79+
def get_post(post_id: str = "") -> dict:
80+
post = Post(**posts[post_id]).dict()
8181
return post
8282

8383

8484
@app.resolver(type_name="Query", field_name="allPosts")
8585
def all_posts() -> List[dict]:
86-
parsed_posts = [post for post in posts.values()]
87-
return parsed_posts
86+
return list(posts.values())
8887

8988

9089
@app.resolver(type_name="Post", field_name="relatedPosts")
9190
def related_posts() -> List[dict]:
9291
posts = []
9392
for resolver_event in app.current_event:
9493
if resolver_event.source:
95-
posts.append(posts_related[resolver_event.source["id"]])
94+
posts.append(posts_related[resolver_event.source["post_id"]])
9695
return posts
9796

9897

tests/e2e/event_handler/infrastructure.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
from aws_cdk import aws_apigatewayv2_alpha as apigwv2
77
from aws_cdk import aws_apigatewayv2_authorizers_alpha as apigwv2authorizers
88
from aws_cdk import aws_apigatewayv2_integrations_alpha as apigwv2integrations
9+
from aws_cdk import aws_appsync_alpha as appsync
910
from aws_cdk import aws_ec2 as ec2
1011
from aws_cdk import aws_elasticloadbalancingv2 as elbv2
1112
from aws_cdk import aws_elasticloadbalancingv2_targets as targets
12-
from aws_cdk import aws_appsync_alpha as appsync
13-
from aws_cdk import aws_iam
1413
from aws_cdk.aws_lambda import Function, FunctionUrlAuthType
1514

1615
from tests.e2e.utils.infrastructure import BaseInfrastructure
@@ -20,10 +19,10 @@ class EventHandlerStack(BaseInfrastructure):
2019
def create_resources(self):
2120
functions = self.create_lambda_functions()
2221

23-
# self._create_alb(function=functions["AlbHandler"])
24-
# self._create_api_gateway_rest(function=functions["ApiGatewayRestHandler"])
25-
# self._create_api_gateway_http(function=functions["ApiGatewayHttpHandler"])
26-
# self._create_lambda_function_url(function=functions["LambdaFunctionUrlHandler"])
22+
self._create_alb(function=functions["AlbHandler"])
23+
self._create_api_gateway_rest(function=functions["ApiGatewayRestHandler"])
24+
self._create_api_gateway_http(function=functions["ApiGatewayHttpHandler"])
25+
self._create_lambda_function_url(function=functions["LambdaFunctionUrlHandler"])
2726
self._create_appsync_endpoint(function=functions["AppsyncResolverHandler"])
2827

2928
def _create_alb(self, function: Function):

tests/e2e/event_handler/test_appsync_resolvers.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import json
2+
23
import pytest
3-
from requests import HTTPError, Request
4+
from requests import Request
45

56
from tests.e2e.utils import data_fetcher
6-
from tests.e2e.utils.auth import build_iam_auth
77

88

99
@pytest.fixture
@@ -20,7 +20,7 @@ def appsync_access_key(infrastructure: dict) -> str:
2020
def test_appsync_get_all_posts(appsync_endpoint, appsync_access_key):
2121
# GIVEN
2222
body = {
23-
"query": "query MyQuery { allPosts { id }}",
23+
"query": "query MyQuery { allPosts { post_id }}",
2424
"variables": None,
2525
"operationName": "MyQuery",
2626
}
@@ -50,7 +50,7 @@ def test_appsync_get_post(appsync_endpoint, appsync_access_key):
5050
# GIVEN
5151
post_id = "1"
5252
body = {
53-
"query": f'query MyQuery {{ getPost(id: "{post_id}") {{ id }} }}',
53+
"query": f'query MyQuery {{ getPost(post_id: "{post_id}") {{ post_id }} }}',
5454
"variables": None,
5555
"operationName": "MyQuery",
5656
}
@@ -71,7 +71,7 @@ def test_appsync_get_post(appsync_endpoint, appsync_access_key):
7171

7272
data = json.loads(response.content.decode("ascii"))["data"]
7373

74-
assert data["getPost"]["id"] == post_id
74+
assert data["getPost"]["post_id"] == post_id
7575

7676

7777
@pytest.mark.xdist_group(name="event_handler")
@@ -81,7 +81,7 @@ def test_appsync_get_related_posts_batch(appsync_endpoint, appsync_access_key):
8181
related_posts_ids = ["3", "5"]
8282

8383
body = {
84-
"query": f'query MyQuery {{ getPost(id: "{post_id}") {{ id relatedPosts {{ id }} }} }}',
84+
"query": f'query MyQuery {{ getPost(post_id: "{post_id}") {{ post_id relatedPosts {{ post_id }} }} }}',
8585
"variables": None,
8686
"operationName": "MyQuery",
8787
}
@@ -102,7 +102,7 @@ def test_appsync_get_related_posts_batch(appsync_endpoint, appsync_access_key):
102102

103103
data = json.loads(response.content.decode("ascii"))["data"]
104104

105-
assert data["getPost"]["id"] == post_id
105+
assert data["getPost"]["post_id"] == post_id
106106
assert len(data["getPost"]["relatedPosts"]) == len(related_posts_ids)
107107
for post in data["getPost"]["relatedPosts"]:
108-
assert post["id"] in related_posts_ids
108+
assert post["post_id"] in related_posts_ids

0 commit comments

Comments
 (0)