|
61 | 61 | (defonce server |
62 | 62 | (future (ring/run-jetty handler {:port 18080})))) |
63 | 63 |
|
| 64 | +(defn localhost [path] |
| 65 | + (str "http://localhost:18080" path)) |
| 66 | + |
64 | 67 | (def base-req |
65 | 68 | {:scheme :http |
66 | 69 | :server-name "localhost" |
|
173 | 176 | :save-request? true})] |
174 | 177 | (is (= 200 (:status resp))) |
175 | 178 | (is (= {:scheme :http |
176 | | - :http-url "http://localhost:18080/post" |
| 179 | + :http-url (localhost "/post") |
177 | 180 | :request-method :post |
178 | 181 | :save-request? true |
179 | 182 | :uri "/post" |
|
213 | 216 |
|
214 | 217 | (deftest ^{:integration true} throw-on-too-many-redirects |
215 | 218 | (run-server) |
216 | | - (let [resp (client/get "http://localhost:18080/redirect" |
| 219 | + (let [resp (client/get (localhost "/redirect") |
217 | 220 | {:max-redirects 2 :throw-exceptions false})] |
218 | 221 | (is (= 302 (:status resp))) |
219 | 222 | (is (= (apply vector (repeat 3 "http://localhost:18080/redirect")) |
220 | 223 | (:trace-redirects resp)))) |
221 | 224 | (is (thrown-with-msg? Exception #"Too many redirects: 3" |
222 | | - (client/get "http://localhost:18080/redirect" |
| 225 | + (client/get (localhost "/redirect") |
223 | 226 | {:max-redirects 2 :throw-exceptions true}))) |
224 | 227 | (is (thrown-with-msg? Exception #"Too many redirects: 21" |
225 | | - (client/get "http://localhost:18080/redirect" |
| 228 | + (client/get (localhost "/redirect") |
226 | 229 | {:throw-exceptions true})))) |
227 | 230 |
|
228 | 231 | (deftest ^{:integration true} get-with-body |
|
239 | 242 |
|
240 | 243 | (deftest ^{:integration true} t-clojure-output-coercion |
241 | 244 | (run-server) |
242 | | - (let [resp (client/get "http://localhost:18080/clojure" {:as :clojure})] |
| 245 | + (let [resp (client/get (localhost "/clojure") {:as :clojure})] |
243 | 246 | (is (= 200 (:status resp))) |
244 | 247 | (is (= {:foo "bar" :baz 7M :eggplant {:quux #{1 2 3}}} (:body resp)))) |
245 | | - (let [resp (client/get "http://localhost:18080/clojure" {:as :auto})] |
| 248 | + (let [resp (client/get (localhost "/clojure") {:as :auto})] |
246 | 249 | (is (= 200 (:status resp))) |
247 | 250 | (is (= {:foo "bar" :baz 7M :eggplant {:quux #{1 2 3}}} (:body resp))))) |
248 | 251 |
|
249 | 252 | (deftest ^{:integration true} t-json-output-coercion |
250 | 253 | (run-server) |
251 | | - (let [resp (client/get "http://localhost:18080/json" {:as :json}) |
252 | | - bad-resp (client/get "http://localhost:18080/json-bad" |
| 254 | + (let [resp (client/get (localhost "/json") {:as :json}) |
| 255 | + bad-resp (client/get (localhost "/json-bad") |
253 | 256 | {:throw-exceptions false :as :json})] |
254 | 257 | (is (= 200 (:status resp))) |
255 | 258 | (is (= {:foo "bar"} (:body resp))) |
|
278 | 281 | ;; super-basic test for methods that aren't used that often |
279 | 282 | (deftest ^{:integration true} t-copy-options-move |
280 | 283 | (run-server) |
281 | | - (let [resp1 (client/options "http://localhost:18080/options") |
282 | | - resp2 (client/move "http://localhost:18080/move") |
283 | | - resp3 (client/copy "http://localhost:18080/copy") |
284 | | - resp4 (client/patch "http://localhost:18080/patch")] |
| 284 | + (let [resp1 (client/options (localhost "/options")) |
| 285 | + resp2 (client/move (localhost "/move")) |
| 286 | + resp3 (client/copy (localhost "/copy")) |
| 287 | + resp4 (client/patch (localhost "/patch"))] |
285 | 288 | (is (= #{200} (set (map :status [resp1 resp2 resp3 resp4])))) |
286 | 289 | (is (= "options" (:body resp1))) |
287 | 290 | (is (= "move" (:body resp2))) |
|
291 | 294 | (deftest ^{:integration true} t-json-encoded-form-params |
292 | 295 | (run-server) |
293 | 296 | (let [params {:param1 "value1" :param2 "value2"} |
294 | | - resp (client/post "http://localhost:18080/post" {:content-type :json |
295 | | - :form-params params})] |
| 297 | + resp (client/post (localhost "/post") {:content-type :json |
| 298 | + :form-params params})] |
296 | 299 | (is (= 200 (:status resp))) |
297 | 300 | (is (= (json/encode params) (:body resp))))) |
0 commit comments