diff --git a/test/metabase/http_client.clj b/test/metabase/http_client.clj index 82a9f2f150817130021861d1668dd2812a9536a2..f321b5faee77718e87f665132df13a44cf57dcf5 100644 --- a/test/metabase/http_client.clj +++ b/test/metabase/http_client.clj @@ -120,14 +120,28 @@ url (build-url url url-param-kwargs) method-name (s/upper-case (name method)) ;; Now perform the HTTP request - {:keys [status body]} (try (request-fn url request-map) - (catch clojure.lang.ExceptionInfo e - (log/debug method-name url) - (:object (ex-data e))))] + {:keys [status body] :as resp} (try (request-fn url request-map) + (catch clojure.lang.ExceptionInfo e + (log/debug method-name url) + (:object (ex-data e))))] (log/debug method-name url status) (check-status-code method-name url body expected-status status) - (parse-response body))) + (update resp :body parse-response))) +(defn- parse-http-client-args + "Parse the list of required and optional `args` into the various separated params that `-client` requires" + [args] + (let [[credentials [method & args]] (u/optional #(or (map? %) (string? %)) args) + [expected-status [url & args]] (u/optional integer? args) + [{:keys [request-options]} args] (u/optional (every-pred map? :request-options) args {:request-options {}}) + [body [& {:as url-param-kwargs}]] (u/optional map? args)] + [credentials method expected-status url body url-param-kwargs request-options])) + +(defn client-full-response + "Identical to `client` except returns the full HTTP response map, not just the body of the response" + {:arglists '([credentials? method expected-status-code? url request-options? http-body-map? & url-kwargs])} + [& args] + (apply -client (parse-http-client-args args))) (defn client "Perform an API call and return the response (for test purposes). @@ -142,7 +156,8 @@ Args: - * CREDENTIALS Optional map of `:username` and `:password` or `X-METABASE-SESSION` token of a User who we should perform the request as + * CREDENTIALS Optional map of `:username` and `:password` or `X-METABASE-SESSION` token of a User who we + should perform the request as * METHOD `:get`, `:post`, `:delete`, or `:put` * EXPECTED-STATUS-CODE When passed, throw an exception if the response has a different status code. * URL Base URL of the request, which will be appended to `*url-prefix*`. e.g. `card/1/favorite` @@ -150,8 +165,4 @@ * URL-KWARGS key-value pairs that will be encoded and added to the URL as GET params" {:arglists '([credentials? method expected-status-code? url request-options? http-body-map? & url-kwargs])} [& args] - (let [[credentials [method & args]] (u/optional #(or (map? %) (string? %)) args) - [expected-status [url & args]] (u/optional integer? args) - [{:keys [request-options]} args] (u/optional (every-pred map? :request-options) args {:request-options {}}) - [body [& {:as url-param-kwargs}]] (u/optional map? args)] - (-client credentials method expected-status url body url-param-kwargs request-options))) + (:body (apply client-full-response args)))