From b56c11639f9ea5ef1354a1e91ca98541a16bca9b Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 28 Jan 2020 21:26:13 +0100 Subject: Move Actix-Web integration into separate askama_actix crate --- askama_actix/tests/basic.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 askama_actix/tests/basic.rs (limited to 'askama_actix/tests/basic.rs') diff --git a/askama_actix/tests/basic.rs b/askama_actix/tests/basic.rs new file mode 100644 index 0000000..f4beff7 --- /dev/null +++ b/askama_actix/tests/basic.rs @@ -0,0 +1,53 @@ +use actix_web::http::header::CONTENT_TYPE; +use actix_web::test; +use actix_web::web; +use askama_actix::{Template, TemplateIntoResponse}; +use bytes::Bytes; + +#[derive(Template)] +#[template(path = "hello.html")] +struct HelloTemplate<'a> { + name: &'a str, +} + +#[actix_rt::test] +async fn test_actix_web() { + let srv = test::start(|| { + actix_web::App::new() + .service(web::resource("/").to(|| async { HelloTemplate { name: "world" } })) + }); + + let request = srv.get("/"); + let mut response = request.send().await.unwrap(); + assert!(response.status().is_success()); + assert_eq!( + response.headers().get(CONTENT_TYPE).unwrap(), + "text/html; charset=utf-8" + ); + + let bytes = response.body().await.unwrap(); + assert_eq!(bytes, Bytes::from_static("Hello, world!".as_ref())); +} + +#[actix_rt::test] +async fn test_actix_web_responder() { + let srv = test::start(|| { + actix_web::App::new().service(web::resource("/").to(|| { + async { + let name = "world".to_owned(); + HelloTemplate { name: &name }.into_response() + } + })) + }); + + let request = srv.get("/"); + let mut response = request.send().await.unwrap(); + assert!(response.status().is_success()); + assert_eq!( + response.headers().get(CONTENT_TYPE).unwrap(), + "text/html; charset=utf-8" + ); + + let bytes = response.body().await.unwrap(); + assert_eq!(bytes, Bytes::from_static("Hello, world!".as_ref())); +} -- cgit