Permalink
Browse files

added more tests for redirect and cookies

  • Loading branch information...
1 parent 9f82ee5 commit 646a6c2a4c1d8f411b2a21c5f162b9d516911a5c @heyZeus committed Mar 6, 2009
Showing with 26 additions and 5 deletions.
  1. +5 −2 README
  2. +21 −3 test/main.clj
View
7 README
@@ -8,6 +8,7 @@ USAGE
home (method "/")]
(println (scrape clj-ws home)))
+
; If you don't care about the HTML from the query you should just call
; send-method. In this example you are posting the login form and need
; to make sure a cookie is set to validate the login was successful.
@@ -18,15 +19,17 @@ USAGE
(println "yeah, I'm in")
(println "i can't remember my password again!")))
+
; You can also pass in a body to the send-method macro to do something
; like check the response status code. Note you can't check the response
-; code outside of the send-method call since all associated resources are
-; released at that point.
+; code outside of the send-method call since all associated resources have
+; been released.
(let [clj-ws (client "http://www.clojure.org")
login (method "/")]
(send-method clj-ws login
(println (.getStatusCode login))))
+
I've only implemented some basic functionality to make the commons-client
more "in line" with functional programming. There are lots of things that
could be added to this Clojure wrapper. I've just scratched the surface.
View
@@ -4,11 +4,12 @@
(def clj-ws (wc/client "http://www.clojure.org"))
(def home (wc/method "/"))
+(def clj-home-page-text "Clojure is a dialect of Lisp")
(deftest client
(let [host "www.clojure.org"
- clj-ws (wc/client (str "http://" host))]
- (is (= (.. clj-ws (getHostConfiguration) getHost) host))))
+ ws (wc/client (str "http://" host))]
+ (is (= (.. ws (getHostConfiguration) getHost) host))))
(deftest method
(let [default-get-method (wc/method "/")
@@ -26,6 +27,23 @@
(deftest scrape
(let [html (wc/scrape clj-ws home)]
- (is (= (.contains html "Clojure")))))
+ (is (= (.contains html clj-home-page-text)))))
+; this test depends on a website that i don't have any control over,
+; this test is fragile, but better than no test
+(deftest cookie-names
+ (wc/send-method clj-ws home)
+ ;(println "Cookies from clojure.org ")
+ ;(wc/print-cookies clj-ws)
+ (is (wc/assert-cookie-names clj-ws "test" "master"))
+ (is (not (wc/assert-cookie-names clj-ws "does-not-exist-at-all"))))
+
+; this test depends on a website that i don't have any control over,
+; this test is fragile, but better than no test
+(deftest redirect
+ ; i setup this redirect at shorturl.com
+ (let [redirect-site (wc/client "http://alturl.com/")
+ home-page (wc/method "/yew")]
+ (is (= (.contains (wc/scrape redirect-site home-page) clj-home-page-text)))))
+
(run-tests)

0 comments on commit 646a6c2

Please sign in to comment.