Struct django_query::mock::Endpoint
source · [−]pub struct Endpoint<T> { /* private fields */ }
Expand description
A Django-style Wiremock endpoint for a collection of suitable objects.
This is the central struct in this crate. Endpoint
implements
Respond(wiremock::Respond and so can be mounted directly into a
MockServer. It contains a RowSource
which it will query for a starting set of data.
It will then filter that data using the URL, using the
Filterable trait on the objects; then it will sort the data
using the Sortable trait on the objects; then it will clip the
results to the selected page using limit
and offset
;finally it
will convert the data to JSON using the IntoRow trait on the
objects.
Implementations
sourceimpl<T, R> Endpoint<T> where
T: Send + Sync + RowSource<Item = R>,
R: Filterable + Sortable + 'static,
<T as RowSource>::Rows: Deref,
for<'a> &'a <<T as RowSource>::Rows as Deref>::Target: IntoIterator<Item = &'a R>,
impl<T, R> Endpoint<T> where
T: Send + Sync + RowSource<Item = R>,
R: Filterable + Sortable + 'static,
<T as RowSource>::Rows: Deref,
for<'a> &'a <<T as RowSource>::Rows as Deref>::Target: IntoIterator<Item = &'a R>,
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).
Trait Implementations
sourceimpl<T, R> Respond for Endpoint<T> where
T: Send + Sync + RowSource<Item = R>,
R: Filterable + Sortable + IntoRow + 'static,
<T as RowSource>::Rows: Deref,
for<'a> &'a <<T as RowSource>::Rows as Deref>::Target: IntoIterator<Item = &'a R>,
impl<T, R> Respond for Endpoint<T> where
T: Send + Sync + RowSource<Item = R>,
R: Filterable + Sortable + IntoRow + 'static,
<T as RowSource>::Rows: Deref,
for<'a> &'a <<T as RowSource>::Rows as Deref>::Target: IntoIterator<Item = &'a R>,
sourcefn respond(&self, request: &Request) -> ResponseTemplate
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. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for Endpoint<T> where
T: RefUnwindSafe,
impl<T> Send for Endpoint<T> where
T: Send,
impl<T> Sync for Endpoint<T> where
T: Sync,
impl<T> Unpin for Endpoint<T> where
T: Unpin,
impl<T> UnwindSafe for Endpoint<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more