-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconftest.py
80 lines (59 loc) · 1.76 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
74
75
76
77
78
79
80
from pathlib import Path
import pytest
from allauth.account.models import EmailAddress
from django.contrib.auth.models import User
from rest_framework.test import APIClient
from rest_framework.authtoken.models import Token
USERNAME = 'qabel_user'
ADMIN = 'qabel_admin'
@pytest.fixture()
def tests_output_path():
output_path = Path(__file__).absolute().parent / 'test-output'
output_path.mkdir(exist_ok=True)
return output_path
@pytest.fixture
def user(db):
try:
u = User.objects.get(username=USERNAME)
except User.DoesNotExist:
u = User.objects.create_user(USERNAME, '[email protected]',
'password')
u.is_staff = False
u.is_superuser = False
u.save()
EmailAddress.objects.create(user=u, email=u.email, primary=True)
return u
@pytest.fixture
def admin(db):
try:
u = User.objects.get(username=ADMIN)
except User.DoesNotExist:
u = User.objects.create_user(USERNAME, '[email protected]',
'password')
u.is_staff = True
u.is_superuser = True
u.save()
EmailAddress.objects.create(user=u, email=u.email, primary=True)
return u
@pytest.fixture
def profile(user):
return user.profile
@pytest.fixture
def token(user):
return Token.objects.create(user=user).key
@pytest.fixture
def api_client():
return APIClient()
@pytest.fixture
def api_secret(settings):
secret = "FOOBAR"
settings.API_SECRET = secret
return secret
@pytest.fixture
def user_client(api_client, user):
api_client.force_authenticate(user)
return api_client
@pytest.fixture
def external_api_client(user, api_secret):
client = APIClient(HTTP_APISECRET=api_secret)
return client