//! Some tests of a CalDAV client. //! Most of them are not really integration tests, but just development tests that should be cleaned up one day. use reqwest::Method; use reqwest::header::CONTENT_TYPE; use minidom::Element; use url::Url; use my_tasks::client::Client; use my_tasks::traits::PartialCalendar; use my_tasks::traits::CalDavSource; use my_tasks::settings::URL; use my_tasks::settings::USERNAME; use my_tasks::settings::PASSWORD; use my_tasks::settings::EXAMPLE_TASK_URL; use my_tasks::settings::EXAMPLE_CALENDAR_URL; static EXAMPLE_TASKS_BODY_LAST_MODIFIED: &str = r#" "#; #[tokio::test] async fn show_calendars() { let _ = env_logger::builder().is_test(true).try_init(); let client = Client::new(URL, USERNAME, PASSWORD).unwrap(); let calendars = client.get_calendars().await.unwrap(); println!("Calendars:"); for (id, calendar) in calendars.iter() { let cal = calendar.lock().unwrap(); println!(" {}\t{}", cal.name(), id.as_str()); println!(" Most recent changes:"); for (_id, task) in cal.get_items_modified_since(None, None).await.unwrap() { my_tasks::utils::print_task(task); } } } #[tokio::test] async fn profind() { let _ = env_logger::builder().is_test(true).try_init(); let url: Url = EXAMPLE_TASK_URL.parse().unwrap(); let method = Method::from_bytes(b"PROPFIND") .expect("cannot create PROPFIND method."); let res = reqwest::Client::new() .request(method, url.as_str()) .header("Depth", 0) .header(CONTENT_TYPE, "application/xml") .basic_auth(USERNAME, Some(PASSWORD)) //.body(body) .send() .await .unwrap(); println!("{:?}", res.text().await); } #[tokio::test] async fn last_modified() { let _ = env_logger::builder().is_test(true).try_init(); let url: Url = EXAMPLE_CALENDAR_URL.parse().unwrap(); let method = Method::from_bytes(b"REPORT") .expect("cannot create REPORT method."); let res = reqwest::Client::new() .request(method, url.as_str()) .header("Depth", 1) .header(CONTENT_TYPE, "application/xml") .basic_auth(USERNAME, Some(PASSWORD)) .body(EXAMPLE_TASKS_BODY_LAST_MODIFIED) .send() .await .unwrap(); let el: Element = res.text().await.unwrap().parse().unwrap(); my_tasks::utils::print_xml(&el); }