-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconftest.py
48 lines (39 loc) · 1.37 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
"""Project conftest"""
# pylint: disable=wildcard-import, unused-wildcard-import
from types import SimpleNamespace
import pytest
from fixtures.common import * # noqa: F403
from fixtures.users import * # noqa: F403
from main.exceptions import DoNotUseRequestException
@pytest.fixture(autouse=True)
def prevent_requests(mocker, request): # noqa: PT004
"""Patch requests to error on request by default"""
if "mocked_responses" in request.fixturenames:
return
mocker.patch(
"requests.sessions.Session.request",
autospec=True,
side_effect=DoNotUseRequestException,
)
@pytest.fixture(autouse=True)
def _use_dummy_redis_cache_backend(settings):
new_cache_settings = settings.CACHES.copy()
new_cache_settings["redis"] = {
"BACKEND": "django.core.cache.backends.dummy.DummyCache",
}
settings.CACHES = new_cache_settings
@pytest.fixture
def mock_http_consumer_send(mocker):
"""Mock the AsyncHttpConsumer class send functions"""
mock_send_body = mocker.patch(
"channels.generic.http.AsyncHttpConsumer.send_body",
new_callable=mocker.AsyncMock,
)
mock_send_headers = mocker.patch(
"channels.generic.http.AsyncHttpConsumer.send_headers",
new_callable=mocker.AsyncMock,
)
return SimpleNamespace(
send_body=mock_send_body,
send_headers=mock_send_headers,
)