-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconftest.py
More file actions
65 lines (49 loc) · 1.55 KB
/
conftest.py
File metadata and controls
65 lines (49 loc) · 1.55 KB
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
from urllib.parse import urlencode
import pytest
from django.test import override_settings
from faker import Faker
from rest_framework.test import APIRequestFactory, APIClient
# Imports all fixtures imported into in test_fixtures/__init__.py
from test_fixtures import *
@pytest.fixture
def client():
return APIClient()
@pytest.fixture
def debug_mode_on():
with override_settings(DEBUG=True):
yield
@pytest.fixture
def enable_auth():
with override_settings(DISABLE_AUTH=False):
yield
@pytest.fixture
def request_builder():
def _request_builder(
method, path, data=None, query_params=None, meta=None, format_="json"
):
"""
Fixture for easily building requests
:param method: HTTP method
:param path: request path
:param data: request body
:param query_params: dictionary that is encoded into query string
:param meta: dictionary that modifies META request headers
:param format_: api request format
:return: django.core.handlers.wsgi.WSGIRequest
"""
request = getattr(APIRequestFactory(), method.lower())(
path,
data=data,
QUERY_STRING=urlencode(query_params, True) if query_params else None,
format=format_,
)
# Reconcile Django vs DRF differences
request.query_params = request.GET
request.data = data
if meta:
request.META.update(meta)
return request
return _request_builder
@pytest.fixture
def fake():
return Faker()