Struct Endpoint

Source
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 */ }
Available on crate feature 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>
where T: Send + Sync + RowSource, for<'t> &'t <<T as RowSource>::Rows as RowSet>::Target: IntoIterator<Item = &'t <T as RowSource>::Item>, <T as RowSource>::Item: Send + Sync + Filterable<'q> + Sortable<'q>,

Source

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).

Source

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>
where T: Send + Sync + RowSource, for<'t> &'t <<T as RowSource>::Rows as RowSet>::Target: IntoIterator<Item = &'t <T as RowSource>::Item>, <T as RowSource>::Item: Send + Sync + Filterable<'q> + Sortable<'q> + IntoRow<'q> + 'q,

Source§

fn respond(&self, request: &Request) -> ResponseTemplate

Given a reference to a Request return a ResponseTemplate that will be used by the MockServer as blueprint for the response returned to the client.

Auto Trait Implementations§

§

impl<T> Freeze for Endpoint<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Endpoint<T>
where T: RefUnwindSafe,

§

impl<T> Send for Endpoint<T>

§

impl<T> Sync for Endpoint<T>

§

impl<T> Unpin for Endpoint<T>
where T: Unpin,

§

impl<T> UnwindSafe for Endpoint<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,