-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathconftest.py
56 lines (40 loc) · 1.17 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from urllib.parse import urlencode
from aiohttp import web
import aiohttp.test_utils
from graphql.execution.executors.asyncio import AsyncioExecutor
import pytest
from aiohttp_graphql import GraphQLView
# pylint: disable=redefined-outer-name
# GraphQL Fixtures
@pytest.fixture(params=[True, False], ids=['async', 'sync'])
def executor(request, event_loop):
if request.param:
return AsyncioExecutor(event_loop)
return None
# GraphQLView Fixtures
@pytest.fixture
def view_kwargs():
return {}
# aiohttp Fixtures
@pytest.fixture
def app(executor, view_kwargs):
app = web.Application()
GraphQLView.attach(app, executor=executor, **view_kwargs)
return app
@pytest.fixture
async def client(event_loop, app):
client = aiohttp.test_utils.TestClient(aiohttp.test_utils.TestServer(app), loop=event_loop)
await client.start_server()
yield client
await client.close()
# URL Fixtures
@pytest.fixture
def base_url():
return '/graphql'
@pytest.fixture
def url_builder(base_url):
def builder(**url_params):
if url_params:
return '{}?{}'.format(base_url, urlencode(url_params))
return base_url
return builder