PageRenderTime 26ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/test/oauth/twitter_test.clj

http://github.com/r0man/oauth-clj
Clojure | 91 lines | 77 code | 14 blank | 0 comment | 7 complexity | ebe92ff46cc3add69cbfd5bbfdd203b9 MD5 | raw file
  1. (ns oauth.twitter-test
  2. (:require [clojure.test :refer :all]
  3. [oauth.twitter :refer :all]))
  4. (def example-consumer-key
  5. "qcz2O57srPsb5eZA2Jyw")
  6. (def example-consumer-secret
  7. "lfs5WjmIzPc3OlDNoHSfbxVBmPNmduTDq4rQHhNN7Q")
  8. (def example-access-token
  9. "469240209-QWtxKSP6vzBaH4TrhbgX20zPC2NyjArNlv4rxdFP")
  10. (def example-access-token-secret
  11. "GZQAudgAQPbnazmqryl4RINMVOzH8QGETPzcHFCg")
  12. (def twitter-client
  13. (oauth-client
  14. example-consumer-key
  15. example-consumer-secret
  16. example-access-token
  17. example-access-token-secret))
  18. (def twitter-update-status
  19. {:method :post
  20. :scheme "https"
  21. :server-name "api.twitter.com"
  22. :uri "/1.1/statuses/update.json"
  23. :query-params {:include_entities true}
  24. :body "status=Hello%20Ladies%20%2b%20Gentlemen%2c%20a%20signed%20OAuth%20request%21"
  25. :oauth-consumer-key "xvz1evFS4wEEPTGEFPHBog"
  26. :oauth-nonce "kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg"
  27. :oauth-signature-method "HMAC-SHA1"
  28. :oauth-timestamp "1318622958"
  29. :oauth-token "370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb"
  30. :oauth-version "1.0"})
  31. (def twitter-request-token
  32. {:method :post
  33. :scheme "https"
  34. :server-name "api.twitter.com"
  35. :uri "/oauth/request_token"
  36. :query-params {"oauth_callback" "http://localhost:3005/the_dance/process_callback?service_provider_id=11"}
  37. :oauth-consumer-key "GDdmIQH6jhtmLUypg82g"
  38. :oauth-nonce "QP70eNmVz8jvdPevU3oJD2AfF7R7odC2XJcn4XlZJqk"
  39. :oauth-signature-method "HMAC-SHA1"
  40. :oauth-timestamp "1272323042"
  41. :oauth-version "1.0"})
  42. (deftest test-oauth-authentication-url
  43. (is (= "https://api.twitter.com/oauth/authenticate?oauth_token=370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb"
  44. (oauth-authentication-url "370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb"))))
  45. (deftest test-oauth-authorization-url
  46. (is (= "https://api.twitter.com/oauth/authorize?oauth_token=370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb"
  47. (oauth-authorization-url "370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb"))))
  48. (deftest test-oauth-client
  49. (is (fn? twitter-client)))
  50. (deftest test-oauth-request-token
  51. (let [request-token (oauth-request-token example-consumer-key example-consumer-secret)]
  52. (is (map? request-token))
  53. (is (string? (:oauth-token request-token)))
  54. (is (string? (:oauth-token-secret request-token)))
  55. (is (= "true" (:oauth-callback-confirmed request-token)))))
  56. (deftest test-verify-credentials
  57. (let [user (twitter-client {:method :get :url "https://api.twitter.com/1.1/account/verify_credentials.json"})]
  58. (is (map? user))
  59. (is (= 469240209 (:id user)))
  60. (let [response (meta user)]
  61. (is (= 200 (:status response))))))
  62. (deftest test-update-status-query-params
  63. (let [status (format "Test-q %s" (java.util.Date.))
  64. response (twitter-client
  65. {:method :post
  66. :url "https://api.twitter.com/1.1/statuses/update.json"
  67. :query-params {:status status}})]
  68. (is (string? (:id-str response)))
  69. (is (= status (:text response)))))
  70. (deftest test-update-status-form-params
  71. (let [status (format "Test-f %s" (java.util.Date.))
  72. response (twitter-client
  73. {:method :post
  74. :url "https://api.twitter.com/1.1/statuses/update.json"
  75. :form-params {:status status}})]
  76. (is (string? (:id-str response)))
  77. (is (= status (:text response)))))