wisp/testing
Values
pub fn bit_array_body(
response: response.Response(wisp.Body),
) -> BitArray
Read the body of a response as a bit string
Panics
This function will panic if the response body is a file and the file cannot be read.
pub fn connect(
path: String,
headers: List(#(String, String)),
) -> request.Request(@internal Connection)
Create a test HTTP request that can be used to test your request handler.
pub const default_secret_key_base: String
The default secret key base used for test requests. This should never be used outside of tests.
pub fn delete(
path: String,
headers: List(#(String, String)),
body: String,
) -> request.Request(@internal Connection)
Create a test HTTP request that can be used to test your request handler.
pub fn delete_form(
path: String,
headers: List(#(String, String)),
data: List(#(String, String)),
) -> request.Request(@internal Connection)
Create a test HTTP request that can be used to test your request handler.
The body parameters are encoded as form data and the content-type
header
is set to application/x-www-form-urlencoded
.
pub fn delete_json(
path: String,
headers: List(#(String, String)),
data: json.Json,
) -> request.Request(@internal Connection)
Create a test HTTP request that can be used to test your request handler.
The content-type
header is set to application/json
.
pub fn get(
path: String,
headers: List(#(String, String)),
) -> request.Request(@internal Connection)
Create a test HTTP request that can be used to test your request handler.
pub fn head(
path: String,
headers: List(#(String, String)),
) -> request.Request(@internal Connection)
Create a test HTTP request that can be used to test your request handler.
pub fn options(
path: String,
headers: List(#(String, String)),
) -> request.Request(@internal Connection)
Create a test HTTP request that can be used to test your request handler.
pub fn patch(
path: String,
headers: List(#(String, String)),
body: String,
) -> request.Request(@internal Connection)
Create a test HTTP request that can be used to test your request handler.
pub fn patch_form(
path: String,
headers: List(#(String, String)),
data: List(#(String, String)),
) -> request.Request(@internal Connection)
Create a test HTTP request that can be used to test your request handler.
The body parameters are encoded as form data and the content-type
header is set to application/x-www-form-urlencoded
.
pub fn patch_json(
path: String,
headers: List(#(String, String)),
data: json.Json,
) -> request.Request(@internal Connection)
Create a test HTTP request that can be used to test your request handler.
The content-type
header is set to application/json
.
pub fn post(
path: String,
headers: List(#(String, String)),
body: String,
) -> request.Request(@internal Connection)
Create a test HTTP request that can be used to test your request handler.
pub fn post_form(
path: String,
headers: List(#(String, String)),
data: List(#(String, String)),
) -> request.Request(@internal Connection)
Create a test HTTP request that can be used to test your request handler.
The body parameters are encoded as form data and the content-type
header
is set to application/x-www-form-urlencoded
.
pub fn post_json(
path: String,
headers: List(#(String, String)),
data: json.Json,
) -> request.Request(@internal Connection)
Create a test HTTP request that can be used to test your request handler.
The content-type
header is set to application/json
.
pub fn put(
path: String,
headers: List(#(String, String)),
body: String,
) -> request.Request(@internal Connection)
Create a test HTTP request that can be used to test your request handler.
pub fn put_form(
path: String,
headers: List(#(String, String)),
data: List(#(String, String)),
) -> request.Request(@internal Connection)
Create a test HTTP request that can be used to test your request handler.
The body parameters are encoded as form data and the content-type
header
is set to application/x-www-form-urlencoded
.
pub fn put_json(
path: String,
headers: List(#(String, String)),
data: json.Json,
) -> request.Request(@internal Connection)
Create a test HTTP request that can be used to test your request handler.
The content-type
header is set to application/json
.
pub fn request(
method: http.Method,
path: String,
headers: List(#(String, String)),
body: BitArray,
) -> request.Request(@internal Connection)
Create a test HTTP request that can be used to test your request handler functions.
Note not all HTTP methods are expected to have an accompanying body, so when
using this function directly over other functions such as get
and post
take care to ensure you are not providing a body when it is not expected.
The default_secret_key_base
constant is used as the secret key base for
requests made with this function.
pub fn set_cookie(
req: request.Request(@internal Connection),
name: String,
value: String,
security: wisp.Security,
) -> request.Request(@internal Connection)
Set a cookie on the request.
pub const set_header: fn(request.Request(a), String, String) -> request.Request(
a,
)
Set a header on a request.
Examples
let request =
test.request(test.Get, "/", [], <<>>)
|> test.set_header("content-type", "application/json")
request.headers
// => [#("content-type", "application/json")]
pub fn string_body(
response: response.Response(wisp.Body),
) -> String
Read the body of a response as a string.
Panics
This function will panic if the response body is a file and the file cannot be read, or if it does not contain valid UTF-8.
pub fn trace(
path: String,
headers: List(#(String, String)),
) -> request.Request(@internal Connection)
Create a test HTTP request that can be used to test your request handler.