session tokens stored in redis now; tests extended

This commit is contained in:
Christian Mueller
2012-06-18 20:55:26 +02:00
parent b080c472f2
commit 0fcf4742e3
5 changed files with 102 additions and 60 deletions
+30 -20
View File
@@ -5,23 +5,33 @@
(def test-title "Some title.")
(def test-note "This is a test note.")
(testing "Storage"
(testing "of correct note creation"
(is (= (do
(set-note date test-title test-note)
(get-note date test-title))
test-note))
(is (= "1" (get-note-views date test-title)))
(is (= (do
(get-note date test-title)
(get-note-views date test-title))
"2")))
(testing "of the note access"
(is (not= (get-note date test-title) "any text")))
(testing "of note existence"
(is (note-exists? date test-title))
(is (not (do
(delete-note date test-title)
(note-exists? date test-title))))
(is (not (note-exists? [2013 06 03] test-title)))
(is (not (note-exists? date "some title")))))
(deftest storage
(testing "Storage"
(testing "of correct note creation"
(is (= (do
(set-note date test-title test-note)
(get-note date test-title))
test-note))
(is (= "1" (get-note-views date test-title)))
(is (= (do
(get-note date test-title)
(get-note-views date test-title))
"2")))
(testing "of the note access"
(is (not= (get-note date test-title) "any text")))
(testing "session management"
(let [s1 (create-session)
s2 (create-session)
s3 (create-session)]
(is (invalidate-session s1))
(is (not (invalidate-session (str s1 s2))))
(is (invalidate-session s2))
(is (not (invalidate-session "wrongtoken")))
(is (invalidate-session s3))))
(testing "of note existence"
(is (note-exists? date test-title))
(is (not (do
(delete-note date test-title)
(note-exists? date test-title))))
(is (not (note-exists? [2013 06 03] test-title)))
(is (not (note-exists? date "some title"))))))
+37 -14
View File
@@ -1,13 +1,15 @@
(ns NoteHub.test.views.pages
(:require [NoteHub.crossover.lib :as lib])
(:use [NoteHub.views.pages]
[noir.util.test]
[clojure.contrib.string :only [substring?]]
[NoteHub.views.common :only [url]]
[NoteHub.storage]
[clojure.test]))
(def date [2012 6 3])
(def test-title "some-title")
(def test-note "# This is a test note.\nHello _world_.")
(def test-note "# This is a test note.\nHello _world_. Motörhead, тест.")
(defn create-testnote-fixture [f]
(set-note date test-title test-note)
@@ -29,22 +31,43 @@
(md-to-html "#_hellö_ __world__\ntest `code`")))))
(deftest export-test
(testing "Markdown export"
(has-body (send-request (url 2012 6 3 "some-title" "export")) test-note)))
(is (has-body (send-request (url 2012 6 3 "some-title" "export")) test-note))))
(deftest note-creation
(let [session-key (create-session)
date (get-date)
; TODO: replace note generation by a function from pages.clj
title "this-is-a-test-note"
[year month day] date]
(testing "Note creation"
(is (has-status
(send-request
[:post "/post-note"]
{:session-key session-key
:draft test-note
:session-value (str (lib/hash #(.codePointAt % 0)
(str test-note session-key)))}) 302))
(is (note-exists? date title))
(is (substring? "Hello <em>world</em>"
((send-request (url year month day title)) :body)))
(is (do
(delete-note date title)
(not (note-exists? date title)))))))
(deftest requests
(testing "HTTP Status"
(testing "of a wrong access"
(has-status (send-request "/wrong-page") 404)
(has-status (send-request (url 2012 6 3 "lol" "stat")) 404)
(has-status (send-request (url 2012 6 3 "lol" "export")) 404)
(has-status (send-request (url 2012 6 3 "lol")) 404)
(has-status (send-request (url 2012 6 4 "wrong-title")) 404))
(is (has-status (send-request "/wrong-page") 404))
(is (has-status (send-request (url 2012 6 3 "lol" "stat")) 404))
(is (has-status (send-request (url 2012 6 3 "lol" "export")) 404))
(is (has-status (send-request (url 2012 6 3 "lol")) 404))
(is (has-status (send-request (url 2012 6 4 "wrong-title")) 404)))
(testing "of corrupt note-post"
(has-status (send-request [:post "/post-note"]) 400))
(is (has-status (send-request [:post "/post-note"]) 400)))
(testing "valid accesses"
(has-status (send-request "/new") 200)
(has-status (send-request (url 2012 6 3 "some-title")) 200)
(has-status (send-request (url 2012 6 3 "some-title" "export")) 200)
(has-status (send-request (url 2012 6 3 "some-title" "stat")) 200)
(has-status (send-request (url 2012 6 3 "some-title")) 200)
(has-status (send-request "/") 200))))
(is (has-status (send-request "/new") 200))
(is (has-status (send-request (url 2012 6 3 "some-title")) 200))
(is (has-status (send-request (url 2012 6 3 "some-title" "export")) 200))
(is (has-status (send-request (url 2012 6 3 "some-title" "stat")) 200))
(is (has-status (send-request (url 2012 6 3 "some-title")) 200))
(is (has-status (send-request "/") 200)))))