Leave the global responses configuration alone (#3529)
Instead of modifying responses._default_mock, create our own responses.RequestsMock object that we can modify as needed without interfering with other users of the responses library. Fixes #3264. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
parent
c8151e1bb4
commit
8befcb6a48
@ -41,6 +41,7 @@ from .exceptions import (
|
|||||||
RestAPINotFound,
|
RestAPINotFound,
|
||||||
ModelNotFound,
|
ModelNotFound,
|
||||||
)
|
)
|
||||||
|
from ..core.models import responses_mock
|
||||||
|
|
||||||
STAGE_URL = "https://{api_id}.execute-api.{region_name}.amazonaws.com/{stage_name}"
|
STAGE_URL = "https://{api_id}.execute-api.{region_name}.amazonaws.com/{stage_name}"
|
||||||
|
|
||||||
@ -565,7 +566,7 @@ class RestAPI(BaseModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
for url in [stage_url_lower, stage_url_upper]:
|
for url in [stage_url_lower, stage_url_upper]:
|
||||||
responses._default_mock._matches.insert(
|
responses_mock._matches.insert(
|
||||||
0,
|
0,
|
||||||
responses.CallbackResponse(
|
responses.CallbackResponse(
|
||||||
url=url,
|
url=url,
|
||||||
|
@ -248,7 +248,7 @@ botocore_mock = responses.RequestsMock(
|
|||||||
target="botocore.vendored.requests.adapters.HTTPAdapter.send",
|
target="botocore.vendored.requests.adapters.HTTPAdapter.send",
|
||||||
)
|
)
|
||||||
|
|
||||||
responses_mock = responses._default_mock
|
responses_mock = responses.RequestsMock(assert_all_requests_are_fired=False)
|
||||||
# Add passthrough to allow any other requests to work
|
# Add passthrough to allow any other requests to work
|
||||||
# Since this uses .startswith, it applies to http and https requests.
|
# Since this uses .startswith, it applies to http and https requests.
|
||||||
responses_mock.add_passthru("http")
|
responses_mock.add_passthru("http")
|
||||||
|
@ -8,9 +8,9 @@ import requests
|
|||||||
import sure # noqa
|
import sure # noqa
|
||||||
from botocore.exceptions import ClientError
|
from botocore.exceptions import ClientError
|
||||||
|
|
||||||
import responses
|
|
||||||
from moto import mock_apigateway, mock_cognitoidp, settings
|
from moto import mock_apigateway, mock_cognitoidp, settings
|
||||||
from moto.core import ACCOUNT_ID
|
from moto.core import ACCOUNT_ID
|
||||||
|
from moto.core.models import responses_mock
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
@ -1786,8 +1786,8 @@ def test_get_model_with_invalid_name():
|
|||||||
|
|
||||||
@mock_apigateway
|
@mock_apigateway
|
||||||
def test_http_proxying_integration():
|
def test_http_proxying_integration():
|
||||||
responses.add(
|
responses_mock.add(
|
||||||
responses.GET, "http://httpbin.org/robots.txt", body="a fake response"
|
responses_mock.GET, "http://httpbin.org/robots.txt", body="a fake response"
|
||||||
)
|
)
|
||||||
|
|
||||||
region_name = "us-west-2"
|
region_name = "us-west-2"
|
||||||
|
@ -8,11 +8,11 @@ import re
|
|||||||
from freezegun import freeze_time
|
from freezegun import freeze_time
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
|
|
||||||
import responses
|
|
||||||
from botocore.exceptions import ClientError
|
from botocore.exceptions import ClientError
|
||||||
import pytest
|
import pytest
|
||||||
from moto import mock_sns, mock_sqs, settings
|
from moto import mock_sns, mock_sqs, settings
|
||||||
from moto.core import ACCOUNT_ID
|
from moto.core import ACCOUNT_ID
|
||||||
|
from moto.core.models import responses_mock
|
||||||
from moto.sns import sns_backend
|
from moto.sns import sns_backend
|
||||||
|
|
||||||
MESSAGE_FROM_SQS_TEMPLATE = (
|
MESSAGE_FROM_SQS_TEMPLATE = (
|
||||||
@ -332,7 +332,7 @@ def test_publish_to_http():
|
|||||||
json.loads.when.called_with(request.body.decode()).should_not.throw(Exception)
|
json.loads.when.called_with(request.body.decode()).should_not.throw(Exception)
|
||||||
return 200, {}, ""
|
return 200, {}, ""
|
||||||
|
|
||||||
responses.add_callback(
|
responses_mock.add_callback(
|
||||||
method="POST", url="http://example.com/foobar", callback=callback
|
method="POST", url="http://example.com/foobar", callback=callback
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user