Permalink
Browse files

Trying out test API routes.

  • Loading branch information...
1 parent cd6a705 commit 063b652ff7b639f4a21fd29ebd2a584f914bf2bc @ifesdjeen committed May 20, 2012
View
5 project.clj
@@ -5,8 +5,11 @@
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.3.0"]
[clj-http "0.4.1" :exclusions [org.clojure/clojure]]
- [org.clojure/data.json "0.1.2"]]
+ [clj-http-fake "0.3.0"]
+ [org.clojure/data.json "0.1.2"]]
+ :profiles {:dev {:resource-paths ["test/resources"]}}
:test-selectors {:default (fn [v] (not (:network-bound v)))
:all (constantly true)
:network-bound :network-bound
+ :fake-api :fake-api
:focus :focus})
View
230 test/resources/api/users.json
@@ -0,0 +1,230 @@
+[{
+ "id": 1864467,
+ "kind": "user",
+ "permalink": "user5892134",
+ "username": "user5892134",
+ "uri": "http://api.sandbox-soundcloud.com/users/1864467",
+ "permalink_url": "http://sandbox-soundcloud.com/user5892134",
+ "avatar_url": "http://a1-sandbox.sndcdn.com/images/default_avatar_large.png?7c7e5ff",
+ "country": null,
+ "full_name": "",
+ "city": null,
+ "description": null,
+ "discogs_name": null,
+ "myspace_name": null,
+ "website": null,
+ "website_title": null,
+ "online": false,
+ "track_count": 0,
+ "playlist_count": 0,
+ "public_favorites_count": 0,
+ "followers_count": 0,
+ "followings_count": 0
+},
+{
+ "id": 1864464,
+ "kind": "user",
+ "permalink": "user6519826",
+ "username": "user6519826",
+ "uri": "http://api.sandbox-soundcloud.com/users/1864464",
+ "permalink_url": "http://sandbox-soundcloud.com/user6519826",
+ "avatar_url": "http://a1-sandbox.sndcdn.com/images/default_avatar_large.png?7c7e5ff",
+ "country": null,
+ "full_name": "",
+ "city": null,
+ "description": null,
+ "discogs_name": null,
+ "myspace_name": null,
+ "website": null,
+ "website_title": null,
+ "online": false,
+ "track_count": 0,
+ "playlist_count": 0,
+ "public_favorites_count": 0,
+ "followers_count": 0,
+ "followings_count": 0
+},
+{
+ "id": 1864459,
+ "kind": "user",
+ "permalink": "user3882667",
+ "username": "user3882667",
+ "uri": "http://api.sandbox-soundcloud.com/users/1864459",
+ "permalink_url": "http://sandbox-soundcloud.com/user3882667",
+ "avatar_url": "http://a1-sandbox.sndcdn.com/images/default_avatar_large.png?7c7e5ff",
+ "country": null,
+ "full_name": "",
+ "city": null,
+ "description": null,
+ "discogs_name": null,
+ "myspace_name": null,
+ "website": null,
+ "website_title": null,
+ "online": false,
+ "track_count": 0,
+ "playlist_count": 0,
+ "public_favorites_count": 0,
+ "followers_count": 0,
+ "followings_count": 0
+},
+{
+ "id": 1864443,
+ "kind": "user",
+ "permalink": "acassiorecoba",
+ "username": "acassiorecoba",
+ "uri": "http://api.sandbox-soundcloud.com/users/1864443",
+ "permalink_url": "http://sandbox-soundcloud.com/acassiorecoba",
+ "avatar_url": "http://i1.sndcdn.com/avatars-000001041911-drxf0w-large.jpg?7c7e5ff",
+ "country": "Brazil",
+ "full_name": "Raimundo Ac\u00e1ssio Andrade Junior",
+ "city": "Teresina",
+ "description": null,
+ "discogs_name": null,
+ "myspace_name": null,
+ "website": null,
+ "website_title": null,
+ "online": false,
+ "track_count": 0,
+ "playlist_count": 0,
+ "public_favorites_count": 1,
+ "followers_count": 0,
+ "followings_count": 0
+},
+{
+ "id": 1864439,
+ "kind": "user",
+ "permalink": "i-aac",
+ "username": "i$aac",
+ "uri": "http://api.sandbox-soundcloud.com/users/1864439",
+ "permalink_url": "http://sandbox-soundcloud.com/i-aac",
+ "avatar_url": "http://i1.sndcdn.com/avatars-000001041907-f34v1k-large.jpg?7c7e5ff",
+ "country": "United States",
+ "full_name": "issac baker",
+ "city": "detroit",
+ "description": null,
+ "discogs_name": null,
+ "myspace_name": null,
+ "website": null,
+ "website_title": null,
+ "online": false,
+ "track_count": 0,
+ "playlist_count": 0,
+ "public_favorites_count": 0,
+ "followers_count": 0,
+ "followings_count": 0
+},
+{
+ "id": 1864436,
+ "kind": "user",
+ "permalink": "dheyvisson",
+ "username": "Dheyvisson Rodrigues",
+ "uri": "http://api.sandbox-soundcloud.com/users/1864436",
+ "permalink_url": "http://sandbox-soundcloud.com/dheyvisson",
+ "avatar_url": "http://a1-sandbox.sndcdn.com/images/default_avatar_large.png?7c7e5ff",
+ "country": null,
+ "full_name": "Dheyvisson Rodrigues",
+ "city": null,
+ "description": null,
+ "discogs_name": null,
+ "myspace_name": null,
+ "website": null,
+ "website_title": null,
+ "online": false,
+ "track_count": 0,
+ "playlist_count": 0,
+ "public_favorites_count": 1,
+ "followers_count": 0,
+ "followings_count": 0
+},
+{
+ "id": 1864428,
+ "kind": "user",
+ "permalink": "user154660",
+ "username": "user154660",
+ "uri": "http://api.sandbox-soundcloud.com/users/1864428",
+ "permalink_url": "http://sandbox-soundcloud.com/user154660",
+ "avatar_url": "http://a1-sandbox.sndcdn.com/images/default_avatar_large.png?7c7e5ff",
+ "country": null,
+ "full_name": "",
+ "city": null,
+ "description": null,
+ "discogs_name": null,
+ "myspace_name": null,
+ "website": null,
+ "website_title": null,
+ "online": false,
+ "track_count": 0,
+ "playlist_count": 0,
+ "public_favorites_count": 0,
+ "followers_count": 0,
+ "followings_count": 0
+},
+{
+ "id": 1864427,
+ "kind": "user",
+ "permalink": "pavilionage",
+ "username": "PavilionAge",
+ "uri": "http://api.sandbox-soundcloud.com/users/1864427",
+ "permalink_url": "http://sandbox-soundcloud.com/pavilionage",
+ "avatar_url": "http://i1.sndcdn.com/avatars-000001041896-k08np3-large.jpg?7c7e5ff",
+ "country": "Romania",
+ "full_name": "Pavilion Age",
+ "city": "Bucharest",
+ "description": null,
+ "discogs_name": null,
+ "myspace_name": null,
+ "website": null,
+ "website_title": null,
+ "online": false,
+ "track_count": 0,
+ "playlist_count": 0,
+ "public_favorites_count": 0,
+ "followers_count": 0,
+ "followings_count": 0
+},
+{
+ "id": 1864425,
+ "kind": "user",
+ "permalink": "agataleanza",
+ "username": "AgataLeanza",
+ "uri": "http://api.sandbox-soundcloud.com/users/1864425",
+ "permalink_url": "http://sandbox-soundcloud.com/agataleanza",
+ "avatar_url": "http://i1.sndcdn.com/avatars-000001041894-3489tw-large.jpg?7c7e5ff",
+ "country": "Italy",
+ "full_name": "",
+ "city": "Ravenna",
+ "description": null,
+ "discogs_name": null,
+ "myspace_name": null,
+ "website": null,
+ "website_title": null,
+ "online": false,
+ "track_count": 3,
+ "playlist_count": 0,
+ "public_favorites_count": 0,
+ "followers_count": 0,
+ "followings_count": 0
+},
+{
+ "id": 1864423,
+ "kind": "user",
+ "permalink": "user1876962",
+ "username": "user1876962",
+ "uri": "http://api.sandbox-soundcloud.com/users/1864423",
+ "permalink_url": "http://sandbox-soundcloud.com/user1876962",
+ "avatar_url": "http://a1-sandbox.sndcdn.com/images/default_avatar_large.png?7c7e5ff",
+ "country": null,
+ "full_name": "",
+ "city": null,
+ "description": null,
+ "discogs_name": null,
+ "myspace_name": null,
+ "website": null,
+ "website_title": null,
+ "online": false,
+ "track_count": 0,
+ "playlist_count": 0,
+ "public_favorites_count": 0,
+ "followers_count": 0,
+ "followings_count": 0
+}]
View
230 test/resources/api/users_page_2.json
@@ -0,0 +1,230 @@
+[{
+ "id": 1864421,
+ "kind": "user",
+ "permalink": "miss-4",
+ "username": "MISS DRAYZER",
+ "uri": "http://api.sandbox-soundcloud.com/users/1864421",
+ "permalink_url": "http://sandbox-soundcloud.com/miss-4",
+ "avatar_url": "http://i1.sndcdn.com/avatars-000001041891-9h6g2y-large.jpg?7c7e5ff",
+ "country": "Spain",
+ "full_name": "MISS DRAYZER",
+ "city": "barcelona",
+ "description": null,
+ "discogs_name": null,
+ "myspace_name": null,
+ "website": null,
+ "website_title": null,
+ "online": false,
+ "track_count": 0,
+ "playlist_count": 0,
+ "public_favorites_count": 0,
+ "followers_count": 0,
+ "followings_count": 0
+},
+{
+ "id": 1864420,
+ "kind": "user",
+ "permalink": "solposto",
+ "username": "SolPosto",
+ "uri": "http://api.sandbox-soundcloud.com/users/1864420",
+ "permalink_url": "http://sandbox-soundcloud.com/solposto",
+ "avatar_url": "http://i1.sndcdn.com/avatars-000001041890-noi8r7-large.jpg?7c7e5ff",
+ "country": "Brazil",
+ "full_name": "Jo\u00e3o SolPosto",
+ "city": "Brasil",
+ "description": null,
+ "discogs_name": null,
+ "myspace_name": null,
+ "website": null,
+ "website_title": null,
+ "online": false,
+ "track_count": 0,
+ "playlist_count": 0,
+ "public_favorites_count": 0,
+ "followers_count": 0,
+ "followings_count": 0
+},
+{
+ "id": 1864417,
+ "kind": "user",
+ "permalink": "user5068846",
+ "username": "user5068846",
+ "uri": "http://api.sandbox-soundcloud.com/users/1864417",
+ "permalink_url": "http://sandbox-soundcloud.com/user5068846",
+ "avatar_url": "http://a1-sandbox.sndcdn.com/images/default_avatar_large.png?7c7e5ff",
+ "country": null,
+ "full_name": "",
+ "city": null,
+ "description": null,
+ "discogs_name": null,
+ "myspace_name": null,
+ "website": null,
+ "website_title": null,
+ "online": false,
+ "track_count": 0,
+ "playlist_count": 0,
+ "public_favorites_count": 0,
+ "followers_count": 0,
+ "followings_count": 0
+},
+{
+ "id": 1864415,
+ "kind": "user",
+ "permalink": "user3255444",
+ "username": "user3255444",
+ "uri": "http://api.sandbox-soundcloud.com/users/1864415",
+ "permalink_url": "http://sandbox-soundcloud.com/user3255444",
+ "avatar_url": "http://a1-sandbox.sndcdn.com/images/default_avatar_large.png?7c7e5ff",
+ "country": null,
+ "full_name": "",
+ "city": null,
+ "description": null,
+ "discogs_name": null,
+ "myspace_name": null,
+ "website": null,
+ "website_title": null,
+ "online": false,
+ "track_count": 0,
+ "playlist_count": 0,
+ "public_favorites_count": 0,
+ "followers_count": 0,
+ "followings_count": 0
+},
+{
+ "id": 1864413,
+ "kind": "user",
+ "permalink": "multiple-assazsin",
+ "username": "multiple assazsin",
+ "uri": "http://api.sandbox-soundcloud.com/users/1864413",
+ "permalink_url": "http://sandbox-soundcloud.com/multiple-assazsin",
+ "avatar_url": "http://i1.sndcdn.com/avatars-000001041886-1p6yrc-large.jpg?7c7e5ff",
+ "country": "United States",
+ "full_name": "mario springs",
+ "city": "Hickory",
+ "description": null,
+ "discogs_name": null,
+ "myspace_name": null,
+ "website": null,
+ "website_title": null,
+ "online": false,
+ "track_count": 0,
+ "playlist_count": 0,
+ "public_favorites_count": 0,
+ "followers_count": 0,
+ "followings_count": 0
+},
+{
+ "id": 1864412,
+ "kind": "user",
+ "permalink": "user6740803",
+ "username": "user6740803",
+ "uri": "http://api.sandbox-soundcloud.com/users/1864412",
+ "permalink_url": "http://sandbox-soundcloud.com/user6740803",
+ "avatar_url": "http://a1-sandbox.sndcdn.com/images/default_avatar_large.png?7c7e5ff",
+ "country": null,
+ "full_name": "",
+ "city": null,
+ "description": null,
+ "discogs_name": null,
+ "myspace_name": null,
+ "website": null,
+ "website_title": null,
+ "online": false,
+ "track_count": 0,
+ "playlist_count": 0,
+ "public_favorites_count": 0,
+ "followers_count": 0,
+ "followings_count": 0
+},
+{
+ "id": 1864407,
+ "kind": "user",
+ "permalink": "revolutionaryrebel",
+ "username": "revolutionaryrebel",
+ "uri": "http://api.sandbox-soundcloud.com/users/1864407",
+ "permalink_url": "http://sandbox-soundcloud.com/revolutionaryrebel",
+ "avatar_url": "http://a1-sandbox.sndcdn.com/images/default_avatar_large.png?7c7e5ff",
+ "country": null,
+ "full_name": "",
+ "city": null,
+ "description": null,
+ "discogs_name": null,
+ "myspace_name": null,
+ "website": null,
+ "website_title": null,
+ "online": false,
+ "track_count": 0,
+ "playlist_count": 0,
+ "public_favorites_count": 0,
+ "followers_count": 0,
+ "followings_count": 0
+},
+{
+ "id": 1864404,
+ "kind": "user",
+ "permalink": "myysilva",
+ "username": "MyySilva",
+ "uri": "http://api.sandbox-soundcloud.com/users/1864404",
+ "permalink_url": "http://sandbox-soundcloud.com/myysilva",
+ "avatar_url": "http://a1-sandbox.sndcdn.com/images/default_avatar_large.png?7c7e5ff",
+ "country": null,
+ "full_name": "Michele Jesus",
+ "city": "",
+ "description": null,
+ "discogs_name": null,
+ "myspace_name": null,
+ "website": null,
+ "website_title": null,
+ "online": false,
+ "track_count": 0,
+ "playlist_count": 0,
+ "public_favorites_count": 1,
+ "followers_count": 0,
+ "followings_count": 0
+},
+{
+ "id": 1864402,
+ "kind": "user",
+ "permalink": "user1640888",
+ "username": "user1640888",
+ "uri": "http://api.sandbox-soundcloud.com/users/1864402",
+ "permalink_url": "http://sandbox-soundcloud.com/user1640888",
+ "avatar_url": "http://a1-sandbox.sndcdn.com/images/default_avatar_large.png?7c7e5ff",
+ "country": null,
+ "full_name": "",
+ "city": null,
+ "description": null,
+ "discogs_name": null,
+ "myspace_name": null,
+ "website": null,
+ "website_title": null,
+ "online": false,
+ "track_count": 0,
+ "playlist_count": 0,
+ "public_favorites_count": 0,
+ "followers_count": 0,
+ "followings_count": 0
+},
+{
+ "id": 1864401,
+ "kind": "user",
+ "permalink": "user9572988",
+ "username": "Josiane",
+ "uri": "http://api.sandbox-soundcloud.com/users/1864401",
+ "permalink_url": "http://sandbox-soundcloud.com/user9572988",
+ "avatar_url": "http://a1-sandbox.sndcdn.com/images/default_avatar_large.png?7c7e5ff",
+ "country": "Brazil",
+ "full_name": "Josiane",
+ "city": "",
+ "description": null,
+ "discogs_name": null,
+ "myspace_name": null,
+ "website": null,
+ "website_title": null,
+ "online": false,
+ "track_count": 0,
+ "playlist_count": 0,
+ "public_favorites_count": 0,
+ "followers_count": 0,
+ "followings_count": 0
+}]
View
2 test/soundcloud_clj/me_test.clj
@@ -22,7 +22,7 @@
(doseq [field (keys track)]
(is (some #(= field %) my-track-fields))))))
-(deftest ^{ :network-bound true :focus true } followings-test
+(deftest ^{ :network-bound true } followings-test
(testing "Get my-tracks API request"
(let [user-id 1888239]
(me/unfollow-user user-id oauth-token)
View
15 test/soundcloud_clj/test_helper.clj
@@ -1,5 +1,6 @@
(ns soundcloud-clj.test-helper
- (:require [soundcloud-clj.config :as config]))
+ (:require [clojure.java.io :as io]
+ [soundcloud-clj.config :as config]))
(def ^:const client-id (get (System/getenv) "CLIENT_ID"))
@@ -19,4 +20,14 @@
(def ^:const me-fields [ :country :private-tracks-count :plan :kind :avatar-url :discogs-name :track-count :permalink-url :full-name :public-favorites-count :private-playlists-count :uri :city :username :permalink :followers-count :playlist-count :online :myspace-name :followings-count :primary-email-confirmed :id :website :website-title :description])
-(def ^:const my-track-fields [ :license :artwork-url :download-url :duration :release-year :downloads-remaining :label-id :kind :state :sharing :user-id :playback-count :user-favorite :label-name :waveform-url :bpm :purchase-title :permalink-url :download-count :downloadable :isrc :favoritings-count :streamable :title :uri :release-day :permalink :genre :secret-token :original-content-size :video-url :release-month :release :commentable :user-playback-count :created-at :user :comment-count :key-signature :purchase-url :stream-url :attachments-uri :secret-uri :id :track-type :tag-list :description :original-format ])
+(def ^:const my-track-fields [ :license :artwork-url :download-url :duration :release-year :downloads-remaining :label-id :kind :state :sharing :user-id :playback-count :user-favorite :label-name :waveform-url :bpm :purchase-title :permalink-url :download-count :downloadable :isrc :favoritings-count :streamable :title :uri :release-day :permalink :genre :secret-token :original-content-size :video-url :release-month :release :commentable :user-playback-count :created-at :user :comment-count :key-signature :purchase-url :stream-url :attachments-uri :secret-uri :id :track-type :tag-list :description :original-format ])
+
+(def ^:const fake-routes
+ { (format "http://api.sandbox-soundcloud.com/users.json?client_id=%s&offset=0&limit=10" client-id)
+ (fn [request] {:status 200 :headers {:content-type "application/json"}
+ :body (slurp (io/resource (str "api/users.json"))) })
+
+ (format "http://api.sandbox-soundcloud.com/users.json?offset=10&client_id=%s&limit=10" client-id)
+ (fn [request] {:status 200 :headers {:content-type "application/json"}
+ :body (slurp (io/resource (str "api/users_page_2.json"))) })
+ })
View
18 test/soundcloud_clj/users_test.clj
@@ -1,6 +1,7 @@
(ns soundcloud-clj.users-test
(:use clojure.test
- soundcloud-clj.test-helper)
+ soundcloud-clj.test-helper
+ clj-http.fake)
(:require [soundcloud-clj.users :as users]))
(initialize-endpoint!)
@@ -52,4 +53,17 @@
following (first followers)]
(is (= 10 (count followers)))
(doseq [field (keys following)]
- (is (some #(= field %) user-fields))))))
+ (is (some #(= field %) user-fields))))))
+
+
+(deftest ^{ :fake-api true :focus true } get-users-2-test
+ (testing "Get users API request"
+ (with-fake-routes-in-isolation fake-routes
+ (let [first-page-response (users/get-users)
+ second-page-response (users/get-users :page 2)
+ response-item (first first-page-response)]
+ (is (= 10 (count first-page-response)))
+ (is (= 10 (count second-page-response)))
+ (is (not (= (first first-page-response) (first second-page-response))))
+ (doseq [field (keys response-item)]
+ (is (some #(= field %) user-fields)))))))

0 comments on commit 063b652

Please sign in to comment.