diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2020-01-02 21:10:55 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2020-01-02 21:10:55 +0100 |
commit | 16a56f12cd2e66e10f8bb5e2c4026d3a7148e680 (patch) | |
tree | 913bd32a563b32302c2e14304460a3cbc9a88a39 /tests | |
parent | 7f306445cb78d52f598eca1810dc2c5002e34a4a (diff) | |
download | rust-zotapi-16a56f12cd2e66e10f8bb5e2c4026d3a7148e680.tar.gz rust-zotapi-16a56f12cd2e66e10f8bb5e2c4026d3a7148e680.tar.bz2 rust-zotapi-16a56f12cd2e66e10f8bb5e2c4026d3a7148e680.zip |
Cargo fmt
Diffstat (limited to 'tests')
-rw-r--r-- | tests/zotapi.rs | 134 |
1 files changed, 82 insertions, 52 deletions
diff --git a/tests/zotapi.rs b/tests/zotapi.rs index d828632..66fe15e 100644 --- a/tests/zotapi.rs +++ b/tests/zotapi.rs @@ -17,9 +17,10 @@ use mockito::{mock, Matcher, Mock}; fn mock_with_authorization(method: &str, url: &str) -> Mock { - mock(method, url) - .match_header("Authorization", - Matcher::Exact(format!("Basic {}", base64::encode("testuser:test1234")))) + mock(method, url).match_header( + "Authorization", + Matcher::Exact(format!("Basic {}", base64::encode("testuser:test1234"))), + ) } fn default_mock(method: &str, url: &str) -> Mock { @@ -81,18 +82,20 @@ fn create_new_post() { #[test] fn create_new_post_with_title() { let m = mock_with_authorization("POST", "/api/z/1.0/item/update") - .match_body( - Matcher::AllOf(vec![ - Matcher::UrlEncoded("title".to_string(), "A+title".to_string()), - Matcher::UrlEncoded("body".to_string(), "This+is+a+test".to_string()), - ]) - ) + .match_body(Matcher::AllOf(vec![ + Matcher::UrlEncoded("title".to_string(), "A+title".to_string()), + Matcher::UrlEncoded("body".to_string(), "This+is+a+test".to_string()), + ])) .with_status(200) .with_header("content-type", "application/json") .with_body("{}") .create(); - let _res = client().item().title("A title").body("This is a test").create(); + let _res = client() + .item() + .title("A title") + .body("This is a test") + .create(); m.assert(); } @@ -106,18 +109,17 @@ fn create_new_post_limited_to_one_privacy_group() { // For now this test makes no assertions, but at least it runs // through the code paths it should. let _m = mock_with_authorization("POST", "/api/z/1.0/item/update") - .match_body( - Matcher::AllOf(vec![ - Matcher::UrlEncoded("body".to_string(), "This is a test".to_string()), - Matcher::UrlEncoded("groups_allow[0]".to_string(), "grouphash".to_string()) - ]) - ) + .match_body(Matcher::AllOf(vec![ + Matcher::UrlEncoded("body".to_string(), "This is a test".to_string()), + Matcher::UrlEncoded("groups_allow[0]".to_string(), "grouphash".to_string()), + ])) .with_status(200) .with_header("content-type", "application/json") .with_body("{}") .create(); - let _res = client().item() + let _res = client() + .item() .body("This is a test") .group_allow("grouphash") .create(); @@ -128,25 +130,30 @@ fn create_new_post_limited_to_one_privacy_group() { #[test] fn upload_item_with_media_file() { let m = mock_with_authorization("POST", "/api/z/1.0/item/update") - .match_header("content-type", Matcher::Regex("^multipart/form-data; boundary=.+$".into())) + .match_header( + "content-type", + Matcher::Regex("^multipart/form-data; boundary=.+$".into()), + ) .match_body(Matcher::Regex( - "--.+\r\n".to_owned() + - "Content-Disposition: form-data; name=\"body\"\r\n" + - "\r\nThis is a test\r\n" + - "--.+\r\n" + - "Content-Disposition: form-data; name=\"title\"\r\n" + - "\r\nA title\r\n" + - "--.+\r\n" + - "Content-Disposition: form-data; name=\"media\"; filename=\"testfile.txt\"\r\n" + - "Content-Type: text/plain\r\n" + - "\r\ntestfile contents\n" + - "\r\n--.+--\r\n")) + "--.+\r\n".to_owned() + + "Content-Disposition: form-data; name=\"body\"\r\n" + + "\r\nThis is a test\r\n" + + "--.+\r\n" + + "Content-Disposition: form-data; name=\"title\"\r\n" + + "\r\nA title\r\n" + + "--.+\r\n" + + "Content-Disposition: form-data; name=\"media\"; filename=\"testfile.txt\"\r\n" + + "Content-Type: text/plain\r\n" + + "\r\ntestfile contents\n" + + "\r\n--.+--\r\n", + )) .with_status(200) .with_header("content-type", "application/json") .with_body("{}") .create(); - let _res = client().item() + let _res = client() + .item() .title("A title") .body("This is a test") .file("tests/fixtures/testfile.txt") @@ -158,29 +165,34 @@ fn upload_item_with_media_file() { #[test] fn upload_item_with_two_files() { let m = mock_with_authorization("POST", "/api/z/1.0/item/update") - .match_header("content-type", Matcher::Regex("multipart/form-data; boundary=.+".into())) + .match_header( + "content-type", + Matcher::Regex("multipart/form-data; boundary=.+".into()), + ) .match_body(Matcher::Regex( - "--.+\r\n".to_owned() + - "Content-Disposition: form-data; name=\"body\"\r\n" + - "\r\nThis is a test\r\n" + - "--.+\r\n" + - "Content-Disposition: form-data; name=\"title\"\r\n" + - "\r\nA title\r\n" + - "--.+\r\n" + - "Content-Disposition: form-data; name=\"media\"; filename=\"testfile.txt\"\r\n" + - "Content-Type: text/plain\r\n" + - "\r\ntestfile contents\n" + - "\r\n--.+\r\n" + - "Content-Disposition: form-data; name=\"media\"; filename=\"testfile.txt\"\r\n" + - "Content-Type: text/plain\r\n" + - "\r\ntestfile contents\n" + - "\r\n--.+--\r\n")) + "--.+\r\n".to_owned() + + "Content-Disposition: form-data; name=\"body\"\r\n" + + "\r\nThis is a test\r\n" + + "--.+\r\n" + + "Content-Disposition: form-data; name=\"title\"\r\n" + + "\r\nA title\r\n" + + "--.+\r\n" + + "Content-Disposition: form-data; name=\"media\"; filename=\"testfile.txt\"\r\n" + + "Content-Type: text/plain\r\n" + + "\r\ntestfile contents\n" + + "\r\n--.+\r\n" + + "Content-Disposition: form-data; name=\"media\"; filename=\"testfile.txt\"\r\n" + + "Content-Type: text/plain\r\n" + + "\r\ntestfile contents\n" + + "\r\n--.+--\r\n", + )) .with_status(200) .with_header("content-type", "application/json") .with_body("{}") .create(); - let _res = client().item() + let _res = client() + .item() .title("A title") .body("This is a test") .file("tests/fixtures/testfile.txt") @@ -193,7 +205,11 @@ fn upload_item_with_two_files() { #[test] fn fetch_xchan_by_address() { let m = default_mock("GET", "/api/z/1.0/xchan?address=test%40test.com"); - let _res = client().xchan().by_address("test@test.com").fetch().unwrap(); + let _res = client() + .xchan() + .by_address("test@test.com") + .fetch() + .unwrap(); m.assert(); } @@ -207,7 +223,11 @@ fn fetch_xchan_by_hash() { #[test] fn fetch_xchan_by_guid() { let m = default_mock("GET", "/api/z/1.0/xchan?guid=baffebaff-baff-baff"); - let _res = client().xchan().by_guid("baffebaff-baff-baff").fetch().unwrap(); + let _res = client() + .xchan() + .by_guid("baffebaff-baff-baff") + .fetch() + .unwrap(); m.assert(); } @@ -235,7 +255,10 @@ fn fetch_privacy_groups() { #[test] fn fetch_members_of_group_by_group_id() { let m = mock_with_authorization("GET", "/api/z/1.0/group_members") - .match_query(Matcher::UrlEncoded("group_id".to_string(), "42".to_string())) + .match_query(Matcher::UrlEncoded( + "group_id".to_string(), + "42".to_string(), + )) .with_status(200) .with_header("content-type", "application/json") .with_body("{}") @@ -248,12 +271,19 @@ fn fetch_members_of_group_by_group_id() { #[test] fn fetch_members_of_group_by_group_name() { let m = mock_with_authorization("GET", "/api/z/1.0/group_members") - .match_query(Matcher::UrlEncoded("group_name".into(), "Friends+of+pain".into())) + .match_query(Matcher::UrlEncoded( + "group_name".into(), + "Friends+of+pain".into(), + )) .with_status(200) .with_header("content-type", "application/json") .with_body("{}") .create(); - let _res = client().group_members().by_group_name("Friends of pain").fetch().unwrap(); + let _res = client() + .group_members() + .by_group_name("Friends of pain") + .fetch() + .unwrap(); m.assert(); } |