Allow mock_s3 to use the standalone moto server running in alternative endpoint by adding TEST_SERVER_MODE_ENDPOINT environment variable (#4723)
This commit is contained in:
parent
bcf2eeb13b
commit
e9fada8ebd
@ -119,7 +119,7 @@ It is possible to keep the state in between tests, using this environment variab
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
MOTO_CALL_RESET_API=true
|
||||
MOTO_CALL_RESET_API=false
|
||||
|
||||
|
||||
Dashboard
|
||||
|
@ -388,7 +388,7 @@ MockAWS = BotocoreEventMockAWS
|
||||
|
||||
class ServerModeMockAWS(BaseMockAWS):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.port = settings.moto_server_port()
|
||||
self.test_server_mode_endpoint = settings.test_server_mode_endpoint()
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def reset(self):
|
||||
@ -396,7 +396,7 @@ class ServerModeMockAWS(BaseMockAWS):
|
||||
if not call_reset_api or call_reset_api.lower() != "false":
|
||||
import requests
|
||||
|
||||
requests.post(f"http://localhost:{self.port}/moto-api/reset")
|
||||
requests.post(f"{self.test_server_mode_endpoint}/moto-api/reset")
|
||||
|
||||
def enable_patching(self, reset=True):
|
||||
if self.__class__.nested_count == 1 and reset:
|
||||
@ -414,12 +414,12 @@ class ServerModeMockAWS(BaseMockAWS):
|
||||
config = Config(user_agent_extra="region/" + region)
|
||||
kwargs["config"] = config
|
||||
if "endpoint_url" not in kwargs:
|
||||
kwargs["endpoint_url"] = f"http://localhost:{self.port}"
|
||||
kwargs["endpoint_url"] = self.test_server_mode_endpoint
|
||||
return real_boto3_client(*args, **kwargs)
|
||||
|
||||
def fake_boto3_resource(*args, **kwargs):
|
||||
if "endpoint_url" not in kwargs:
|
||||
kwargs["endpoint_url"] = f"http://localhost:{self.port}"
|
||||
kwargs["endpoint_url"] = self.test_server_mode_endpoint
|
||||
return real_boto3_resource(*args, **kwargs)
|
||||
|
||||
self._client_patcher = patch("boto3.client", fake_boto3_client)
|
||||
|
@ -141,13 +141,13 @@ class ActionAuthenticatorMixin(object):
|
||||
|
||||
@staticmethod
|
||||
def set_initial_no_auth_action_count(initial_no_auth_action_count):
|
||||
_port = settings.moto_server_port()
|
||||
_test_server_mode_endpoint = settings.test_server_mode_endpoint()
|
||||
|
||||
def decorator(function):
|
||||
def wrapper(*args, **kwargs):
|
||||
if settings.TEST_SERVER_MODE:
|
||||
response = requests.post(
|
||||
f"http://localhost:{_port}/moto-api/reset-auth",
|
||||
f"{_test_server_mode_endpoint}/moto-api/reset-auth",
|
||||
data=str(initial_no_auth_action_count).encode("utf-8"),
|
||||
)
|
||||
original_initial_no_auth_action_count = response.json()[
|
||||
@ -165,7 +165,7 @@ class ActionAuthenticatorMixin(object):
|
||||
finally:
|
||||
if settings.TEST_SERVER_MODE:
|
||||
requests.post(
|
||||
f"http://localhost:{_port}/moto-api/reset-auth",
|
||||
f"{_test_server_mode_endpoint}/moto-api/reset-auth",
|
||||
data=str(original_initial_no_auth_action_count).encode(
|
||||
"utf-8"
|
||||
),
|
||||
|
@ -70,6 +70,12 @@ def moto_network_mode():
|
||||
return os.environ.get("MOTO_DOCKER_NETWORK_MODE")
|
||||
|
||||
|
||||
def test_server_mode_endpoint():
|
||||
return os.environ.get(
|
||||
"TEST_SERVER_MODE_ENDPOINT", f"http://localhost:{moto_server_port()}"
|
||||
)
|
||||
|
||||
|
||||
def is_docker():
|
||||
path = "/proc/self/cgroup"
|
||||
return (
|
||||
|
Loading…
Reference in New Issue
Block a user