aboutsummaryrefslogtreecommitdiffstats
path: root/testing
diff options
context:
space:
mode:
authorLibravatar Ryan McGrath <ryan@rymc.io>2018-07-21 19:10:48 +0000
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-07-22 14:47:29 +0100
commited98793b506c66723c713991f40c0065557a35d5 (patch)
tree6ab23bf2dab25d63f276de96504f7cb28cb3d9cb /testing
parentc860bee5d5934fba6d57cbf815894a5cc8599ad9 (diff)
downloadaskama-ed98793b506c66723c713991f40c0065557a35d5.tar.gz
askama-ed98793b506c66723c713991f40c0065557a35d5.tar.bz2
askama-ed98793b506c66723c713991f40c0065557a35d5.zip
Tests for actix_web
Diffstat (limited to '')
-rw-r--r--testing/Cargo.toml6
-rw-r--r--testing/tests/actix_web.rs29
2 files changed, 33 insertions, 2 deletions
diff --git a/testing/Cargo.toml b/testing/Cargo.toml
index ff67e2e..6223673 100644
--- a/testing/Cargo.toml
+++ b/testing/Cargo.toml
@@ -9,7 +9,9 @@ default = []
nightly = ["rocket", "rocket_codegen", "askama/with-rocket"]
[dependencies]
-askama = { path = "../askama", version = "*", features = ["with-iron", "serde-json"] }
+actix-web = "0.7"
+askama = { path = "../askama", version = "*", features = ["with-actix-web", "with-iron", "serde-json"] }
+bytes = "0.4"
criterion = "0.2"
iron = "0.6"
rocket = { version = "0.3", optional = true }
@@ -17,7 +19,7 @@ rocket_codegen = { version = "0.3", optional = true }
serde_json = "1.0"
[build-dependencies]
-askama = { path = "../askama", version = "*", features = ["with-iron", "serde-json"] }
+askama = { path = "../askama", version = "*", features = ["with-actix-web", "with-iron", "serde-json"] }
[[bench]]
name = "all"
diff --git a/testing/tests/actix_web.rs b/testing/tests/actix_web.rs
new file mode 100644
index 0000000..12724d9
--- /dev/null
+++ b/testing/tests/actix_web.rs
@@ -0,0 +1,29 @@
+#[macro_use]
+extern crate askama;
+extern crate actix_web;
+extern crate bytes;
+
+use actix_web::http::header::CONTENT_TYPE;
+use actix_web::test;
+use actix_web::HttpMessage;
+use askama::Template;
+use bytes::Bytes;
+
+#[derive(Template)]
+#[template(path = "hello.html")]
+struct HelloTemplate<'a> {
+ name: &'a str,
+}
+
+#[test]
+fn test_actix_web() {
+ let mut srv = test::TestServer::new(|app| app.handler(|_| HelloTemplate { name: "world" }));
+
+ let request = srv.get().finish().unwrap();
+ let response = srv.execute(request.send()).unwrap();
+ assert!(response.status().is_success());
+ assert_eq!(response.headers().get(CONTENT_TYPE).unwrap(), "text/html");
+
+ let bytes = srv.execute(response.body()).unwrap();
+ assert_eq!(bytes, Bytes::from_static("Hello, world!".as_ref()));
+}