Permalink
Browse files

a few basic tests

  • Loading branch information...
1 parent 448f035 commit adde3db1942104307873282cc77275a4ff1e61fa @klang klang committed with abedra Sep 21, 2010
@@ -0,0 +1,27 @@
+(ns basic-with-style.core-test
+ (:use [basic-with-style.core] :reload-all)
+ (:use [clojure.test]))
+
+(deftest not-found-error
+ (let [request {:uri "/error"}
+ response (routes request)]
+ (testing "not-found"
+ (is (= 404 (:status response)))
+ (is (re-find #"Not Found" (:body response))))))
+
+(deftest default-page
+ (let [request {:uri "/" :request-method :get}
+ response (routes request)]
+ (testing "default page"
+ (is (= 200 (:status response)))
+ (is (re-find #"Hello World" (:body response)))
+ (is (re-find #"screen.css" (:body response))))))
+
+(deftest file-delivery
+ (let [request {:uri "/stylesheets/screen.css" :request-method :get}
+ response (routes request)]
+ (testing "file delivery"
+ (is (= 200 (:status response)))
+ (is (.exists (response :body)))
+ (is (.isFile (response :body)))
+ (is (= "screen.css" (.getName (response :body)))))))
@@ -0,0 +1,16 @@
+(ns basic.core-test
+ (:use [basic.core] :reload-all)
+ (:use [clojure.test]))
+
+(deftest not-found-error
+ (let [request {:uri "/error"}
+ response (routes request)]
+ (testing "not-found"
+ (is (nil? response)))))
+
+(deftest default-page
+ (let [request {:uri "/" :request-method :get}
+ response (routes request)]
+ (testing "default page"
+ (is (= 200 (:status response)))
+ (is (= "<h2>Hello World</h2>" (:body response))))))
@@ -0,0 +1,78 @@
+(ns basic-with-authentication.core-test
+ (:use [basic-with-authentication.core] :reload-all)
+ (:use clojure.test
+ ring.middleware.params)
+ (:use (sandbar core
+ stateful-session
+ form-authentication
+ [test :only (t)])
+ )
+ (:require [basic-with-authentication.auth :as auth]
+ [basic-with-authentication.html :as html]
+ [ring.util.test :as tu]))
+
+(def session-key :sandbar.stateful-session/session)
+
+(deftest not-found-error
+ (let [request {:uri "/error"}
+ response (routes request)]
+ (testing "not-found"
+ (is (= 404 (:status response)))
+ (is (re-find #"Not Found" (:body response))))))
+
+(deftest default-page
+ (binding [*sandbar-session* (atom {})]
+ (let [request {:uri "/" :request-method :get}
+ response (routes request)]
+ (testing "default page"
+ (is (= 200 (:status response)))
+ (is (re-find #"Hello World" (:body response)))
+ (is (re-find #"screen.css" (:body response)))))))
+
+(deftest decorated-default-page
+ (binding [*sandbar-session* (atom {})]
+ (let [request {:uri "/" :request-method :get}
+ response (application-routes request)]
+ (is (= 302 (:status response)))
+ (is (= "/login" ((:headers response) "Location" ))))))
+
+(deftest decorated-login-page
+ (binding [*sandbar-session* (atom {})]
+ (let [request {:uri "/login" :request-method :get}
+ response (application-routes request)]
+ (is (= 200 (:status response)))
+ (is (re-find #"Login" (:body response)))
+ (is (re-find #"Username" (:body response)))
+ (is (re-find #"Password" (:body response))))))
+
+(deftest file-delivery
+ (let [request {:uri "/stylesheets/screen.css" :request-method :get}
+ response (routes request)]
+ (testing "file delivery"
+ (is (= 200 (:status response)))
+ (is (.exists (response :body)))
+ (is (.isFile (response :body)))
+ (is (= "screen.css" (.getName (response :body)))))))
+
+(comment
+ (deftest test-login-page
+ (binding [*sandbar-session* (atom {})]
+ (let [request {:uri "/login" :request-method :post}
+ response (application-routes request)]
+ response))))
+
+(comment
+ (def wrapped-echo (wrap-params identity)))
+
+(comment
+ (deftest test-login-page-login
+ (binding [*sandbar-session* (atom {})]
+ (let [request {:uri "/login" :request-method :post
+ :query-string nil
+ :content-type "application/x-www-form-urlencoded"
+ :body (tu/string-input-stream "username=example&password=password&submit=Login")}
+ response (application-routes #_request (wrapped-echo request))]
+ response))))
+
+
+

0 comments on commit adde3db

Please sign in to comment.