pub struct Endpoint<T>where
T: Send + Sync + RowSource,
for<'t> &'t <<T as RowSource>::Rows as RowSet>::Target: IntoIterator<Item = &'t <T as RowSource>::Item>,{ /* private fields */ }wiremock only.Expand description
A Django-style wiremock endpoint for a collection of objects.
This is the central type in this crate. Endpoint implements
wiremock::Respond and so can be mounted directly into a
wiremock::MockServer. It contains a RowSource
which it will query for a fresh data on each query.
The Endpoint will filter the returned data based on the query
parameters in the URL, by using the Filterable trait on the
objects. It will then sort the data using the Sortable trait
on the objects. It will paginate the results as required using
"limit" and "offset". Finally, the returned data will be
converted using the IntoRow trait.
Implementations§
Source§impl<'q, T> Endpoint<T>
impl<'q, T> Endpoint<T>
Sourcepub fn new(row_source: T, base_uri: Option<&str>) -> Self
pub fn new(row_source: T, base_uri: Option<&str>) -> Self
Create a new endpoint.
row_source is where the data comes from. base_uri, if provided, should
be the wiremock server URI.
base_uri is only required because wiremock mangles the
request URL such that it’s not possible to inspect it to see
how to give out other URLs on the same server; the port
number, which is usually random when mocking, is lost. Since
Django includes full absolute URLs for the next and preceding
pages for a query, mimicking this is impossible without more
information (i.e. including usable URLs for the next page
within the query response is impossible).
Sourcepub fn default_limit(&mut self, limit: usize)
pub fn default_limit(&mut self, limit: usize)
Set the default number of results returned
This is the value used when no limit is specified in the query. This value is configurable in Django; the default behaviour of this mock endpoint is to return everything, but that makes testing code that uses the default pagination more difficult.
Trait Implementations§
Source§impl<'q, T> Respond for Endpoint<T>
impl<'q, T> Respond for Endpoint<T>
Source§fn respond(&self, request: &Request) -> ResponseTemplate
fn respond(&self, request: &Request) -> ResponseTemplate
Request return a ResponseTemplate that will be used
by the MockServer as blueprint for the response returned to the client.