2013-12-20 20:29:48 +01:00
|
|
|
(require hy.contrib.meth)
|
|
|
|
|
|
|
|
(defclass FakeMeth []
|
|
|
|
"Mocking decorator class"
|
2015-08-04 16:43:07 +02:00
|
|
|
[rules {}]
|
|
|
|
(defn route [self rule &kwargs options]
|
|
|
|
(fn [f]
|
|
|
|
(assoc self.rules rule (, f options))
|
|
|
|
f)))
|
2013-12-20 20:29:48 +01:00
|
|
|
|
|
|
|
(defn test_route []
|
2015-08-17 09:07:32 +02:00
|
|
|
(let [app (FakeMeth)]
|
2013-12-20 20:29:48 +01:00
|
|
|
(route get-index "/" [] (str "Hy world!"))
|
|
|
|
(setv app-rules (getattr app "rules"))
|
|
|
|
(assert (in "/" app-rules))
|
2015-08-17 09:07:32 +02:00
|
|
|
(let [(, rule-fun rule-opt) (get app-rules "/")]
|
2013-12-20 20:29:48 +01:00
|
|
|
(assert (not (empty? rule-opt)))
|
|
|
|
(assert (in "GET" (get rule-opt "methods")))
|
|
|
|
(assert (= (getattr rule-fun "__name__") "get_index"))
|
|
|
|
(assert (= "Hy world!" (rule-fun))))))
|
|
|
|
|
|
|
|
(defn test_post_route []
|
2015-08-17 09:07:32 +02:00
|
|
|
(let [app (FakeMeth)]
|
2013-12-20 20:29:48 +01:00
|
|
|
(post-route get-index "/" [] (str "Hy world!"))
|
|
|
|
(setv app-rules (getattr app "rules"))
|
|
|
|
(assert (in "/" app-rules))
|
2015-08-17 09:07:32 +02:00
|
|
|
(let [(, rule-fun rule-opt) (get app-rules "/")]
|
2013-12-20 20:29:48 +01:00
|
|
|
(assert (not (empty? rule-opt)))
|
|
|
|
(assert (in "POST" (get rule-opt "methods")))
|
|
|
|
(assert (= (getattr rule-fun "__name__") "get_index"))
|
|
|
|
(assert (= "Hy world!" (rule-fun))))))
|
|
|
|
|
|
|
|
(defn test_put_route []
|
2015-08-17 09:07:32 +02:00
|
|
|
(let [app (FakeMeth)]
|
2013-12-20 20:29:48 +01:00
|
|
|
(put-route get-index "/" [] (str "Hy world!"))
|
|
|
|
(setv app-rules (getattr app "rules"))
|
|
|
|
(assert (in "/" app-rules))
|
2015-08-17 09:07:32 +02:00
|
|
|
(let [(, rule-fun rule-opt) (get app-rules "/")]
|
2013-12-20 20:29:48 +01:00
|
|
|
(assert (not (empty? rule-opt)))
|
|
|
|
(assert (in "PUT" (get rule-opt "methods")))
|
|
|
|
(assert (= (getattr rule-fun "__name__") "get_index"))
|
|
|
|
(assert (= "Hy world!" (rule-fun))))))
|
|
|
|
|
|
|
|
(defn test_delete_route []
|
2015-08-17 09:07:32 +02:00
|
|
|
(let [app (FakeMeth)]
|
2013-12-20 20:29:48 +01:00
|
|
|
(delete-route get-index "/" [] (str "Hy world!"))
|
|
|
|
(setv app-rules (getattr app "rules"))
|
|
|
|
(assert (in "/" app-rules))
|
2015-08-17 09:07:32 +02:00
|
|
|
(let [(, rule-fun rule-opt) (get app-rules "/")]
|
2013-12-20 20:29:48 +01:00
|
|
|
(assert (not (empty? rule-opt)))
|
|
|
|
(assert (in "DELETE" (get rule-opt "methods")))
|
|
|
|
(assert (= (getattr rule-fun "__name__") "get_index"))
|
|
|
|
(assert (= "Hy world!" (rule-fun))))))
|