diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2019-07-29 21:32:27 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2019-07-29 21:43:11 +0200 |
commit | d586d19bf239e27922eb896c6c496e931598ae78 (patch) | |
tree | 9dfd950c352a2b39e0de0d6e31418b5057f2b233 /tests | |
parent | 9806d9e094271f76c99589d252a57117d35ae7e5 (diff) | |
download | rust-zotapi-d586d19bf239e27922eb896c6c496e931598ae78.tar.gz rust-zotapi-d586d19bf239e27922eb896c6c496e931598ae78.tar.bz2 rust-zotapi-d586d19bf239e27922eb896c6c496e931598ae78.zip |
Update to Mockito 0.19 for smoother tests.
Provides matching against query params, so we don't need the ugly
regexes anymore.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/zotapi.rs | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/tests/zotapi.rs b/tests/zotapi.rs index 8c9d0b0..38bdf8a 100644 --- a/tests/zotapi.rs +++ b/tests/zotapi.rs @@ -29,8 +29,7 @@ fn default_mock(method: &str, url: &str) -> Mock { } fn client() -> zotapi::Client { - let listen_url = format!("http://{}", mockito::SERVER_ADDRESS); - zotapi::client(&listen_url, "testuser", "test1234") + zotapi::client(&mockito::server_url(), "testuser", "test1234") } #[test] @@ -80,14 +79,14 @@ fn create_new_post() { #[test] fn create_new_post_with_title() { - // Note this regex is not as good as it could be. But since the rust regex crate - // don't support back references it's the best we can do and not care about the - // oder of the entries. - let expected_body = Matcher::Regex(r"(title=A\+title&?|body=This\+is\+a\+test&?){2}".into()); - let m = mock("POST", "/api/z/1.0/item/update") .match_header("Authorization", Matcher::Regex(r"Basic \w+".into())) - .match_body(expected_body) + .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("{}") @@ -209,8 +208,8 @@ fn fetch_privacy_groups() { #[test] fn fetch_members_of_group_by_group_id() { - let m = mock("GET", Matcher::Regex( - r"^/api/z/1.0/group_members\?([^&]*&)*group_id=42".into())) + let m = mock("GET", "/api/z/1.0/group_members") + .match_query(Matcher::UrlEncoded("group_id".to_string(), "42".to_string())) .match_header("Authorization", Matcher::Regex(r"Basic \w+".into())) .with_status(200) .with_header("content-type", "application/json") @@ -223,8 +222,8 @@ fn fetch_members_of_group_by_group_id() { #[test] fn fetch_members_of_group_by_group_name() { - let m = mock("GET", Matcher::Regex( - r"^/api/z/1.0/group_members\?([^&]*&)*group_name=Friends\+of\+pain".into())) + let m = mock("GET", "/api/z/1.0/group_members") + .match_query(Matcher::UrlEncoded("group_name".into(), "Friends+of+pain".into())) .match_header("Authorization", Matcher::Regex(r"Basic \w+".into())) .with_status(200) .with_header("content-type", "application/json") |