-
Notifications
You must be signed in to change notification settings - Fork 6
/
conftest.py
73 lines (55 loc) · 1.7 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""Top level conftest module."""
import json
import pytest
from django.urls import reverse
from graphene_django.utils import testing
from django.contrib.auth import get_user_model
@pytest.fixture
def user():
user = get_user_model().objects.create_user(email='[email protected]', password='Lyrid123',
first_name='Support', is_active=True)
"""Return a db user."""
return user
@pytest.fixture
def superuser():
user = get_user_model().objects.create_user(email='[email protected]', password='Lyrid123',
first_name='Support-SU', is_active=True, is_staff=True)
"""Return a db super user."""
return user
@pytest.fixture
def graphql_query(client):
"""Return a client query fn without logged-in user."""
def func(*args, **kwargs):
return testing.graphql_query(
*args,
**kwargs,
client=client,
graphql_url=reverse("graphql"),
)
return func
@pytest.fixture
def graphql_query_user(client, user):
"""Return a client query fn."""
def func(*args, **kwargs):
return testing.graphql_query(
*args,
**kwargs,
client=client,
graphql_url=reverse("graphql"),
)
client.force_login(user)
return func
@pytest.fixture
def json_loads():
"""Return json loads."""
return json.loads
@pytest.fixture
def user_client(client, user):
"""Return logged in client."""
client.force_login(user)
return client
@pytest.fixture
def superuser_client(client, superuser):
"""Return logged in superuser client."""
client.force_login(superuser)
return client