forked from abedra/clojure-web
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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))))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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)))))) |
78 changes: 78 additions & 0 deletions
78
separation-anxiety/test/basic_with_authentication/core_test.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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)))) | |||
|
|||
|
|||
|