-
Notifications
You must be signed in to change notification settings - Fork 49
/
conftest.py
38 lines (31 loc) · 1.44 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
from pytest_factoryboy import register
import pytest
from rest_framework.test import APIClient
from accounts.factories import AccountFactory
from events.factories import CategoryFactory, EventFactory
from comments.factories import CommentFactory
register(AccountFactory, 'account')
register(CategoryFactory, 'category')
register(EventFactory, 'event')
register(CommentFactory, 'comment')
@pytest.fixture
def authenticated_user(client, account):
"""Create an authenticated user for a test"""
# user = G(User, email='[email protected]')
account.email = '[email protected]'
account.set_password('my_password123')
account.save()
client.login(email='[email protected]', password='my_password123')
return account
@pytest.fixture
def authenticated():
client = APIClient()
client.post('http://127.0.0.1:8000/auth/users/', data={"first_name": "iyanu",
"last_name": "ajao",
"email": "[email protected]",
"password": "decagon1234"})
response = client.post('http://127.0.0.1:8000/auth/token/login/', data={"password": "decagon1234",
"email": "[email protected]"})
auth_token = response.data['auth_token']
client.credentials(HTTP_AUTHORIZATION='Token ' + auth_token)
return client