PageRenderTime 51ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/src/test/clojure/plugboard/demos/forms/test_responses.clj

http://github.com/malcolmsparks/plugboard
Clojure | 54 lines | 33 code | 6 blank | 15 comment | 4 complexity | 8940dfeb20ecbe0eb5e381b8032e4c75 MD5 | raw file
Possible License(s): AGPL-3.0
  1. ;; Copyright 2010 Malcolm Sparks.
  2. ;;
  3. ;; This file is part of Plugboard.
  4. ;;
  5. ;; Plugboard is free software: you can redistribute it and/or modify it under the
  6. ;; terms of the GNU Affero General Public License as published by the Free
  7. ;; Software Foundation, either version 3 of the License, or (at your option) any
  8. ;; later version.
  9. ;;
  10. ;; Plugboard is distributed in the hope that it will be useful but WITHOUT ANY
  11. ;; WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. ;; A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. ;; details.
  14. ;;
  15. ;; Please see the LICENSE file for a copy of the GNU Affero General Public License.
  16. (ns plugboard.demos.forms.test-responses
  17. (:use
  18. clojure.test
  19. compojure.core
  20. plugboard.demos.jetty-fixture
  21. clojure.data.zip.xml
  22. plugboard.util)
  23. (:require
  24. [clj-http.client :as http]
  25. [ring.util.codec :as codec]
  26. [clojure.string :as string]
  27. plugboard.demos.forms.configuration))
  28. (defroutes main-routes
  29. (ANY "/forms/*" []
  30. (ring.middleware.params/wrap-params
  31. (create-handler (plugboard.demos.forms.configuration/create-plugboard)))))
  32. (use-fixtures :once (make-fixture main-routes))
  33. (deftest test-get
  34. (let [url "http://localhost:%d/forms/index.html"
  35. response (http/get (format url (get-jetty-port)))
  36. form-doc (body-zip response)
  37. form (xml1-> form-doc :form)]
  38. (is (= 200 (get response :status)))
  39. (is (not (nil? form)))))
  40. (deftest test-post
  41. (dosync (ref-set plugboard.demos.forms.webfunctions/favorites {}))
  42. (is (empty? @plugboard.demos.forms.webfunctions/favorites))
  43. (let [url "http://localhost:%d/forms/submit.html"
  44. response (post-form (format url (get-jetty-port)) {"key" "fish"
  45. "value" "herring"
  46. "submit" "submit"})]
  47. (is (= 200 (get response :status)))
  48. (is (= @plugboard.demos.forms.webfunctions/favorites {"fish" "herring"}))))