Crates.io | django-query_derive |
lib.rs | django-query_derive |
version | 0.2.1 |
source | src |
created_at | 2022-04-05 06:51:42.969821 |
updated_at | 2022-06-01 23:26:16.61513 |
description | Macros for the django-query crate |
homepage | |
repository | https://github.com/eds-collabora/django-query-rs |
max_upload_size | |
id | 562454 |
size | 66,206 |
A set of tools for creating Django-style mock endpoints. The basic
usage is to annotate the type that you want to simulate having a
database of, derive the necessary traits, and then create an
Endpoint
to serve a sortable, filterable database of them.
Example usage:
#[derive(Filterable, IntoRow, Sortable)]
struct Foo {
#[django(sort, op(lt, gt))]
a: i32,
#[django(sort, op(icontains, iexact))]
b: String,
}
#[tokio::test]
fn simple_test() {
let server = MockServer::start().await;
// create a Vec of struct Foo here, and optionally
// wrap it in an Arc.
// Now serve our mock database with wiremock
Mock::given(matchers::method("GET"))
.respond_with(Endpoint::new(foo_table, Some(&server.uri())));
// And now we can make requests from our code like
reqwest::get(&format!("{}?limit=5&offset=5&b__icontains=apple&ordering=-a"))
.await
.expect("error getting response")
.json()
.await
.expect("error parsing response");
// which will perform
// - pagination (5 responses, offset by 5)
// - filtering (only array members whose b member contains apple,
// case insensitively)
// - sorting (the results will be in decreasing order of the a
// member)
}
It integrates with
persian-rug
and
clone-replace
to provide mutable collections of interlinked objects.
This code is made available under either an Apache-2.0 or an MIT license.