renamed paths to urls back

This commit is contained in:
Christian Mueller
2014-01-19 09:57:22 +01:00
parent c84909d891
commit 99ac828ba3
6 changed files with 66 additions and 66 deletions
+8 -8
View File
@@ -1,5 +1,5 @@
(ns NoteHub.test.api
(:require
(:require
[cheshire.core :refer :all]
[NoteHub.storage :as storage])
(:use [NoteHub.api]
@@ -10,7 +10,7 @@
(def pid "somePlugin")
(def pid2 "somePlugin2")
(def note-title (str (apply print-str (get-date)) " hello-world-this-is-a-test-note"))
(def note-url (str (apply str (interpose "/" (get-date))) "/hello-world-this-is-a-test-note"))
(def note-url (str (apply str domain "/" (interpose "/" (get-date))) "/hello-world-this-is-a-test-note"))
(defn substring? [a b] (not (= nil (re-matches (re-pattern (str "(?s).*" a ".*")) b))))
(defmacro isnt [arg] `(is (not ~arg)))
@@ -43,8 +43,8 @@
(is (:success (:status post-response)))
(is (:success (:status get-response)))
(is (= note (:note get-response)))
(is (= (:longPath post-response) (:longPath get-response) note-url))
(is (= (:shortPath post-response) (:shortPath get-response)))
(is (= (:longURL post-response) (:longURL get-response) note-url))
(is (= (:shortURL post-response) (:shortURL get-response)))
(is (= "1" (get-in get-response [:statistics :views])))
(isnt (get-in get-response [:statistics :edited]))
(is (= "2" (get-in (get-note (:noteID post-response)) [:statistics :views])))))
@@ -74,12 +74,12 @@
(isnt (:success (:status update-response)))
(is (= "signature invalid" (:message (:status update-response)))))
(is (= note (:note (get-note note-id))))
(let [update-response (update-note note-id new-note pid
(let [update-response (update-note note-id new-note pid
(get-signature pid psk note-id new-note "passwd") "passwd")]
(is (= { :success true } (:status update-response)))
(isnt (= nil (get-in (get-note note-id) [:statistics :edited])))
(is (= new-note (:note (get-note note-id)))))
(let [update-response (update-note note-id "aaa" pid
(let [update-response (update-note note-id "aaa" pid
(get-signature pid psk note-id "aaa" "pass") "pass")]
(isnt (:success (:status update-response)))
(is (= "password invalid" (:message (:status update-response)))))
@@ -99,7 +99,7 @@
(is (get-in body ["status" "success"]))
(is (= note ((parse-string
(:body (send-request [:get "/api/note"] {:version "1.0" :noteID noteID}))) "note")))
(is (do
(is (do
(storage/delete-note noteID)
(not (storage/note-exists? noteID)))))))
@@ -148,6 +148,6 @@
(is (substring? "UPDATED CONTENT"
((parse-string
(:body (send-request [:get "/api/note"] {:version "1.0" :noteID noteID}))) "note")))
(is (do
(is (do
(storage/delete-note noteID)
(not (storage/note-exists? noteID)))))))
+22 -22
View File
@@ -35,18 +35,18 @@
title "this-is-a-test-note"
[year month day] date]
(testing "Note creation"
(is (has-status
(send-request
[:post "/post-note"]
{:session session-key
:note test-note
:signature (get-signature session-key test-note)}) 302))
(is (note-exists? (build-key date title)))
(is (substring? "Hello _world_"
((send-request (url year month day title)) :body)))
(is (do
(delete-note (build-key date title))
(not (note-exists? (build-key date title))))))))
(let [resp (send-request
[:post "/post-note"]
{:session session-key
:note test-note
:signature (get-signature session-key test-note)})]
(is (has-status resp 302))
(is (note-exists? (build-key date title)))
(is (substring? "Hello _world_"
((send-request (url year month day title)) :body)))
(is (do
(delete-note (build-key date title))
(not (note-exists? (build-key date title)))))))))
(deftest note-creation-utf
(let [session-key (create-session)
@@ -55,15 +55,15 @@
note "# Радуга\nкаждый охотник желает знать, где сидят фазаны."
[year month day] date]
(testing "Note creation with UTF8 symbols"
(is (has-status
(send-request
(is (has-status
(send-request
[:post "/post-note"]
{:session session-key
:note note
:signature (get-signature session-key note)}) 302))
(is (note-exists? (build-key date title)))
(is (substring? "знать" ((send-request (url year month day title)) :body)))
(is (do
(is (do
(delete-note (build-key date title))
(not (note-exists? (build-key date title))))))))
@@ -74,8 +74,8 @@
[year month day] date
hash (get-signature session-key test-note)]
(testing "Note update"
(is (has-status
(send-request
(is (has-status
(send-request
[:post "/post-note"]
{:session session-key
:note test-note
@@ -83,21 +83,21 @@
:signature hash}) 302))
(is (note-exists? (build-key date title)))
(is (substring? "test note" ((send-request (url year month day title)) :body)))
(is (has-status
(send-request
(is (has-status
(send-request
[:post "/update-note"]
{:noteID (build-key [year month day] title)
:note "WRONG pass"
:password "qwerty1" }) 403))
(is (substring? "test note" ((send-request (url year month day title)) :body)))
(is (has-status
(send-request
(is (has-status
(send-request
[:post "/update-note"]
{:noteID (build-key [year month day] title)
:note "UPDATED CONTENT 123"
:password "qwerty" }) 302))
(is (substring? "UPDATED CONTENT" ((send-request (url year month day title)) :body)))
(is (do
(is (do
(delete-note (build-key date title))
(not (note-exists? (build-key date title))))))))