Skip to content

Commit 87fb848

Browse files
author
Michael Brewer
committed
tests(data-clasess): Verify async and yield works
1 parent 7c5b6e9 commit 87fb848

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/functional/appsync/test_appsync_resolver_utils.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import datetime
23
import json
34
import os
@@ -126,6 +127,43 @@ def test_resolver_value_error():
126127
assert exp.value.args[0] == "No resolver found for 'type.field'"
127128

128129

130+
def test_resolver_yield():
131+
# GIVEN
132+
app = AppSyncResolver()
133+
134+
mock_event = {"typeName": "Customer", "fieldName": "field", "arguments": {}}
135+
136+
@app.resolver(field_name="field")
137+
def func_yield():
138+
yield "value"
139+
140+
# WHEN
141+
mock_context = LambdaContext()
142+
result = app.resolve(mock_event, mock_context)
143+
144+
# THEN
145+
assert next(result) == "value"
146+
147+
148+
def test_resolver_async():
149+
# GIVEN
150+
app = AppSyncResolver()
151+
152+
mock_event = {"typeName": "Customer", "fieldName": "field", "arguments": {}}
153+
154+
@app.resolver(field_name="field")
155+
async def get_async():
156+
await asyncio.sleep(0.0001)
157+
return "value"
158+
159+
# WHEN
160+
mock_context = LambdaContext()
161+
result = app.resolve(mock_event, mock_context)
162+
163+
# THEN
164+
assert asyncio.run(result) == "value"
165+
166+
129167
def test_make_id():
130168
uuid: str = make_id()
131169
assert isinstance(uuid, str)

0 commit comments

Comments
 (0)