-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
44 lines (38 loc) · 1.43 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
# pylint: disable=wildcard-import, unused-wildcard-import
from unittest.mock import Mock, patch
import pytest
from fixtures.common import * # noqa: F403
from fixtures.users import * # noqa: F403
from unified_ecommerce.exceptions import DoNotUseRequestException
@pytest.fixture(autouse=True)
def mock_requests_get():
# Mock the response of requests.get
with patch("system_meta.tasks.requests.get") as mock_get:
# Create a mock response object
mock_response = Mock()
mock_response.raise_for_status = Mock() # Mock the raise_for_status method
mock_response.json.return_value = {
"results": [
{
"image": {
"url": "http://example.com/image.jpg",
"alt": "Image alt text",
"description": "Image description",
}
}
]
}
mock_get.return_value = (
mock_response # Set the mock response to be returned by requests.get
)
yield mock_get # This will be the mocked requests.get
@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,
)