예제 #1
0
    def set_initial_no_auth_action_count(initial_no_auth_action_count):
        _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"{_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(
                    )["PREVIOUS_INITIAL_NO_AUTH_ACTION_COUNT"]
                else:
                    original_initial_no_auth_action_count = (
                        settings.INITIAL_NO_AUTH_ACTION_COUNT)
                    original_request_count = ActionAuthenticatorMixin.request_count
                    settings.INITIAL_NO_AUTH_ACTION_COUNT = initial_no_auth_action_count
                    ActionAuthenticatorMixin.request_count = 0
                try:
                    result = function(*args, **kwargs)
                finally:
                    if settings.TEST_SERVER_MODE:
                        requests.post(
                            f"{_test_server_mode_endpoint}/moto-api/reset-auth",
                            data=str(original_initial_no_auth_action_count).
                            encode("utf-8"),
                        )
                    else:
                        ActionAuthenticatorMixin.request_count = original_request_count
                        settings.INITIAL_NO_AUTH_ACTION_COUNT = (
                            original_initial_no_auth_action_count)
                return result

            functools.update_wrapper(wrapper, function)
            wrapper.__wrapped__ = function
            return wrapper

        return decorator
예제 #2
0
 def __init__(self, *args, **kwargs):
     self.test_server_mode_endpoint = settings.test_server_mode_endpoint()
     super().__init__(*args, **kwargs)