-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconftest.py
75 lines (47 loc) · 1.87 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
import pytest
from django.contrib.auth.models import User
from model_bakery import baker
from rest_framework.test import APIClient
@pytest.fixture
def api_client():
return APIClient()
@pytest.fixture
def authenticate(api_client):
"""For authenticating normal and admin user"""
def inner_authenticate(is_staff=False):
return api_client.force_authenticate(user=User(is_staff=is_staff))
return inner_authenticate
# we are using same user for authentication and for performing operation in review
@pytest.fixture
def request_authenticate(api_client):
"""For authentication and for request"""
def inner_request_authenticate(user):
return api_client.force_authenticate(user=user)
return inner_request_authenticate
@pytest.fixture
def send_post_request(api_client):
"""For sending POST request to particular endpoint with particular data"""
def inner_send_post_request(endpoint: str, data: dict):
return api_client.post(endpoint, data)
return inner_send_post_request
@pytest.fixture
def send_patch_request(api_client):
"""For sending PATCH request to particular endpoint with particular data"""
def inner_send_patch_request(endpoint: str, data: dict):
return api_client.patch(endpoint, data)
return inner_send_patch_request
@pytest.fixture
def send_put_request(api_client):
"""For sending PUT request to particular endpoint with particular data"""
def inner_send_put_request(endpoint: str, data: dict):
return api_client.put(endpoint, data)
return inner_send_put_request
@pytest.fixture
def send_delete_request(api_client):
"""For sending DELETE request to particular endpoint with particular data"""
def inner_send_delete_request(endpoint: str):
return api_client.delete(endpoint)
return inner_send_delete_request
@pytest.fixture
def user():
return baker.make(User)