forked from babashka/babashka.curl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support :multipart options, modeled after clj-http [babashka#26]
- Loading branch information
1 parent
eee04eb
commit 4d48326
Showing
2 changed files
with
60 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,8 +64,7 @@ | |
headers (:headers body) | ||
content-type (:content-type headers)] | ||
(is (= "application/x-www-form-urlencoded" content-type)))) | ||
;; TODO: | ||
#_(testing "multipart" | ||
(testing "multipart" | ||
(testing "posting file" | ||
(let [tmp-file (java.io.File/createTempFile "foo" "bar") | ||
_ (spit tmp-file "Michiel Borkent") | ||
|
@@ -81,6 +80,8 @@ | |
(is (str/starts-with? content-type "multipart/form-data")) | ||
(is (:files body)) | ||
(is (str/includes? (-> body :form :filename) "foo")) | ||
#_(is (str/includes? (-> body :form :filename) "filename")) | ||
#_(is (str/includes? (-> body :form :filename) "file2")) | ||
(prn body))))) | ||
|
||
(deftest patch-test | ||
|
@@ -244,3 +245,36 @@ | |
(let [response (curl/get "https://httpstat.us/404" {:throw false})] | ||
(is (= 404 (:status response))) | ||
(is (zero? (:exit response)))))) | ||
|
||
|
||
(deftest create-multipart-params-test | ||
(testing "nil multipart" | ||
(is (= nil (seq (#'curl/create-multipart-params nil))))) | ||
(testing "string content" | ||
(let [multipart [{:name "foo" :content "bar"}]] | ||
(is (= ["--form" "foo=bar"] | ||
(#'curl/create-multipart-params multipart))))) | ||
(testing "with :mime-type" | ||
(let [multipart [{:name "boo" :content "baz" :mime-type "text/plain"}]] | ||
(is (= ["--form" "boo=baz;type=text/plain"] | ||
(#'curl/create-multipart-params multipart))))) | ||
(testing "with :part-name" | ||
(let [multipart [{:name "boo" :content "baz" :mime-type "text/plain" :part-name "hotdog"}]] | ||
(is (= ["--form" "hotdog=baz;type=text/plain"] | ||
(#'curl/create-multipart-params multipart))))) | ||
(testing "File content" | ||
(let [multipart [{:name "myfile" :content (io/file "README.md")}]] | ||
(is (= ["--form" "[email protected]"] | ||
(#'curl/create-multipart-params multipart))))) | ||
#_(testing "vector part" | ||
(let [multipart [["file4" (io/file "README.md")]]] | ||
(is (= ["--form" "[email protected]"] | ||
(#'curl/create-multipart-params multipart))))) | ||
(testing "multiple fields" | ||
(let [multipart [{:name "title" :content "awesome"} | ||
{:name "foo" :part-name "eggplant" :content "zack" :mime-type "text/plain"} | ||
{:name "myfile" :content (io/file "README.md")}]] | ||
(is (= ["--form" "title=awesome" | ||
"--form" "eggplant=zack;type=text/plain" | ||
"--form" "[email protected]"] | ||
(#'curl/create-multipart-params multipart)))))) |