Phoenix.ConnTest

Source

Summary

clear_flash(conn)

Clears up the flash storage

conn()

Creates a connection to be used in upcoming requests

conn(method, path, params_or_body \\ nil)

Creates a connection to be used in upcoming requests with a preset method, path and body

connect(conn, path_or_action, params_or_body \\ nil)

Dispatches to the current endpoint

delete(conn, path_or_action, params_or_body \\ nil)

Dispatches to the current endpoint

delete_req_cookie(conn, key)

Deletes a request cookie

delete_req_header(conn, key)

Deletes a request header

dispatch(conn, endpoint, method, path_or_action, params_or_body \\ nil)

Dispatches the connection to the given endpoint

ensure_recycled(conn)

Ensures the connection is recycled if it wasn’t already

fetch_flash(conn)

Fetches the flash storage

get(conn, path_or_action, params_or_body \\ nil)

Dispatches to the current endpoint

get_flash(conn)

Gets the whole flash storage

get_flash(conn, key)

Gets the given key from the flash storage

head(conn, path_or_action, params_or_body \\ nil)

Dispatches to the current endpoint

options(conn, path_or_action, params_or_body \\ nil)

Dispatches to the current endpoint

patch(conn, path_or_action, params_or_body \\ nil)

Dispatches to the current endpoint

post(conn, path_or_action, params_or_body \\ nil)

Dispatches to the current endpoint

put(conn, path_or_action, params_or_body \\ nil)

Dispatches to the current endpoint

put_flash(conn, key, value)

Puts the given value under key in the flash storage

put_req_cookie(conn, key, value)

Puts a request cookie

put_req_header(conn, key, value)

Puts a new request header

recycle(conn)

Recycles the connection

trace(conn, path_or_action, params_or_body \\ nil)

Dispatches to the current endpoint

Functions

clear_flash(conn)

Specs:

  • clear_flash(Plug.Conn.t) :: Plug.Conn.t

Clears up the flash storage.

Source
conn()

Specs:

  • conn :: Plug.Conn.t
  • conn :: Plug.Conn.t

Creates a connection to be used in upcoming requests.

Source
conn(method, path, params_or_body \\ nil)

Creates a connection to be used in upcoming requests with a preset method, path and body.

This is useful when a specific connection is required for testing a plug or a particular function.

Source
delete_req_cookie(conn, key)

Specs:

  • delete_req_cookie(Plug.Conn.t, binary) :: Plug.Conn.t

Deletes a request cookie.

Source
delete_req_header(conn, key)

Specs:

  • delete_req_header(Plug.Conn.t, binary) :: Plug.Conn.t

Deletes a request header.

Source
dispatch(conn, endpoint, method, path_or_action, params_or_body \\ nil)

Dispatches the connection to the given endpoint.

When invoked via get/3, post/3 and friends, the endpoint is automatically retrieved from the @endpoint module attribute, otherwise it must be given as an argument.

The connection will be configured with the given method, path_or_action and params_or_body.

If path_or_action is a string, it is considered to be the request path and stored as so in the connection. If an atom, it is assumed to be an action and the connection is dispatched to the given action.

Parameters and body

This function, as well as get/3, post/3 and friends, accept the request body or parameters as last argument:

get conn(), "/", some: "param"
  get conn(), "/", "some=param&url=encoded"

The allowed values are:

  • nil - meaning there is no body

  • a binary - containing a request body. For such cases, :headers must be given as option with a content-type

  • a map or list - containing the parameters which will automatically set the content-type to multipart. The map or list may contain other lists or maps and all entries will be normalized to string keys
Source
ensure_recycled(conn)

Ensures the connection is recycled if it wasn’t already.

See recycle/1 for more information.

Source
fetch_flash(conn)

Specs:

  • fetch_flash(Plug.Conn.t) :: Plug.Conn.t

Fetches the flash storage.

Source
get_flash(conn)

Specs:

  • get_flash(Plug.Conn.t) :: Plug.Conn.t

Gets the whole flash storage.

Source
get_flash(conn, key)

Specs:

  • get_flash(Plug.Conn.t, term) :: Plug.Conn.t

Gets the given key from the flash storage.

Source
put_flash(conn, key, value)

Specs:

  • put_flash(Plug.Conn.t, term, term) :: Plug.Conn.t

Puts the given value under key in the flash storage.

Source
put_req_cookie(conn, key, value)

Specs:

  • put_req_cookie(Plug.Conn.t, binary, binary) :: Plug.Conn.t

Puts a request cookie.

Source
put_req_header(conn, key, value)

Specs:

  • put_req_header(Plug.Conn.t, binary, binary) :: Plug.Conn.t

Puts a new request header.

Previous entries of the same header are overridden.

Source
recycle(conn)

Specs:

  • recycle(Plug.Conn.t) :: Plug.Conn.t
  • recycle(Plug.Conn.t) :: Plug.Conn.t

Recycles the connection.

Recycling receives an connection and returns a new connection, containing cookies and relevant information from the given one.

This emulates behaviour performed by browsers where cookies returned in the response are available in following requests.

Note recycle/1 is automatically invoked when dispatching to the endpoint, unless the connection has already been recycled.

Source

Macros

connect(conn, path_or_action, params_or_body \\ nil)

Dispatches to the current endpoint.

See dispatch/5 for more information.

Source
delete(conn, path_or_action, params_or_body \\ nil)

Dispatches to the current endpoint.

See dispatch/5 for more information.

Source
get(conn, path_or_action, params_or_body \\ nil)

Dispatches to the current endpoint.

See dispatch/5 for more information.

Source
head(conn, path_or_action, params_or_body \\ nil)

Dispatches to the current endpoint.

See dispatch/5 for more information.

Source
options(conn, path_or_action, params_or_body \\ nil)

Dispatches to the current endpoint.

See dispatch/5 for more information.

Source
patch(conn, path_or_action, params_or_body \\ nil)

Dispatches to the current endpoint.

See dispatch/5 for more information.

Source
post(conn, path_or_action, params_or_body \\ nil)

Dispatches to the current endpoint.

See dispatch/5 for more information.

Source
put(conn, path_or_action, params_or_body \\ nil)

Dispatches to the current endpoint.

See dispatch/5 for more information.

Source
trace(conn, path_or_action, params_or_body \\ nil)

Dispatches to the current endpoint.

See dispatch/5 for more information.

Source