-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconftest.py
72 lines (55 loc) · 1.8 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
import pytest
from rest_framework.test import APIClient
from authors.apps.authentication.backends import JWTAuthentication
from authors.apps.authentication.tests.factories.authentication import \
(UserFactory2, ProfileFactory, FollowerFactory)
@pytest.fixture()
def test_user(db):
"""create a sample user"""
user = UserFactory2()
yield user
@pytest.fixture()
def test_user2(db):
"""create a sample user"""
user = UserFactory2()
yield user
@pytest.fixture()
def test_profile(db, test_user):
"""create a sample user profile"""
profile = ProfileFactory(user=test_user)
yield profile
@pytest.fixture()
def test_profile2(db, test_user2):
"""create a sample user profile"""
profile = ProfileFactory(user=test_user2)
yield profile
@pytest.fixture()
def test_following_relation(db, test_user, test_user2):
"""def test follower relationship"""
following = FollowerFactory(follower=test_user, followed=test_user2)
yield following
@pytest.fixture()
def test_reversed_following_relation(db, test_user, test_user2):
"""def test follower relationship"""
following = FollowerFactory(follower=test_user2, followed=test_user)
yield following
@pytest.fixture()
def test_client():
"""
a session wide client to test application endpoints
:return test_client:
"""
# a drf api client instance is returned
client = APIClient()
yield client # yield the fixture value
@pytest.fixture()
def test_auth_client(test_user):
"""
a session wide client to test protected application endpoints
:return client:
"""
token = JWTAuthentication.generate_token(test_user)
# a drf api client instance is returned
client = APIClient()
client.credentials(HTTP_AUTHORIZATION='Token ' + token)
yield client # yield the fixture value