Skip to content

Commit

Permalink
Fix linter checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Ploski committed Mar 10, 2023
1 parent e3ca8c5 commit ccdbbea
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 32 deletions.
4 changes: 2 additions & 2 deletions tests/e2e/event_handler/files/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ schema {
}

type Query {
getPost(id:ID!): Post
getPost(post_id:ID!): Post
allPosts: [Post]
}

type Post {
id: ID!
post_id: ID!
author: String!
title: String
content: String
Expand Down
31 changes: 15 additions & 16 deletions tests/e2e/event_handler/handlers/appsync_resolver_handler.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
from typing import List

from pydantic import BaseModel

from aws_lambda_powertools.event_handler import AppSyncResolver
from aws_lambda_powertools.utilities.typing import LambdaContext
from pydantic import BaseModel

app = AppSyncResolver()


posts = {
"1": {
"id": "1",
"post_id": "1",
"title": "First book",
"author": "Author1",
"url": "https://amazon.com/",
"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",
"content": "SAMPLE TEXT AUTHOR 1",
"ups": "100",
"downs": "10",
},
"2": {
"id": "2",
"post_id": "2",
"title": "Second book",
"author": "Author2",
"url": "https://amazon.com",
"content": "SAMPLE TEXT AUTHOR 2 SAMPLE TEXT AUTHOR 2 SAMPLE TEXT",
"content": "SAMPLE TEXT AUTHOR 2",
"ups": "100",
"downs": "10",
},
"3": {
"id": "3",
"post_id": "3",
"title": "Third book",
"author": "Author3",
"url": None,
Expand All @@ -37,20 +37,20 @@
"downs": None,
},
"4": {
"id": "4",
"post_id": "4",
"title": "Fourth book",
"author": "Author4",
"url": "https://www.amazon.com/",
"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",
"content": "SAMPLE TEXT AUTHOR 4",
"ups": "1000",
"downs": "0",
},
"5": {
"id": "5",
"post_id": "5",
"title": "Fifth book",
"author": "Author5",
"url": "https://www.amazon.com/",
"content": "SAMPLE TEXT AUTHOR 5 SAMPLE TEXT AUTHOR 5 SAMPLE TEXT AUTHOR 5 SAMPLE TEXT AUTHOR 5 SAMPLE TEXT",
"content": "SAMPLE TEXT AUTHOR 5",
"ups": "50",
"downs": "0",
},
Expand All @@ -66,7 +66,7 @@


class Post(BaseModel):
id: str
post_id: str
author: str
title: str
url: str
Expand All @@ -76,23 +76,22 @@ class Post(BaseModel):


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


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


@app.resolver(type_name="Post", field_name="relatedPosts")
def related_posts() -> List[dict]:
posts = []
for resolver_event in app.current_event:
if resolver_event.source:
posts.append(posts_related[resolver_event.source["id"]])
posts.append(posts_related[resolver_event.source["post_id"]])
return posts


Expand Down
11 changes: 5 additions & 6 deletions tests/e2e/event_handler/infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
from aws_cdk import aws_apigatewayv2_alpha as apigwv2
from aws_cdk import aws_apigatewayv2_authorizers_alpha as apigwv2authorizers
from aws_cdk import aws_apigatewayv2_integrations_alpha as apigwv2integrations
from aws_cdk import aws_appsync_alpha as appsync
from aws_cdk import aws_ec2 as ec2
from aws_cdk import aws_elasticloadbalancingv2 as elbv2
from aws_cdk import aws_elasticloadbalancingv2_targets as targets
from aws_cdk import aws_appsync_alpha as appsync
from aws_cdk import aws_iam
from aws_cdk.aws_lambda import Function, FunctionUrlAuthType

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

# self._create_alb(function=functions["AlbHandler"])
# self._create_api_gateway_rest(function=functions["ApiGatewayRestHandler"])
# self._create_api_gateway_http(function=functions["ApiGatewayHttpHandler"])
# self._create_lambda_function_url(function=functions["LambdaFunctionUrlHandler"])
self._create_alb(function=functions["AlbHandler"])
self._create_api_gateway_rest(function=functions["ApiGatewayRestHandler"])
self._create_api_gateway_http(function=functions["ApiGatewayHttpHandler"])
self._create_lambda_function_url(function=functions["LambdaFunctionUrlHandler"])
self._create_appsync_endpoint(function=functions["AppsyncResolverHandler"])

def _create_alb(self, function: Function):
Expand Down
16 changes: 8 additions & 8 deletions tests/e2e/event_handler/test_appsync_resolvers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import json

import pytest
from requests import HTTPError, Request
from requests import Request

from tests.e2e.utils import data_fetcher
from tests.e2e.utils.auth import build_iam_auth


@pytest.fixture
Expand All @@ -20,7 +20,7 @@ def appsync_access_key(infrastructure: dict) -> str:
def test_appsync_get_all_posts(appsync_endpoint, appsync_access_key):
# GIVEN
body = {
"query": "query MyQuery { allPosts { id }}",
"query": "query MyQuery { allPosts { post_id }}",
"variables": None,
"operationName": "MyQuery",
}
Expand Down Expand Up @@ -50,7 +50,7 @@ def test_appsync_get_post(appsync_endpoint, appsync_access_key):
# GIVEN
post_id = "1"
body = {
"query": f'query MyQuery {{ getPost(id: "{post_id}") {{ id }} }}',
"query": f'query MyQuery {{ getPost(post_id: "{post_id}") {{ post_id }} }}',
"variables": None,
"operationName": "MyQuery",
}
Expand All @@ -71,7 +71,7 @@ def test_appsync_get_post(appsync_endpoint, appsync_access_key):

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

assert data["getPost"]["id"] == post_id
assert data["getPost"]["post_id"] == post_id


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

body = {
"query": f'query MyQuery {{ getPost(id: "{post_id}") {{ id relatedPosts {{ id }} }} }}',
"query": f'query MyQuery {{ getPost(post_id: "{post_id}") {{ post_id relatedPosts {{ post_id }} }} }}',
"variables": None,
"operationName": "MyQuery",
}
Expand All @@ -102,7 +102,7 @@ def test_appsync_get_related_posts_batch(appsync_endpoint, appsync_access_key):

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

assert data["getPost"]["id"] == post_id
assert data["getPost"]["post_id"] == post_id
assert len(data["getPost"]["relatedPosts"]) == len(related_posts_ids)
for post in data["getPost"]["relatedPosts"]:
assert post["id"] in related_posts_ids
assert post["post_id"] in related_posts_ids

0 comments on commit ccdbbea

Please sign in to comment.