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