IbkrApi.Support.HTTPSandbox (ibkr_api v1.0.3)
View SourceHTTP sandbox for mocking HTTP requests in tests.
Stores response functions in a Registry under the PID of the test process. In test, the IbkrApi.SharedUtils.HTTP module will check this sandbox before making actual HTTP requests.
Summary
Functions
Retrieves the response for a DELETE request
Finds the appropriate response function for the given action and URL. Returns the function or raises an error.
Retrieves the response for a GET request
Retrieves the response for a HEAD request
Retrieves the response for a POST request
Retrieves the response for a PUT request
Checks if the HTTP sandbox is disabled. Used by the HTTP client to determine whether to use mock responses.
Sets sandbox responses for DELETE requests.
Sets sandbox responses for GET requests.
Sets sandbox responses for HEAD requests.
Sets sandbox responses for POST requests.
Sets sandbox responses for PUT requests.
Start the HTTP sandbox registry. Should be called from test_helper.exs
Types
Functions
Retrieves the response for a DELETE request
Finds the appropriate response function for the given action and URL. Returns the function or raises an error.
Retrieves the response for a GET request
Retrieves the response for a HEAD request
Retrieves the response for a POST request
Retrieves the response for a PUT request
@spec sandbox_disabled?() :: boolean()
Checks if the HTTP sandbox is disabled. Used by the HTTP client to determine whether to use mock responses.
Always returns false in tests, meaning the sandbox is always enabled.
Sets sandbox responses for DELETE requests.
Examples
HTTPSandbox.set_delete_responses([
{"https://localhost:5000/v1/api/iserver/account/order/12345", fn ->
{:ok, %{"id" => "12345"}, %IbkrApi.SharedUtils.HTTP.Response{status: 200}}
end}
])
Sets sandbox responses for GET requests.
Examples
HTTPSandbox.set_get_responses([
{"https://localhost:5000/v1/api/iserver/auth/status", fn ->
{:ok, %{
"authenticated" => true,
"competing" => false,
"connected" => true,
"message" => ""
}, %IbkrApi.SharedUtils.HTTP.Response{status: 200}}
end}
])
Sets sandbox responses for HEAD requests.
Examples
HTTPSandbox.set_head_responses([
{"https://localhost:5000/v1/api/iserver/auth/status", fn ->
{:ok, %{}, %IbkrApi.SharedUtils.HTTP.Response{status: 200}}
end}
])
Sets sandbox responses for POST requests.
Examples
HTTPSandbox.set_post_responses([
{"https://localhost:5000/v1/api/iserver/account", fn ->
{:ok, %{"acctId" => "U12345678"}, %IbkrApi.SharedUtils.HTTP.Response{status: 200}}
end}
])
Sets sandbox responses for PUT requests.
Examples
HTTPSandbox.set_put_responses([
{"https://localhost:5000/v1/api/iserver/account/orders", fn ->
{:ok, %{"id" => "12345"}, %IbkrApi.SharedUtils.HTTP.Response{status: 200}}
end}
])
Start the HTTP sandbox registry. Should be called from test_helper.exs