graphene/tests_asyncio/test_subscribe.py

35 lines
672 B
Python
Raw Normal View History

from pytest import mark
2020-07-11 15:41:47 +03:00
from graphene import ObjectType, Int, String, Schema
2020-07-11 15:37:18 +03:00
class Query(ObjectType):
2020-07-11 13:51:04 +03:00
a = String()
2020-07-11 13:51:04 +03:00
class Subscription(ObjectType):
2020-07-12 14:45:31 +03:00
count_to_ten = Int()
2020-07-12 14:45:31 +03:00
async def subscribe_count_to_ten(root, info):
count = 0
while count < 10:
count += 1
2020-07-11 15:37:18 +03:00
yield count
2020-07-12 14:45:31 +03:00
schema = Schema(query=Query, subscription=Subscription)
@mark.asyncio
async def test_subscription():
2020-07-11 15:37:18 +03:00
subscription = """
subscription {
countToTen
}
"""
result = await schema.subscribe(subscription)
count = 0
async for item in result:
count = item.data["countToTen"]
assert count == 10