flickr.rb 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Changelog.txt +7 -2
- data/Gemfile +4 -0
- data/Gemfile.lock +24 -0
- data/LICENSE +16 -17
- data/Manifest.txt +2 -2
- data/README.txt +3 -1
- data/Rakefile +3 -24
- data/flickr.gemspec +22 -17
- data/lib/flickr.rb +104 -104
- data/rdoc/Flickr.html +1003 -0
- data/rdoc/Flickr/Config.html +267 -0
- data/rdoc/Flickr/Group.html +343 -0
- data/rdoc/Flickr/Photo.html +1396 -0
- data/rdoc/Flickr/PhotoCollection.html +229 -0
- data/rdoc/Flickr/Photoset.html +359 -0
- data/rdoc/Flickr/User.html +745 -0
- data/rdoc/README_txt.html +199 -0
- data/rdoc/created.rid +3 -1
- data/rdoc/fonts.css +167 -0
- data/rdoc/fonts/Lato-Light.ttf +0 -0
- data/rdoc/fonts/Lato-LightItalic.ttf +0 -0
- data/rdoc/fonts/Lato-Regular.ttf +0 -0
- data/rdoc/fonts/Lato-RegularItalic.ttf +0 -0
- data/rdoc/fonts/SourceCodePro-Bold.ttf +0 -0
- data/rdoc/fonts/SourceCodePro-Regular.ttf +0 -0
- data/rdoc/images/add.png +0 -0
- data/rdoc/images/arrow_up.png +0 -0
- data/rdoc/images/brick.png +0 -0
- data/rdoc/images/brick_link.png +0 -0
- data/rdoc/images/bug.png +0 -0
- data/rdoc/images/bullet_black.png +0 -0
- data/rdoc/images/bullet_toggle_minus.png +0 -0
- data/rdoc/images/bullet_toggle_plus.png +0 -0
- data/rdoc/images/date.png +0 -0
- data/rdoc/images/delete.png +0 -0
- data/rdoc/images/find.png +0 -0
- data/rdoc/images/loadingAnimation.gif +0 -0
- data/rdoc/images/macFFBgHack.png +0 -0
- data/rdoc/images/package.png +0 -0
- data/rdoc/images/page_green.png +0 -0
- data/rdoc/images/page_white_text.png +0 -0
- data/rdoc/images/page_white_width.png +0 -0
- data/rdoc/images/plugin.png +0 -0
- data/rdoc/images/ruby.png +0 -0
- data/rdoc/images/tag_blue.png +0 -0
- data/rdoc/images/tag_green.png +0 -0
- data/rdoc/images/transparent.png +0 -0
- data/rdoc/images/wrench.png +0 -0
- data/rdoc/images/wrench_orange.png +0 -0
- data/rdoc/images/zoom.png +0 -0
- data/rdoc/index.html +101 -21
- data/rdoc/js/darkfish.js +140 -0
- data/rdoc/js/jquery.js +18 -0
- data/rdoc/js/navigation.js +142 -0
- data/rdoc/js/search.js +109 -0
- data/rdoc/js/search_index.js +1 -0
- data/rdoc/js/searcher.js +228 -0
- data/rdoc/rdoc.css +580 -0
- data/rdoc/table_of_contents.html +473 -0
- data/test/flickr_test.rb +229 -227
- metadata +132 -68
- data/rdoc/classes/Flickr.html +0 -807
- data/rdoc/classes/Flickr/Config.html +0 -240
- data/rdoc/classes/Flickr/Group.html +0 -251
- data/rdoc/classes/Flickr/Photo.html +0 -1101
- data/rdoc/classes/Flickr/PhotoCollection.html +0 -194
- data/rdoc/classes/Flickr/Photoset.html +0 -266
- data/rdoc/classes/Flickr/User.html +0 -738
- data/rdoc/files/README_txt.html +0 -209
- data/rdoc/files/lib/flickr_rb.html +0 -162
- data/rdoc/fr_class_index.html +0 -33
- data/rdoc/fr_file_index.html +0 -28
- data/rdoc/fr_method_index.html +0 -112
- data/rdoc/rdoc-style.css +0 -208
data/test/flickr_test.rb
CHANGED
@@ -1,56 +1,56 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'flickr'
|
3
3
|
require 'test/unit'
|
4
|
-
require 'mocha'
|
4
|
+
require 'mocha/setup'
|
5
5
|
|
6
6
|
class TestFlickr < Test::Unit::TestCase
|
7
7
|
|
8
8
|
# Flickr client tests
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# instantiation tests
|
11
11
|
def test_should_instantiate_new_flickr_client
|
12
12
|
Flickr.any_instance.stubs(:login)
|
13
13
|
flickr = Flickr.new(:api_key => 'some_api_key', :shared_secret => 'some_shared_secret')
|
14
|
-
|
14
|
+
|
15
15
|
assert_equal 'some_api_key', flickr.api_key
|
16
16
|
assert_equal 'some_shared_secret', flickr.instance_variable_get(:@shared_secret)
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def test_should_instantiate_new_flickr_client_on_new_api
|
20
20
|
flickr = Flickr.new(:api_key => 'some_api_key', :shared_secret => 'some_shared_secret', 'foo' => 'bar')
|
21
|
-
|
21
|
+
|
22
22
|
assert_equal 'some_api_key', flickr.api_key
|
23
23
|
assert_equal 'some_shared_secret', flickr.instance_variable_get(:@shared_secret)
|
24
24
|
assert_nil flickr.instance_variable_get(:@foo) # should ignore other params
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
# signature_from method tests
|
28
28
|
def test_should_return_signature_from_given_params
|
29
|
-
assert_equal Digest::MD5.hexdigest('shared_secret_codea_param1234xb_param5678yc_param97531t'),
|
29
|
+
assert_equal Digest::MD5.hexdigest('shared_secret_codea_param1234xb_param5678yc_param97531t'),
|
30
30
|
authenticated_flickr_client.send(:signature_from, {:b_param => '5678y', 'c_param' => '97531t', :a_param => '1234x', :d_param => nil})
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def test_should_return_nil_for_signature_when_no_shared_secret
|
34
34
|
assert_nil flickr_client.send(:signature_from, {:b_param => '5678y', :c_param => '97531t', :a_param => '1234x'})
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
# request_url method tests
|
38
38
|
def test_should_get_signature_for_params_when_building_url
|
39
39
|
f = authenticated_flickr_client
|
40
|
-
f.expects(:signature_from).with( 'method' => 'flickr.someMethod',
|
41
|
-
'api_key' => 'some_api_key',
|
42
|
-
'foo' => 'value which/needs&escaping',
|
40
|
+
f.expects(:signature_from).with( 'method' => 'flickr.someMethod',
|
41
|
+
'api_key' => 'some_api_key',
|
42
|
+
'foo' => 'value which/needs&escaping',
|
43
43
|
'auth_token' => 'some_auth_token').returns("foo123bar456")
|
44
|
-
|
44
|
+
|
45
45
|
url = f.send(:request_url, 'someMethod', 'foo' => 'value which/needs&escaping')
|
46
46
|
end
|
47
47
|
|
48
48
|
def test_should_build_url_from_params_with_signature
|
49
49
|
f = authenticated_flickr_client
|
50
50
|
f.stubs(:signature_from).returns("foo123bar456")
|
51
|
-
|
51
|
+
|
52
52
|
url = f.send(:request_url, 'someMethod', 'foo' => 'value which/needs&escaping')
|
53
|
-
[ "#{Flickr::HOST_URL}#{Flickr::API_PATH}",
|
53
|
+
[ "#{Flickr::HOST_URL}#{Flickr::API_PATH}",
|
54
54
|
'api_key=some_api_key',
|
55
55
|
'method=flickr.someMethod',
|
56
56
|
'foo=value+which%2Fneeds%26escaping',
|
@@ -63,58 +63,58 @@ class TestFlickr < Test::Unit::TestCase
|
|
63
63
|
def test_should_build_url_from_params_when_signature_returns_nil
|
64
64
|
flickr = flickr_client
|
65
65
|
flickr.stubs(:signature_from)
|
66
|
-
assert_equal "#{Flickr::HOST_URL}#{Flickr::API_PATH}/?method=flickr.someMethod
|
67
|
-
assert_equal "#{Flickr::HOST_URL}#{Flickr::API_PATH}/?
|
68
|
-
assert_equal "#{Flickr::HOST_URL}#{Flickr::API_PATH}/?
|
69
|
-
assert_equal "#{Flickr::HOST_URL}#{Flickr::API_PATH}/?
|
66
|
+
assert_equal "#{Flickr::HOST_URL}#{Flickr::API_PATH}/?api_key=some_api_key&method=flickr.someMethod", flickr.send(:request_url, 'someMethod')
|
67
|
+
assert_equal "#{Flickr::HOST_URL}#{Flickr::API_PATH}/?foo=bar&api_key=some_api_key&method=flickr.someMethod", flickr.send(:request_url, 'someMethod', 'foo' => 'bar', 'foobar' => nil)
|
68
|
+
assert_equal "#{Flickr::HOST_URL}#{Flickr::API_PATH}/?foo=101&api_key=some_api_key&method=flickr.someMethod", flickr.send(:request_url, 'someMethod', 'foo' => 101)
|
69
|
+
assert_equal "#{Flickr::HOST_URL}#{Flickr::API_PATH}/?foo=value+which%2Fneeds%26escaping&api_key=some_api_key&method=flickr.someMethod", flickr.send(:request_url, 'someMethod', 'foo' => 'value which/needs&escaping')
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
# method_missing tests
|
73
73
|
def test_should_generate_flickr_method_from_unkown_method_on_flickr_client
|
74
|
-
f = flickr_client
|
74
|
+
f = flickr_client
|
75
75
|
f.expects(:request).with('some.unknown.methodForFlickr', {})
|
76
76
|
f.some_unknown_methodForFlickr
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
# request method tests
|
80
80
|
def test_should_make_successful_request
|
81
|
-
f = flickr_client
|
81
|
+
f = flickr_client
|
82
82
|
f.expects(:http_get).with('some.url').returns(successful_xml_response)
|
83
83
|
f.expects(:request_url).with('some_method', 'foo' => 'bar').returns("some.url")
|
84
|
-
|
84
|
+
|
85
85
|
f.send(:request, 'some_method', 'foo' => 'bar') # request is protected
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
def test_should_raise_exception_on_unsuccessful_request
|
89
|
-
f = flickr_client
|
89
|
+
f = flickr_client
|
90
90
|
f.expects(:http_get).returns(unsuccessful_xml_response)
|
91
|
-
|
91
|
+
|
92
92
|
assert_raise(RuntimeError) { f.send(:request, 'some_method', 'foo' => 'bar') }
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
def test_should_parse_returned_xml_in_successful_request
|
96
96
|
f = flickr_client
|
97
97
|
f.stubs(:http_get).returns(successful_xml_response)
|
98
|
-
expected_response = { "contacts" => { "perpage" => "1000",
|
99
|
-
"contact" => [{ "nsid"=>"12037949629@N01",
|
100
|
-
"username"=>"Eric",
|
101
|
-
"ignored"=>"1",
|
102
|
-
"family"=>"0",
|
103
|
-
"friend"=>"1",
|
104
|
-
"realname"=>"Eric Costello",
|
105
|
-
"iconserver"=>"1"},
|
106
|
-
{ "nsid"=>"12037949631@N01",
|
107
|
-
"username"=>"neb",
|
108
|
-
"ignored"=>"0",
|
109
|
-
"family"=>"0",
|
110
|
-
"friend"=>"0",
|
111
|
-
"realname"=>"Ben Cerveny",
|
112
|
-
"iconserver"=>"1"}],
|
113
|
-
"total" => "2",
|
114
|
-
"pages"=> "1",
|
115
|
-
"page"=>"1" },
|
98
|
+
expected_response = { "contacts" => { "perpage" => "1000",
|
99
|
+
"contact" => [{ "nsid"=>"12037949629@N01",
|
100
|
+
"username"=>"Eric",
|
101
|
+
"ignored"=>"1",
|
102
|
+
"family"=>"0",
|
103
|
+
"friend"=>"1",
|
104
|
+
"realname"=>"Eric Costello",
|
105
|
+
"iconserver"=>"1"},
|
106
|
+
{ "nsid"=>"12037949631@N01",
|
107
|
+
"username"=>"neb",
|
108
|
+
"ignored"=>"0",
|
109
|
+
"family"=>"0",
|
110
|
+
"friend"=>"0",
|
111
|
+
"realname"=>"Ben Cerveny",
|
112
|
+
"iconserver"=>"1"}],
|
113
|
+
"total" => "2",
|
114
|
+
"pages"=> "1",
|
115
|
+
"page"=>"1" },
|
116
116
|
"stat"=>"ok" }
|
117
|
-
|
117
|
+
|
118
118
|
assert_equal expected_response, f.send(:request, 'some_method', 'foo' => 'bar')
|
119
119
|
end
|
120
120
|
|
@@ -135,24 +135,24 @@ class TestFlickr < Test::Unit::TestCase
|
|
135
135
|
"some_api_key", { "key3" => "value3"})
|
136
136
|
photos = f.photos_request('some_method')
|
137
137
|
end
|
138
|
-
|
138
|
+
|
139
139
|
def test_should_parse_photos_response_into_flickr_photo_collection
|
140
140
|
f = flickr_client
|
141
141
|
f.expects(:request).returns(dummy_photos_response)
|
142
142
|
assert_kind_of Flickr::PhotoCollection, f.photos_request('some_method')
|
143
143
|
end
|
144
|
-
|
144
|
+
|
145
145
|
def test_should_store_pagination_info_in_photo_collection
|
146
146
|
f = flickr_client
|
147
147
|
f.expects(:request).returns(dummy_photos_response)
|
148
148
|
photos = f.photos_request('some_method')
|
149
|
-
|
149
|
+
|
150
150
|
assert_equal "3", photos.page
|
151
151
|
assert_equal "5", photos.pages
|
152
152
|
assert_equal "10", photos.perpage
|
153
153
|
assert_equal "42", photos.total
|
154
154
|
end
|
155
|
-
|
155
|
+
|
156
156
|
def test_should_return_collection_of_photos
|
157
157
|
f = flickr_client
|
158
158
|
f.expects(:request).returns(dummy_photos_response)
|
@@ -183,26 +183,26 @@ class TestFlickr < Test::Unit::TestCase
|
|
183
183
|
f.expects(:signature_from).with('api_key' => 'some_api_key', 'perms' => 'write').returns('validsignature')
|
184
184
|
assert_equal 'http://flickr.com/services/auth/?api_key=some_api_key&perms=write&api_sig=validsignature', f.login_url('write')
|
185
185
|
end
|
186
|
-
|
186
|
+
|
187
187
|
def test_should_get_token_from_frob
|
188
188
|
f = flickr_client
|
189
189
|
f.expects(:request).with('auth.getToken',:frob => 'some_frob').returns({'auth' => {'token' => 'some_auth_token', 'user' => {}}})
|
190
|
-
|
190
|
+
|
191
191
|
auth_token = f.get_token_from('some_frob')
|
192
192
|
assert_equal 'some_auth_token', auth_token
|
193
193
|
end
|
194
|
-
|
194
|
+
|
195
195
|
def test_should_store_auth_token_in_client
|
196
196
|
f = flickr_client
|
197
197
|
f.expects(:request).returns({'auth' => {'token' => 'some_auth_token','user' => {}}})
|
198
198
|
f.get_token_from('some_frob')
|
199
199
|
assert_equal 'some_auth_token', f.auth_token
|
200
200
|
end
|
201
|
-
|
201
|
+
|
202
202
|
def test_should_store_authenticated_user_details_in_client
|
203
203
|
f = flickr_client
|
204
|
-
f.expects(:request).returns({ 'auth' => { 'token' => 'some_auth_token',
|
205
|
-
'user' => { 'nsid' => 'foo123',
|
204
|
+
f.expects(:request).returns({ 'auth' => { 'token' => 'some_auth_token',
|
205
|
+
'user' => { 'nsid' => 'foo123',
|
206
206
|
'username' => 'some_user', 'fullname' => 'Some User'}}})
|
207
207
|
f.get_token_from('some_frob')
|
208
208
|
assert_kind_of Flickr::User, user = f.user
|
@@ -211,14 +211,14 @@ class TestFlickr < Test::Unit::TestCase
|
|
211
211
|
assert_equal 'Some User', user.name
|
212
212
|
assert_equal f, user.client
|
213
213
|
end
|
214
|
-
|
214
|
+
|
215
215
|
# photos method tests
|
216
216
|
def test_should_get_recent_photos_if_no_params_for_photos
|
217
217
|
f = flickr_client
|
218
218
|
f.expects(:recent)
|
219
219
|
f.photos
|
220
220
|
end
|
221
|
-
|
221
|
+
|
222
222
|
# photos_search method tests
|
223
223
|
def test_should_search_photos
|
224
224
|
f = authenticated_flickr_client
|
@@ -226,7 +226,7 @@ class TestFlickr < Test::Unit::TestCase
|
|
226
226
|
photos = f.photos_search
|
227
227
|
assert_kind_of Flickr::Photo, photos.first
|
228
228
|
end
|
229
|
-
|
229
|
+
|
230
230
|
# users method tests
|
231
231
|
def test_should_find_user_from_email
|
232
232
|
f = flickr_client
|
@@ -235,34 +235,34 @@ class TestFlickr < Test::Unit::TestCase
|
|
235
235
|
assert_equal "12037949632@N01", user.id
|
236
236
|
assert_equal "Stewart", user.username
|
237
237
|
end
|
238
|
-
|
238
|
+
|
239
239
|
def test_should_find_user_from_username_if_fails_to_get_from_email
|
240
240
|
f = flickr_client
|
241
241
|
f.expects(:request).with('people.findByEmail', anything).raises
|
242
242
|
f.expects(:request).with('people.findByUsername', anything).returns(dummy_user_response)
|
243
243
|
assert_kind_of Flickr::User, f.users("email@test.com")
|
244
244
|
end
|
245
|
-
|
245
|
+
|
246
246
|
def test_should_pass_on_flickr_client_when_finding_user
|
247
247
|
f = flickr_client
|
248
248
|
f.stubs(:request).returns(dummy_user_response)
|
249
249
|
user = f.users("email@test.com")
|
250
250
|
assert_equal f, user.client
|
251
251
|
end
|
252
|
-
|
252
|
+
|
253
253
|
# groups method tests
|
254
254
|
def test_should_search_for_given_group
|
255
255
|
f = flickr_client
|
256
256
|
f.expects(:request).with("groups.search", {"text" => "foo"}).returns(dummy_groups_response)
|
257
257
|
f.groups("foo")
|
258
258
|
end
|
259
|
-
|
259
|
+
|
260
260
|
def test_should_search_for_given_group_with_additional_params
|
261
261
|
f = flickr_client
|
262
262
|
f.expects(:request).with("groups.search", {"text" => "foo", "per_page" => "1"}).returns(dummy_groups_response)
|
263
263
|
f.groups("foo", "per_page" => "1")
|
264
264
|
end
|
265
|
-
|
265
|
+
|
266
266
|
def test_should_instantiate_groups_from_search_response
|
267
267
|
f = flickr_client
|
268
268
|
f.stubs(:request).returns(dummy_groups_response)
|
@@ -273,7 +273,7 @@ class TestFlickr < Test::Unit::TestCase
|
|
273
273
|
assert_equal "0", group.eighteenplus
|
274
274
|
assert_equal f, group.client
|
275
275
|
end
|
276
|
-
|
276
|
+
|
277
277
|
def test_should_instantiate_groups_from_search_response_with_single_group_returned
|
278
278
|
f = flickr_client
|
279
279
|
f.stubs(:request).returns(dummy_single_group_response)
|
@@ -281,51 +281,51 @@ class TestFlickr < Test::Unit::TestCase
|
|
281
281
|
assert_equal 1, groups.size
|
282
282
|
assert_equal "group1", groups.first.id
|
283
283
|
end
|
284
|
-
|
284
|
+
|
285
285
|
# ##### DIRECT MODE
|
286
|
-
#
|
286
|
+
#
|
287
287
|
# def test_test_echo
|
288
288
|
# assert_equal @f.test_echo['stat'], 'ok'
|
289
289
|
# end
|
290
290
|
# def test_test_login
|
291
291
|
# assert_equal @f.test_login['stat'], 'ok'
|
292
292
|
# end
|
293
|
-
#
|
294
|
-
#
|
293
|
+
#
|
294
|
+
#
|
295
295
|
# ##### BASICS
|
296
|
-
#
|
296
|
+
#
|
297
297
|
# def test_login
|
298
298
|
# assert_equal @username, @f.user.getInfo.username
|
299
299
|
# end
|
300
|
-
#
|
300
|
+
#
|
301
301
|
# def test_find_by_url
|
302
302
|
# assert_equal @group_id, @f.find_by_url(@group_url).getInfo.id # find group by URL
|
303
303
|
# assert_equal @user_id, @f.find_by_url(@user_url).getInfo.id # find user by URL
|
304
304
|
# end
|
305
|
-
#
|
305
|
+
#
|
306
306
|
# def test_licenses
|
307
307
|
# assert_kind_of Array, @f.licenses # find all licenses
|
308
308
|
# end
|
309
|
-
#
|
310
|
-
|
311
|
-
#
|
309
|
+
#
|
310
|
+
|
311
|
+
#
|
312
312
|
# Flickr#photos tests
|
313
|
-
#
|
314
|
-
|
315
|
-
|
313
|
+
#
|
314
|
+
|
315
|
+
|
316
316
|
# ##### Flickr::User tests
|
317
|
-
#
|
317
|
+
#
|
318
318
|
def test_should_instantiate_user
|
319
319
|
user = new_user
|
320
320
|
assert_equal 'foo123', user.id
|
321
321
|
assert_equal 'some_user', user.username
|
322
322
|
assert_equal 'bar', user.instance_variable_get(:@foo) # should collect all other params up and store as instance variables
|
323
323
|
end
|
324
|
-
|
324
|
+
|
325
325
|
def test_should_instantiate_new_user_with_old_api
|
326
326
|
Flickr.any_instance.stubs(:login) # stub logging in
|
327
|
-
user = Flickr::User.new('foo123',
|
328
|
-
'some_user',
|
327
|
+
user = Flickr::User.new('foo123',
|
328
|
+
'some_user',
|
329
329
|
'email@test.com', # email irrelevant since Flickr API no longer supports authentication in this way
|
330
330
|
'password', # password irrelevant since Flickr API no longer supports authentication in this way
|
331
331
|
'bar456')
|
@@ -335,59 +335,59 @@ class TestFlickr < Test::Unit::TestCase
|
|
335
335
|
assert_equal 'password', user.instance_variable_get(:@password)
|
336
336
|
assert_equal 'bar456', user.client.api_key
|
337
337
|
end
|
338
|
-
|
338
|
+
|
339
339
|
def test_should_instantiate_new_client_when_instantiating_user_if_no_client_passed_in_params
|
340
340
|
f = flickr_client
|
341
341
|
Flickr.expects(:new).returns(f)
|
342
342
|
user = new_user( 'api_key' => 'an_api_key' )
|
343
343
|
assert_equal f, user.client
|
344
344
|
end
|
345
|
-
|
345
|
+
|
346
346
|
def test_should_not_instantiate_new_client_when_instantiating_user_if_client_passed_in_params
|
347
347
|
f = flickr_client
|
348
348
|
Flickr.expects(:new).never
|
349
349
|
user = new_user( 'client' => f )
|
350
350
|
assert_equal f, user.client
|
351
351
|
end
|
352
|
-
|
352
|
+
|
353
353
|
def test_should_not_instantiate_client_if_no_api_key_passed
|
354
354
|
Flickr.expects(:new).never
|
355
355
|
user = new_user
|
356
356
|
assert_nil user.client
|
357
357
|
end
|
358
|
-
|
358
|
+
|
359
359
|
def test_should_build_url_for_users_profile_page_using_user_id
|
360
360
|
Flickr.any_instance.expects(:http_get).never
|
361
361
|
assert_equal "http://www.flickr.com/people/foo123/", new_user.url
|
362
362
|
end
|
363
|
-
|
363
|
+
|
364
364
|
def test_should_build_url_for_users_photos_page_using_user_id
|
365
365
|
Flickr.any_instance.expects(:http_get).never
|
366
366
|
assert_equal "http://www.flickr.com/photos/foo123/", new_user.photos_url
|
367
367
|
end
|
368
|
-
|
368
|
+
|
369
369
|
def test_should_get_pretty_url_for_users_profile_page
|
370
370
|
f = flickr_client
|
371
371
|
f.expects(:urls_getUserProfile).returns({"user" => {"nsid" => "bar456", "url" => "http://www.flickr.com/people/killer_bob/"}})
|
372
|
-
|
372
|
+
|
373
373
|
assert_equal "http://www.flickr.com/people/killer_bob/", new_user( 'client' => f ).pretty_url
|
374
374
|
end
|
375
|
-
|
375
|
+
|
376
376
|
def test_should_cache_pretty_url_for_users_profile_page
|
377
377
|
f = flickr_client
|
378
378
|
user = new_user( 'client' => f )
|
379
379
|
f.expects(:urls_getUserProfile).returns({"user" => {"nsid" => "bar456", "url" => "http://www.flickr.com/people/killer_bob/"}}) # expects only one call
|
380
|
-
|
380
|
+
|
381
381
|
user.pretty_url
|
382
382
|
user.pretty_url
|
383
383
|
end
|
384
|
-
|
384
|
+
|
385
385
|
def test_should_get_users_public_groups
|
386
386
|
f = flickr_client
|
387
387
|
f.expects(:request).with("people.getPublicGroups", anything).returns(dummy_groups_response)
|
388
388
|
new_user( 'client' => f ).groups
|
389
389
|
end
|
390
|
-
|
390
|
+
|
391
391
|
def test_should_instantiate_users_public_groups
|
392
392
|
f = flickr_client
|
393
393
|
f.stubs(:request).returns(dummy_groups_response)
|
@@ -401,7 +401,7 @@ class TestFlickr < Test::Unit::TestCase
|
|
401
401
|
assert_equal "0", group.eighteenplus
|
402
402
|
assert_equal f, group.client
|
403
403
|
end
|
404
|
-
|
404
|
+
|
405
405
|
def test_should_instantiate_users_public_groups_when_only_one_returned
|
406
406
|
f = flickr_client
|
407
407
|
f.stubs(:request).returns(dummy_single_group_response)
|
@@ -427,35 +427,35 @@ class TestFlickr < Test::Unit::TestCase
|
|
427
427
|
assert_kind_of Array, pop_tags
|
428
428
|
assert_equal pop_tags, [{"tag"=>"design", "count"=>"94"}, {"tag"=>"offf08", "count"=>"94"}, {"tag"=>"ruby", "count"=>"3"}, {"tag"=>"rubyonrails", "count"=>"3"}, {"tag"=>"wbs", "count"=>"3"}, {"tag"=>"webreakstuff", "count"=>"97"}]
|
429
429
|
end
|
430
|
-
|
430
|
+
|
431
431
|
# def test_getInfo
|
432
432
|
# @u.getInfo
|
433
433
|
# assert_equal @username, @u.username
|
434
434
|
# end
|
435
|
-
#
|
435
|
+
#
|
436
436
|
# def test_groups
|
437
437
|
# assert_kind_of Flickr::Group, @u.groups.first # public groups
|
438
438
|
# end
|
439
|
-
#
|
440
|
-
#
|
439
|
+
#
|
440
|
+
#
|
441
441
|
# def test_contacts
|
442
442
|
# assert_kind_of Flickr::User, @u.contacts.first # public contacts
|
443
443
|
# end
|
444
|
-
#
|
444
|
+
#
|
445
445
|
# def test_favorites
|
446
446
|
# assert_kind_of Flickr::Photo, @u.favorites.first # public favorites
|
447
447
|
# end
|
448
|
-
#
|
448
|
+
#
|
449
449
|
# def test_photosets
|
450
450
|
# assert_kind_of Flickr::Photoset, @u.photosets.first # public photosets
|
451
451
|
# end
|
452
|
-
#
|
452
|
+
#
|
453
453
|
# def test_contactsPhotos
|
454
454
|
# assert_kind_of Flickr::Photo, @u.contactsPhotos.first # contacts' favorites
|
455
455
|
# end
|
456
|
-
|
456
|
+
|
457
457
|
# User#photos tests
|
458
|
-
|
458
|
+
|
459
459
|
def test_should_get_users_public_photos
|
460
460
|
client = mock
|
461
461
|
client.expects(:photos_request).with('people.getPublicPhotos', {'user_id' => 'some_id'}).returns([new_photo, new_photo])
|
@@ -475,7 +475,7 @@ class TestFlickr < Test::Unit::TestCase
|
|
475
475
|
user = Flickr::User.new("some_id", "some_user", nil, nil, "some_api_key")
|
476
476
|
user.favorites
|
477
477
|
end
|
478
|
-
|
478
|
+
|
479
479
|
def test_should_instantiate_contacts_photos_with_id_and_all_params_returned_by_query
|
480
480
|
client = mock
|
481
481
|
client.expects(:photos_request).with('photos.getContactsPublicPhotos', {'user_id' => 'some_id'})
|
@@ -483,7 +483,7 @@ class TestFlickr < Test::Unit::TestCase
|
|
483
483
|
user = Flickr::User.new('some_id', "some_user", nil, nil, "some_api_key")
|
484
484
|
user.contactsPhotos
|
485
485
|
end
|
486
|
-
|
486
|
+
|
487
487
|
# ##### Flickr::Photo tests
|
488
488
|
|
489
489
|
def test_should_initialize_photo_from_id
|
@@ -496,7 +496,7 @@ class TestFlickr < Test::Unit::TestCase
|
|
496
496
|
assert_equal 'value1', photo.instance_variable_get(:@key1)
|
497
497
|
assert_equal 'value2', photo.instance_variable_get(:@key2)
|
498
498
|
end
|
499
|
-
|
499
|
+
|
500
500
|
def test_should_be_able_to_access_instance_variables_through_hash_like_interface
|
501
501
|
photo = Flickr::Photo.new
|
502
502
|
photo.instance_variable_set(:@key1, 'value1')
|
@@ -505,13 +505,13 @@ class TestFlickr < Test::Unit::TestCase
|
|
505
505
|
assert_nil photo[:key2]
|
506
506
|
assert_nil photo['key2']
|
507
507
|
end
|
508
|
-
|
508
|
+
|
509
509
|
def test_should_get_and_store_other_info_for_photo
|
510
510
|
Flickr.any_instance.stubs(:http_get).returns(photo_info_xml_response)
|
511
511
|
photo = Flickr::Photo.new('foo123', 'some_api_key')
|
512
|
-
|
512
|
+
|
513
513
|
assert_equal "1964 120 amazon estate", photo.title # calling #title method triggers getting of info
|
514
|
-
assert_equal "1964 120 amazon estate", photo.instance_variable_get(:@title)
|
514
|
+
assert_equal "1964 120 amazon estate", photo.instance_variable_get(:@title)
|
515
515
|
assert_equal "3142", photo.instance_variable_get(:@server)
|
516
516
|
assert_equal "ae75bd3111", photo.instance_variable_get(:@secret)
|
517
517
|
assert_equal "4", photo.instance_variable_get(:@farm)
|
@@ -537,11 +537,11 @@ class TestFlickr < Test::Unit::TestCase
|
|
537
537
|
assert_kind_of Flickr::User, owner = photo.instance_variable_get(:@owner)
|
538
538
|
assert_equal "Rootes_arrow_1725", owner.username
|
539
539
|
end
|
540
|
-
|
540
|
+
|
541
541
|
def test_should_get_and_other_info_for_photo_when_some_attributes_missing
|
542
542
|
Flickr.any_instance.stubs(:http_get).returns(sparse_photo_info_xml_response)
|
543
543
|
photo = Flickr::Photo.new('foo123', 'some_api_key')
|
544
|
-
|
544
|
+
|
545
545
|
assert_equal "1964 120 amazon estate", photo.title # calling #title method triggers getting of info
|
546
546
|
assert_equal "1964 120 amazon estate", photo.instance_variable_get(:@title)
|
547
547
|
assert_equal( {}, photo.instance_variable_get(:@description))
|
@@ -549,17 +549,17 @@ class TestFlickr < Test::Unit::TestCase
|
|
549
549
|
assert_nil photo.instance_variable_get(:@tags)
|
550
550
|
assert_equal "1", photo.instance_variable_get(:@comments)
|
551
551
|
end
|
552
|
-
|
552
|
+
|
553
553
|
def test_should_not_get_info_more_than_once
|
554
554
|
Flickr.any_instance.expects(:http_get).returns(photo_info_xml_response) # expects only one call
|
555
555
|
photo = Flickr::Photo.new('foo123', 'some_api_key')
|
556
|
-
|
556
|
+
|
557
557
|
photo.description # calling #description method triggers getting of info
|
558
558
|
photo.instance_variable_set(:@description, nil) # set description to nil
|
559
559
|
photo.description # call #description method again
|
560
560
|
end
|
561
|
-
|
562
|
-
#
|
561
|
+
|
562
|
+
#
|
563
563
|
# owner tests
|
564
564
|
def test_should_return_owner_when_flickr_user
|
565
565
|
user = Flickr::User.new
|
@@ -567,65 +567,65 @@ class TestFlickr < Test::Unit::TestCase
|
|
567
567
|
|
568
568
|
assert_equal user, photo.owner
|
569
569
|
end
|
570
|
-
|
570
|
+
|
571
571
|
def test_should_get_info_on_owner_if_not_known
|
572
572
|
photo = new_photo("owner" => nil)
|
573
573
|
# stubbing private methods causes problems so we mock client method, which is what Photo#getInfo users to make API call
|
574
|
-
Flickr.any_instance.expects(:photos_getInfo).returns('photo' => { 'owner'=>{'nsid'=>'abc123', 'username'=>'SomeUserName', 'realname'=>"", 'location'=>''},
|
575
|
-
'notes' => {}, 'tags' => {}, 'urls' => {'url' => {'content' => 'http://prettyurl'}}})
|
574
|
+
Flickr.any_instance.expects(:photos_getInfo).returns('photo' => { 'owner'=>{'nsid'=>'abc123', 'username'=>'SomeUserName', 'realname'=>"", 'location'=>''},
|
575
|
+
'notes' => {}, 'tags' => {}, 'urls' => {'url' => {'content' => 'http://prettyurl'}}})
|
576
576
|
|
577
577
|
owner = photo.owner
|
578
578
|
assert_kind_of Flickr::User, owner
|
579
579
|
assert_equal 'abc123', owner.id
|
580
580
|
assert_equal 'SomeUserName', owner.username
|
581
581
|
end
|
582
|
-
|
582
|
+
|
583
583
|
def test_should_instantiate_flickr_user_from_owner_id_if_we_have_it
|
584
584
|
photo = Flickr::Photo.new
|
585
585
|
photo.instance_variable_set(:@owner, "some_user_id")
|
586
586
|
Flickr.any_instance.expects(:photos_getInfo).never
|
587
|
-
|
587
|
+
|
588
588
|
user = photo.owner
|
589
589
|
assert_kind_of Flickr::User, user
|
590
590
|
assert_equal "some_user_id", user.id
|
591
591
|
end
|
592
|
-
|
592
|
+
|
593
593
|
def test_should_cache_owner_when_instantiated
|
594
594
|
user = Flickr::User.new
|
595
595
|
photo = Flickr::Photo.new
|
596
596
|
photo.instance_variable_set(:@owner, "some_user_id")
|
597
597
|
Flickr::User.expects(:new).returns(user)
|
598
|
-
|
598
|
+
|
599
599
|
photo.owner
|
600
600
|
photo.owner # call twice but mock expects only one call
|
601
601
|
end
|
602
|
-
|
603
|
-
#
|
602
|
+
|
603
|
+
#
|
604
604
|
# image_source_uri_from_self tests
|
605
605
|
def test_should_build_image_source_uri_from_self
|
606
606
|
assert_equal "http://farm1.static.flickr.com/2/1418878_1e92283336.jpg",
|
607
607
|
new_photo.send(:image_source_uri_from_self) # no size specified
|
608
608
|
end
|
609
|
-
|
609
|
+
|
610
610
|
def test_should_build_image_source_uri_from_self_for_given_size
|
611
611
|
assert_equal "http://farm1.static.flickr.com/2/1418878_1e92283336_m.jpg",
|
612
612
|
new_photo.send(:image_source_uri_from_self, "Small") # size specified
|
613
613
|
end
|
614
|
-
|
614
|
+
|
615
615
|
def test_should_build_image_source_uri_from_self_for_default_size_when_explicitly_asked_for
|
616
616
|
assert_equal "http://farm1.static.flickr.com/2/1418878_1e92283336.jpg",
|
617
617
|
new_photo.send(:image_source_uri_from_self, "Medium") # medium size specified -- the default
|
618
618
|
end
|
619
|
-
|
619
|
+
|
620
620
|
def test_should_build_image_source_uri_from_self_for_default_size_when_unknown_size_asked_for
|
621
621
|
assert_equal "http://farm1.static.flickr.com/2/1418878_1e92283336.jpg",
|
622
622
|
new_photo.send(:image_source_uri_from_self, "Dummy") # bad size specified
|
623
623
|
end
|
624
|
-
|
624
|
+
|
625
625
|
def test_should_return_nil_for_image_source_uri_if_no_attributes
|
626
|
-
assert_nil Flickr::Photo.new.send(:image_source_uri_from_self)
|
626
|
+
assert_nil Flickr::Photo.new.send(:image_source_uri_from_self)
|
627
627
|
end
|
628
|
-
|
628
|
+
|
629
629
|
def test_should_return_nil_for_image_source_uri_if_missing_required_attributes
|
630
630
|
assert_nil Flickr::Photo.new("1418878", nil, "farm" => "1").send(:image_source_uri_from_self)
|
631
631
|
end
|
@@ -641,42 +641,42 @@ class TestFlickr < Test::Unit::TestCase
|
|
641
641
|
assert_equal photo.send(:uri_for_photo_from_self, 'Large'),
|
642
642
|
photo.send(:uri_for_photo_from_self, :large)
|
643
643
|
end
|
644
|
-
|
644
|
+
|
645
645
|
def test_should_get_source_uri_by_building_from_self_if_possible
|
646
646
|
photo = Flickr::Photo.new
|
647
647
|
photo.expects(:image_source_uri_from_self).with('Medium').returns(true) # return any non-false-evaluating value so that sizes method isn't called
|
648
648
|
photo.source
|
649
649
|
end
|
650
|
-
|
650
|
+
|
651
651
|
def test_should_get_source_uri_by_building_from_self_if_possible_requesting_source_for_given_size
|
652
652
|
photo = Flickr::Photo.new
|
653
653
|
photo.expects(:image_source_uri_from_self).with('Large').returns(true) # return any non-false-evaluating value so that sizes method isn't called
|
654
654
|
photo.source('Large')
|
655
655
|
end
|
656
|
-
|
656
|
+
|
657
657
|
def test_should_get_source_uri_by_calling_sizes_method_if_no_luck_building_uri
|
658
658
|
photo = Flickr::Photo.new
|
659
659
|
photo.stubs(:image_source_uri_from_self) # ...and hence returns nil
|
660
660
|
photo.expects(:sizes).with('Medium').returns({})
|
661
661
|
photo.source
|
662
662
|
end
|
663
|
-
|
663
|
+
|
664
664
|
def test_should_build_uri_for_photo_from_self
|
665
|
-
assert_equal "http://www.flickr.com/photos/abc123/1418878", new_photo.send(:uri_for_photo_from_self)
|
665
|
+
assert_equal "http://www.flickr.com/photos/abc123/1418878", new_photo.send(:uri_for_photo_from_self)
|
666
666
|
end
|
667
|
-
|
667
|
+
|
668
668
|
def test_should_build_uri_for_photo_from_self_when_owner_is_a_string
|
669
|
-
assert_equal "http://www.flickr.com/photos/789user321/1418878", new_photo('owner' => "789user321").send(:uri_for_photo_from_self)
|
669
|
+
assert_equal "http://www.flickr.com/photos/789user321/1418878", new_photo('owner' => "789user321").send(:uri_for_photo_from_self)
|
670
670
|
end
|
671
|
-
|
671
|
+
|
672
672
|
def test_should_build_uri_for_photo_from_self_for_given_size
|
673
673
|
assert_equal "http://www.flickr.com/photos/abc123/1418878/sizes/s/", new_photo.send(:uri_for_photo_from_self, "Small")
|
674
674
|
end
|
675
|
-
|
675
|
+
|
676
676
|
def test_should_build_uri_for_photo_from_self_with_unknown_size
|
677
677
|
assert_equal "http://www.flickr.com/photos/abc123/1418878", new_photo.send(:uri_for_photo_from_self, "Dummy")
|
678
678
|
end
|
679
|
-
|
679
|
+
|
680
680
|
def test_should_return_nil_for_uri_for_photo_when_no_user_id
|
681
681
|
assert_nil Flickr::Photo.new("1418878", nil).send(:uri_for_photo_from_self)
|
682
682
|
end
|
@@ -684,7 +684,7 @@ class TestFlickr < Test::Unit::TestCase
|
|
684
684
|
def test_should_return_nil_for_uri_for_photo_when_no_photo_id
|
685
685
|
assert_nil Flickr::Photo.new.send(:uri_for_photo_from_self)
|
686
686
|
end
|
687
|
-
|
687
|
+
|
688
688
|
def test_should_get_uri_for_photo_flickr_page
|
689
689
|
photo = new_photo
|
690
690
|
assert_equal "http://www.flickr.com/photos/abc123/1418878", photo.url
|
@@ -705,7 +705,7 @@ class TestFlickr < Test::Unit::TestCase
|
|
705
705
|
photo.expects(:uri_for_photo_from_self).with('Large').returns(true) # return any non-false-evaluating value so that sizes method isn't called
|
706
706
|
photo.size_url('Large')
|
707
707
|
end
|
708
|
-
|
708
|
+
|
709
709
|
def test_should_get_flickr_page_uri_by_calling_sizes_method_if_no_luck_building_uri
|
710
710
|
photo = new_photo
|
711
711
|
photo.stubs(:uri_for_photo_from_self) # ...and hence returns nil
|
@@ -747,40 +747,40 @@ class TestFlickr < Test::Unit::TestCase
|
|
747
747
|
photo.client.expects(:photos_getSizes).at_least_once.returns(sizes)
|
748
748
|
assert_equal photo.sizes('Large'), photo.sizes(:large)
|
749
749
|
end
|
750
|
-
|
750
|
+
|
751
751
|
# Photo#context tests
|
752
752
|
def test_should_call_photos_getContext_to_get_context_photos
|
753
753
|
Flickr.any_instance.expects(:photos_getContext).returns({'prevphoto' => {}, 'nextphoto' => {}})
|
754
754
|
new_photo.context
|
755
755
|
end
|
756
|
-
|
756
|
+
|
757
757
|
def test_should_instantiate_context_photos_with_id_and_all_params_returned_by_query
|
758
758
|
photo = new_photo
|
759
|
-
Flickr.any_instance.expects(:photos_getContext).returns({ 'prevphoto' => {'id' => '123', 'key_1' => 'value_1' },
|
759
|
+
Flickr.any_instance.expects(:photos_getContext).returns({ 'prevphoto' => {'id' => '123', 'key_1' => 'value_1' },
|
760
760
|
'nextphoto' => {'id' => '456', 'key_2' => 'value_2'}})
|
761
761
|
Flickr::Photo.expects(:new).with("123", "foo123", { "key_1" => "value_1"})
|
762
762
|
Flickr::Photo.expects(:new).with("456", "foo123", { "key_2" => "value_2"})
|
763
|
-
|
763
|
+
|
764
764
|
photo.context
|
765
765
|
end
|
766
|
-
|
766
|
+
|
767
767
|
def test_should_not_instantiate_context_photos_with_id_of_0
|
768
768
|
photo = new_photo
|
769
|
-
Flickr.any_instance.expects(:photos_getContext).returns({ 'prevphoto' => {'id' => '123', 'key_1' => 'value_1' },
|
769
|
+
Flickr.any_instance.expects(:photos_getContext).returns({ 'prevphoto' => {'id' => '123', 'key_1' => 'value_1' },
|
770
770
|
'nextphoto' => {'id' => '0', 'key_2' => 'value_2'}})
|
771
771
|
Flickr::Photo.expects(:new).with("123", anything, anything)
|
772
772
|
Flickr::Photo.expects(:new).with("0", anything, anything).never
|
773
|
-
|
773
|
+
|
774
774
|
photo.context
|
775
775
|
end
|
776
|
-
|
776
|
+
|
777
777
|
# ##### Flickr::Group tests
|
778
|
-
#
|
778
|
+
#
|
779
779
|
def test_should_instantiate_group_from_id
|
780
780
|
group = Flickr::Group.new("group1")
|
781
781
|
assert_equal "group1", group.id
|
782
782
|
end
|
783
|
-
|
783
|
+
|
784
784
|
# tests old api for instantiating groups
|
785
785
|
def test_should_instantiate_group_from_id_and_api_key
|
786
786
|
f = flickr_client
|
@@ -788,7 +788,7 @@ class TestFlickr < Test::Unit::TestCase
|
|
788
788
|
group = Flickr::Group.new("group1", "some_api_key")
|
789
789
|
assert_equal f, group.client
|
790
790
|
end
|
791
|
-
|
791
|
+
|
792
792
|
# new api for instantiating groups
|
793
793
|
def test_should_instantiate_group_from_params_hash
|
794
794
|
group = Flickr::Group.new("id" => "group1", "name" => "Group One", "eighteenplus" => "1", "foo" => "bar")
|
@@ -797,14 +797,14 @@ class TestFlickr < Test::Unit::TestCase
|
|
797
797
|
assert_equal "1", group.eighteenplus
|
798
798
|
assert_equal "bar", group.instance_variable_get(:@foo)
|
799
799
|
end
|
800
|
-
|
800
|
+
|
801
801
|
def test_should_use_flickr_client_passed_in_params_hash_when_instantiating_group
|
802
802
|
f = flickr_client
|
803
803
|
Flickr.expects(:new).never
|
804
804
|
group = Flickr::Group.new("id" => "group1", "name" => "Group One", "client" => f)
|
805
805
|
assert_equal f, group.client
|
806
806
|
end
|
807
|
-
|
807
|
+
|
808
808
|
def test_should_provide_id_name_eighteenplus_description_members_online_privacy_reader_methods_for_group
|
809
809
|
g = Flickr::Group.new
|
810
810
|
%w(id name eighteenplus description members online privacy).each do |m|
|
@@ -812,18 +812,18 @@ class TestFlickr < Test::Unit::TestCase
|
|
812
812
|
assert_equal "foo_#{m}", g.send(m)
|
813
813
|
end
|
814
814
|
end
|
815
|
-
|
815
|
+
|
816
816
|
# def test_should_initialize_photo_from_id
|
817
817
|
# photo = Flickr::Photo.new("foo123")
|
818
818
|
# assert_equal "foo123", photo.id
|
819
819
|
# end
|
820
|
-
#
|
820
|
+
#
|
821
821
|
# def test_should_save_extra_params_as_instance_variables
|
822
822
|
# photo = Flickr::Photo.new('foo123', 'some_api_key', { 'key1' => 'value1', 'key2' => 'value2'})
|
823
823
|
# assert_equal 'value1', photo.instance_variable_get(:@key1)
|
824
824
|
# assert_equal 'value2', photo.instance_variable_get(:@key2)
|
825
825
|
# end
|
826
|
-
#
|
826
|
+
#
|
827
827
|
# def test_should_be_able_to_access_instance_variables_through_hash_like_interface
|
828
828
|
# photo = Flickr::Photo.new
|
829
829
|
# photo.instance_variable_set(:@key1, 'value1')
|
@@ -832,57 +832,57 @@ class TestFlickr < Test::Unit::TestCase
|
|
832
832
|
# assert_nil photo[:key2]
|
833
833
|
# assert_nil photo['key2']
|
834
834
|
# end
|
835
|
-
|
835
|
+
|
836
836
|
## PHOTOSETS
|
837
|
-
|
837
|
+
|
838
838
|
def test_should_initialize_photoset_from_id
|
839
839
|
photoset = Flickr::Photoset.new("foo123")
|
840
840
|
assert_equal "foo123", photoset.id
|
841
841
|
end
|
842
|
-
|
842
|
+
|
843
843
|
def test_should_initialize_photoset_from_id_and_api_key
|
844
844
|
photoset = Flickr::Photoset.new("foo123", "some_api_key")
|
845
845
|
assert_equal "some_api_key", photoset.instance_variable_get(:@api_key)
|
846
846
|
end
|
847
|
-
|
847
|
+
|
848
848
|
def test_should_get_photos_for_specified_photoset
|
849
849
|
Flickr.any_instance.expects(:request).with('photosets.getPhotos', {'photoset_id' => 'some_id'}).returns(dummy_photoset_photos_response)
|
850
850
|
photoset = Flickr::Photoset.new("some_id", "some_api_key")
|
851
|
-
|
851
|
+
|
852
852
|
assert_kind_of Flickr::PhotoCollection, photos = photoset.getPhotos
|
853
853
|
assert_equal 2, photos.size
|
854
854
|
assert_kind_of Flickr::Photo, photos.first
|
855
855
|
end
|
856
856
|
|
857
|
-
|
857
|
+
|
858
858
|
# def test_photosets_editMeta
|
859
859
|
# assert_equal @f.photosets_editMeta('photoset_id'=>@photoset_id, 'title'=>@title)['stat'], 'ok'
|
860
860
|
# end
|
861
|
-
#
|
861
|
+
#
|
862
862
|
# def test_photosets_editPhotos
|
863
863
|
# assert_equal @f.photosets_editPhotos('photoset_id'=>@photoset_id, 'primary_photo_id'=>@photo_id, 'photo_ids'=>@photo_id)['stat'], 'ok'
|
864
864
|
# end
|
865
|
-
#
|
865
|
+
#
|
866
866
|
# def test_photosets_getContext
|
867
867
|
# assert_equal @f.photosets_getContext('photoset_id'=>@photoset_id, 'photo_id'=>@photo_id)['stat'], 'ok'
|
868
868
|
# end
|
869
|
-
#
|
869
|
+
#
|
870
870
|
# def test_photosets_getContext
|
871
871
|
# assert_equal @f.photosets_getContext('photoset_id'=>@photoset_id, 'photo_id'=>@photo_id)['stat'], 'ok'
|
872
872
|
# end
|
873
|
-
#
|
873
|
+
#
|
874
874
|
# def test_photosets_getInfo
|
875
875
|
# assert_equal @f.photosets_getInfo('photoset_id'=>@photoset_id)['stat'], 'ok'
|
876
876
|
# end
|
877
|
-
#
|
877
|
+
#
|
878
878
|
# def test_photosets_getList
|
879
879
|
# assert_equal @f.photosets_getList['stat'], 'ok'
|
880
880
|
# end
|
881
|
-
#
|
881
|
+
#
|
882
882
|
# def test_photosets_getPhotos
|
883
883
|
# assert_equal @f.photosets_getPhotos('photoset_id'=>@photoset_id)['stat'], 'ok'
|
884
884
|
# end
|
885
|
-
#
|
885
|
+
#
|
886
886
|
# def test_photosets_orderSets
|
887
887
|
# assert_equal @f.photosets_orderSets('photoset_ids'=>@photoset_id)['stat'], 'ok'
|
888
888
|
# end
|
@@ -901,27 +901,27 @@ class TestFlickr < Test::Unit::TestCase
|
|
901
901
|
end
|
902
902
|
|
903
903
|
# ##### Flickr::PhotoCollection tests
|
904
|
-
#
|
904
|
+
#
|
905
905
|
def test_should_subclass_array_as_photo_collection
|
906
906
|
assert_equal Array, Flickr::PhotoCollection.superclass
|
907
907
|
end
|
908
|
-
|
908
|
+
|
909
909
|
def test_should_make_page_a_reader_method
|
910
910
|
assert_equal "3", dummy_photo_collection.page
|
911
911
|
end
|
912
|
-
|
912
|
+
|
913
913
|
def test_should_make_pages_a_reader_method
|
914
914
|
assert_equal "5", dummy_photo_collection.pages
|
915
915
|
end
|
916
|
-
|
916
|
+
|
917
917
|
def test_should_make_perpage_a_reader_method
|
918
918
|
assert_equal "10", dummy_photo_collection.perpage
|
919
919
|
end
|
920
|
-
|
920
|
+
|
921
921
|
def test_should_make_total_a_reader_method
|
922
922
|
assert_equal "42", dummy_photo_collection.total
|
923
923
|
end
|
924
|
-
|
924
|
+
|
925
925
|
def test_should_instantiate_photo_collection_from_photos_hash
|
926
926
|
pc = Flickr::PhotoCollection.new(dummy_photos_response)
|
927
927
|
assert_kind_of Flickr::PhotoCollection, pc
|
@@ -929,110 +929,112 @@ class TestFlickr < Test::Unit::TestCase
|
|
929
929
|
assert_kind_of Flickr::Photo, pc.first
|
930
930
|
assert_equal "foo123", pc.first["id"]
|
931
931
|
end
|
932
|
-
|
932
|
+
|
933
933
|
def test_should_instantiate_photo_collection_using_given_api_key
|
934
934
|
photo = Flickr::PhotoCollection.new(dummy_photos_response, "some_api_key").first
|
935
935
|
assert_equal "some_api_key", photo.instance_variable_get(:@api_key)
|
936
936
|
end
|
937
|
-
|
937
|
+
|
938
938
|
private
|
939
939
|
def flickr_client
|
940
940
|
Flickr.new("some_api_key")
|
941
941
|
end
|
942
|
-
|
942
|
+
|
943
943
|
def authenticated_flickr_client
|
944
944
|
f = Flickr.new(:api_key => 'some_api_key', :shared_secret => 'shared_secret_code')
|
945
945
|
f.instance_variable_set(:@auth_token, 'some_auth_token')
|
946
946
|
f
|
947
947
|
end
|
948
|
-
|
948
|
+
|
949
949
|
def new_user(options={})
|
950
950
|
Flickr::User.new({ 'id' => 'foo123',
|
951
951
|
'username' => 'some_user',
|
952
|
-
'name' => 'Some User',
|
953
|
-
'foo' => 'bar',
|
952
|
+
'name' => 'Some User',
|
953
|
+
'foo' => 'bar',
|
954
954
|
'auth_token' => 'foobar789'}.merge(options))
|
955
|
-
|
955
|
+
|
956
956
|
end
|
957
957
|
def new_photo(options={})
|
958
|
-
Flickr::Photo.new("1418878",
|
958
|
+
Flickr::Photo.new("1418878",
|
959
959
|
"foo123",
|
960
960
|
{ "farm" => "1",
|
961
961
|
"server" => "2",
|
962
962
|
"secret" => "1e92283336",
|
963
963
|
"owner" => Flickr::User.new("abc123", "some_user", nil, nil, "some_api_key") }.merge(options))
|
964
964
|
end
|
965
|
-
|
965
|
+
|
966
966
|
def dummy_photo_collection
|
967
967
|
Flickr::PhotoCollection.new(dummy_photos_response)
|
968
968
|
end
|
969
|
-
|
969
|
+
|
970
970
|
def dummy_photos_response
|
971
|
-
{ "
|
972
|
-
|
973
|
-
|
974
|
-
|
971
|
+
{ "stat"=>"ok",
|
972
|
+
"photos" =>
|
973
|
+
{ "photo" =>
|
974
|
+
[{ "id" => "foo123",
|
975
|
+
"key1" => "value1",
|
975
976
|
"key2" => "value2" },
|
976
|
-
{ "id" => "bar456",
|
977
|
+
{ "id" => "bar456",
|
977
978
|
"key3" => "value3"}],
|
978
|
-
"page"=>"3",
|
979
|
-
"pages"=>"5",
|
979
|
+
"page"=>"3",
|
980
|
+
"pages"=>"5",
|
980
981
|
"perpage"=>"10",
|
981
982
|
"total"=>"42" } }
|
982
983
|
end
|
983
|
-
|
984
|
+
|
984
985
|
def dummy_single_photo_response
|
985
|
-
{ "
|
986
|
-
|
987
|
-
|
988
|
-
|
986
|
+
{ "stat"=>"ok",
|
987
|
+
"photos" =>
|
988
|
+
{ "photo" =>
|
989
|
+
{ "id" => "foo123",
|
990
|
+
"key1" => "value1",
|
989
991
|
"key2" => "value2" } } }
|
990
992
|
end
|
991
993
|
|
992
994
|
def dummy_zero_photo_response
|
993
|
-
{ "photos" => { "total" => 0 } }
|
995
|
+
{ "stat"=>"ok", "photos" => { "total" => 0 } }
|
994
996
|
end
|
995
|
-
|
997
|
+
|
996
998
|
def dummy_user_response
|
997
|
-
{ "user" =>
|
999
|
+
{ "user" =>
|
998
1000
|
{ "nsid" => "12037949632@N01",
|
999
1001
|
"username" => "Stewart" }
|
1000
1002
|
}
|
1001
1003
|
end
|
1002
|
-
|
1004
|
+
|
1003
1005
|
def dummy_groups_response
|
1004
|
-
{ "groups" =>
|
1005
|
-
{ "group" =>
|
1006
|
-
[{ "nsid" => "group1",
|
1007
|
-
"name" => "Group One",
|
1006
|
+
{ "groups" =>
|
1007
|
+
{ "group" =>
|
1008
|
+
[{ "nsid" => "group1",
|
1009
|
+
"name" => "Group One",
|
1008
1010
|
"eighteenplus" => "0" },
|
1009
|
-
{ "nsid" => "group2",
|
1011
|
+
{ "nsid" => "group2",
|
1010
1012
|
"name" => "Group Two",
|
1011
1013
|
"eighteenplus" => "1"}] } }
|
1012
1014
|
end
|
1013
|
-
|
1015
|
+
|
1014
1016
|
def dummy_single_group_response
|
1015
|
-
{ "groups" =>
|
1016
|
-
{ "group" =>
|
1017
|
-
{ "nsid" => "group1",
|
1018
|
-
"name" => "Group One",
|
1017
|
+
{ "groups" =>
|
1018
|
+
{ "group" =>
|
1019
|
+
{ "nsid" => "group1",
|
1020
|
+
"name" => "Group One",
|
1019
1021
|
"eighteenplus" => "0" } } }
|
1020
1022
|
end
|
1021
|
-
|
1023
|
+
|
1022
1024
|
def dummy_photoset_photos_response
|
1023
|
-
{ "photoset" =>
|
1024
|
-
{ "photo" =>
|
1025
|
-
[{ "id" => "foo123",
|
1026
|
-
"key1" => "value1",
|
1025
|
+
{ "stat"=>"ok", "photoset" =>
|
1026
|
+
{ "photo" =>
|
1027
|
+
[{ "id" => "foo123",
|
1028
|
+
"key1" => "value1",
|
1027
1029
|
"key2" => "value2" },
|
1028
|
-
{ "id" => "bar456",
|
1030
|
+
{ "id" => "bar456",
|
1029
1031
|
"key3" => "value3"}],
|
1030
|
-
"page"=>"3",
|
1031
|
-
"pages"=>"5",
|
1032
|
+
"page"=>"3",
|
1033
|
+
"pages"=>"5",
|
1032
1034
|
"perpage"=>"10",
|
1033
1035
|
"total"=>"42" } }
|
1034
1036
|
end
|
1035
|
-
|
1037
|
+
|
1036
1038
|
def successful_xml_response
|
1037
1039
|
<<-EOF
|
1038
1040
|
<?xml version="1.0" encoding="utf-8" ?>
|
@@ -1040,15 +1042,15 @@ class TestFlickr < Test::Unit::TestCase
|
|
1040
1042
|
<contacts page="1" pages="1" perpage="1000" total="2">
|
1041
1043
|
<contact nsid="12037949629@N01" username="Eric" iconserver="1"
|
1042
1044
|
realname="Eric Costello"
|
1043
|
-
friend="1" family="0" ignored="1" />
|
1045
|
+
friend="1" family="0" ignored="1" />
|
1044
1046
|
<contact nsid="12037949631@N01" username="neb" iconserver="1"
|
1045
1047
|
realname="Ben Cerveny"
|
1046
|
-
friend="0" family="0" ignored="0" />
|
1048
|
+
friend="0" family="0" ignored="0" />
|
1047
1049
|
</contacts>
|
1048
1050
|
</rsp>
|
1049
1051
|
EOF
|
1050
1052
|
end
|
1051
|
-
|
1053
|
+
|
1052
1054
|
def unsuccessful_xml_response
|
1053
1055
|
<<-EOF
|
1054
1056
|
<?xml version="1.0" encoding="utf-8" ?>
|
@@ -1109,4 +1111,4 @@ class TestFlickr < Test::Unit::TestCase
|
|
1109
1111
|
EOF
|
1110
1112
|
end
|
1111
1113
|
|
1112
|
-
end
|
1114
|
+
end
|