flickr.rb 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,24 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
5
+
6
+ <!--
7
+
8
+ Flickr
9
+
10
+ -->
11
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
12
+ <head>
13
+ <title>Flickr</title>
14
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
15
+ </head>
16
+ <frameset rows="20%, 80%">
17
+ <frameset cols="25%,35%,45%">
18
+ <frame src="fr_file_index.html" title="Files" name="Files" />
19
+ <frame src="fr_class_index.html" name="Classes" />
20
+ <frame src="fr_method_index.html" name="Methods" />
21
+ </frameset>
22
+ <frame src="files/README_txt.html" name="docwin" />
23
+ </frameset>
24
+ </html>
@@ -0,0 +1,208 @@
1
+
2
+ body {
3
+ font-family: Verdana,Arial,Helvetica,sans-serif;
4
+ font-size: 90%;
5
+ margin: 0;
6
+ margin-left: 40px;
7
+ padding: 0;
8
+ background: white;
9
+ }
10
+
11
+ h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; }
12
+ h1 { font-size: 150%; }
13
+ h2,h3,h4 { margin-top: 1em; }
14
+
15
+ a { background: #eef; color: #039; text-decoration: none; }
16
+ a:hover { background: #039; color: #eef; }
17
+
18
+ /* Override the base stylesheet's Anchor inside a table cell */
19
+ td > a {
20
+ background: transparent;
21
+ color: #039;
22
+ text-decoration: none;
23
+ }
24
+
25
+ /* and inside a section title */
26
+ .section-title > a {
27
+ background: transparent;
28
+ color: #eee;
29
+ text-decoration: none;
30
+ }
31
+
32
+ /* === Structural elements =================================== */
33
+
34
+ div#index {
35
+ margin: 0;
36
+ margin-left: -40px;
37
+ padding: 0;
38
+ font-size: 90%;
39
+ }
40
+
41
+
42
+ div#index a {
43
+ margin-left: 0.7em;
44
+ }
45
+
46
+ div#index .section-bar {
47
+ margin-left: 0px;
48
+ padding-left: 0.7em;
49
+ background: #ccc;
50
+ font-size: small;
51
+ }
52
+
53
+
54
+ div#classHeader, div#fileHeader {
55
+ width: auto;
56
+ color: white;
57
+ padding: 0.5em 1.5em 0.5em 1.5em;
58
+ margin: 0;
59
+ margin-left: -40px;
60
+ border-bottom: 3px solid #006;
61
+ }
62
+
63
+ div#classHeader a, div#fileHeader a {
64
+ background: inherit;
65
+ color: white;
66
+ }
67
+
68
+ div#classHeader td, div#fileHeader td {
69
+ background: inherit;
70
+ color: white;
71
+ }
72
+
73
+
74
+ div#fileHeader {
75
+ background: #057;
76
+ }
77
+
78
+ div#classHeader {
79
+ background: #048;
80
+ }
81
+
82
+
83
+ .class-name-in-header {
84
+ font-size: 180%;
85
+ font-weight: bold;
86
+ }
87
+
88
+
89
+ div#bodyContent {
90
+ padding: 0 1.5em 0 1.5em;
91
+ }
92
+
93
+ div#description {
94
+ padding: 0.5em 1.5em;
95
+ background: #efefef;
96
+ border: 1px dotted #999;
97
+ }
98
+
99
+ div#description h1,h2,h3,h4,h5,h6 {
100
+ color: #125;;
101
+ background: transparent;
102
+ }
103
+
104
+ div#validator-badges {
105
+ text-align: center;
106
+ }
107
+ div#validator-badges img { border: 0; }
108
+
109
+ div#copyright {
110
+ color: #333;
111
+ background: #efefef;
112
+ font: 0.75em sans-serif;
113
+ margin-top: 5em;
114
+ margin-bottom: 0;
115
+ padding: 0.5em 2em;
116
+ }
117
+
118
+
119
+ /* === Classes =================================== */
120
+
121
+ table.header-table {
122
+ color: white;
123
+ font-size: small;
124
+ }
125
+
126
+ .type-note {
127
+ font-size: small;
128
+ color: #DEDEDE;
129
+ }
130
+
131
+ .xxsection-bar {
132
+ background: #eee;
133
+ color: #333;
134
+ padding: 3px;
135
+ }
136
+
137
+ .section-bar {
138
+ color: #333;
139
+ border-bottom: 1px solid #999;
140
+ margin-left: -20px;
141
+ }
142
+
143
+
144
+ .section-title {
145
+ background: #79a;
146
+ color: #eee;
147
+ padding: 3px;
148
+ margin-top: 2em;
149
+ margin-left: -30px;
150
+ border: 1px solid #999;
151
+ }
152
+
153
+ .top-aligned-row { vertical-align: top }
154
+ .bottom-aligned-row { vertical-align: bottom }
155
+
156
+ /* --- Context section classes ----------------------- */
157
+
158
+ .context-row { }
159
+ .context-item-name { font-family: monospace; font-weight: bold; color: black; }
160
+ .context-item-value { font-size: small; color: #448; }
161
+ .context-item-desc { color: #333; padding-left: 2em; }
162
+
163
+ /* --- Method classes -------------------------- */
164
+ .method-detail {
165
+ background: #efefef;
166
+ padding: 0;
167
+ margin-top: 0.5em;
168
+ margin-bottom: 1em;
169
+ border: 1px dotted #ccc;
170
+ }
171
+ .method-heading {
172
+ color: black;
173
+ background: #ccc;
174
+ border-bottom: 1px solid #666;
175
+ padding: 0.2em 0.5em 0 0.5em;
176
+ }
177
+ .method-signature { color: black; background: inherit; }
178
+ .method-name { font-weight: bold; }
179
+ .method-args { font-style: italic; }
180
+ .method-description { padding: 0 0.5em 0 0.5em; }
181
+
182
+ /* --- Source code sections -------------------- */
183
+
184
+ a.source-toggle { font-size: 90%; }
185
+ div.method-source-code {
186
+ background: #262626;
187
+ color: #ffdead;
188
+ margin: 1em;
189
+ padding: 0.5em;
190
+ border: 1px dashed #999;
191
+ overflow: hidden;
192
+ }
193
+
194
+ div.method-source-code pre { color: #ffdead; overflow: hidden; }
195
+
196
+ /* --- Ruby keyword styles --------------------- */
197
+
198
+ .standalone-code { background: #221111; color: #ffdead; overflow: hidden; }
199
+
200
+ .ruby-constant { color: #7fffd4; background: transparent; }
201
+ .ruby-keyword { color: #00ffff; background: transparent; }
202
+ .ruby-ivar { color: #eedd82; background: transparent; }
203
+ .ruby-operator { color: #00ffee; background: transparent; }
204
+ .ruby-identifier { color: #ffdead; background: transparent; }
205
+ .ruby-node { color: #ffa07a; background: transparent; }
206
+ .ruby-comment { color: #b22222; font-weight: bold; background: transparent; }
207
+ .ruby-regexp { color: #ffa07a; background: transparent; }
208
+ .ruby-value { color: #7fffd4; background: transparent; }
@@ -0,0 +1,1112 @@
1
+ require 'rubygems'
2
+ require 'flickr'
3
+ require 'test/unit'
4
+ require 'mocha'
5
+
6
+ class TestFlickr < Test::Unit::TestCase
7
+
8
+ # Flickr client tests
9
+ #
10
+ # instantiation tests
11
+ def test_should_instantiate_new_flickr_client
12
+ Flickr.any_instance.stubs(:login)
13
+ flickr = Flickr.new(:api_key => 'some_api_key', :shared_secret => 'some_shared_secret')
14
+
15
+ assert_equal 'some_api_key', flickr.api_key
16
+ assert_equal 'some_shared_secret', flickr.instance_variable_get(:@shared_secret)
17
+ end
18
+
19
+ def test_should_instantiate_new_flickr_client_on_new_api
20
+ flickr = Flickr.new(:api_key => 'some_api_key', :shared_secret => 'some_shared_secret', 'foo' => 'bar')
21
+
22
+ assert_equal 'some_api_key', flickr.api_key
23
+ assert_equal 'some_shared_secret', flickr.instance_variable_get(:@shared_secret)
24
+ assert_nil flickr.instance_variable_get(:@foo) # should ignore other params
25
+ end
26
+
27
+ # signature_from method tests
28
+ def test_should_return_signature_from_given_params
29
+ assert_equal Digest::MD5.hexdigest('shared_secret_codea_param1234xb_param5678yc_param97531t'),
30
+ authenticated_flickr_client.send(:signature_from, {:b_param => '5678y', 'c_param' => '97531t', :a_param => '1234x', :d_param => nil})
31
+ end
32
+
33
+ def test_should_return_nil_for_signature_when_no_shared_secret
34
+ assert_nil flickr_client.send(:signature_from, {:b_param => '5678y', :c_param => '97531t', :a_param => '1234x'})
35
+ end
36
+
37
+ # request_url method tests
38
+ def test_should_get_signature_for_params_when_building_url
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',
43
+ 'auth_token' => 'some_auth_token').returns("foo123bar456")
44
+
45
+ url = f.send(:request_url, 'someMethod', 'foo' => 'value which/needs&escaping')
46
+ end
47
+
48
+ def test_should_build_url_from_params_with_signature
49
+ f = authenticated_flickr_client
50
+ f.stubs(:signature_from).returns("foo123bar456")
51
+
52
+ url = f.send(:request_url, 'someMethod', 'foo' => 'value which/needs&escaping')
53
+ [ "#{Flickr::HOST_URL}#{Flickr::API_PATH}",
54
+ 'api_key=some_api_key',
55
+ 'method=flickr.someMethod',
56
+ 'foo=value+which%2Fneeds%26escaping',
57
+ 'auth_token=some_auth_token',
58
+ 'api_sig=foo123bar456'].each do |kv_pair|
59
+ assert_match Regexp.new(Regexp.escape(kv_pair)), url
60
+ end
61
+ end
62
+
63
+ def test_should_build_url_from_params_when_signature_returns_nil
64
+ flickr = flickr_client
65
+ flickr.stubs(:signature_from)
66
+ assert_equal "#{Flickr::HOST_URL}#{Flickr::API_PATH}/?method=flickr.someMethod&api_key=some_api_key", flickr.send(:request_url, 'someMethod')
67
+ assert_equal "#{Flickr::HOST_URL}#{Flickr::API_PATH}/?method=flickr.someMethod&api_key=some_api_key&foo=bar", flickr.send(:request_url, 'someMethod', 'foo' => 'bar', 'foobar' => nil)
68
+ assert_equal "#{Flickr::HOST_URL}#{Flickr::API_PATH}/?method=flickr.someMethod&api_key=some_api_key&foo=101", flickr.send(:request_url, 'someMethod', 'foo' => 101)
69
+ assert_equal "#{Flickr::HOST_URL}#{Flickr::API_PATH}/?method=flickr.someMethod&api_key=some_api_key&foo=value+which%2Fneeds%26escaping", flickr.send(:request_url, 'someMethod', 'foo' => 'value which/needs&escaping')
70
+ end
71
+
72
+ # method_missing tests
73
+ def test_should_generate_flickr_method_from_unkown_method_on_flickr_client
74
+ f = flickr_client
75
+ f.expects(:request).with('some.unknown.methodForFlickr', {})
76
+ f.some_unknown_methodForFlickr
77
+ end
78
+
79
+ # request method tests
80
+ def test_should_make_successful_request
81
+ f = flickr_client
82
+ f.expects(:http_get).with('some.url').returns(successful_xml_response)
83
+ f.expects(:request_url).with('some_method', 'foo' => 'bar').returns("some.url")
84
+
85
+ f.send(:request, 'some_method', 'foo' => 'bar') # request is protected
86
+ end
87
+
88
+ def test_should_raise_exception_on_unsuccessful_request
89
+ f = flickr_client
90
+ f.expects(:http_get).returns(unsuccessful_xml_response)
91
+
92
+ assert_raise(RuntimeError) { f.send(:request, 'some_method', 'foo' => 'bar') }
93
+ end
94
+
95
+ def test_should_parse_returned_xml_in_successful_request
96
+ f = flickr_client
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" },
116
+ "stat"=>"ok" }
117
+
118
+ assert_equal expected_response, f.send(:request, 'some_method', 'foo' => 'bar')
119
+ end
120
+
121
+ # photos_request tests
122
+ def test_should_pass_photos_request_params_to_request
123
+ f = flickr_client
124
+ f.expects(:request).with('flickr.method', :one => 1, :two => "2").returns(dummy_photos_response)
125
+ f.photos_request( 'flickr.method', :one => 1, :two => "2")
126
+ end
127
+
128
+ def test_should_instantiate_recent_photos_with_id_and_all_params_returned_by_flickr
129
+ f = flickr_client
130
+ f.expects(:request).returns(dummy_photos_response)
131
+ Flickr::Photo.expects(:new).with("foo123",
132
+ "some_api_key", { "key1" => "value1",
133
+ "key2" => "value2"})
134
+ Flickr::Photo.expects(:new).with("bar456",
135
+ "some_api_key", { "key3" => "value3"})
136
+ photos = f.photos_request('some_method')
137
+ end
138
+
139
+ def test_should_parse_photos_response_into_flickr_photo_collection
140
+ f = flickr_client
141
+ f.expects(:request).returns(dummy_photos_response)
142
+ assert_kind_of Flickr::PhotoCollection, f.photos_request('some_method')
143
+ end
144
+
145
+ def test_should_store_pagination_info_in_photo_collection
146
+ f = flickr_client
147
+ f.expects(:request).returns(dummy_photos_response)
148
+ photos = f.photos_request('some_method')
149
+
150
+ assert_equal "3", photos.page
151
+ assert_equal "5", photos.pages
152
+ assert_equal "10", photos.perpage
153
+ assert_equal "42", photos.total
154
+ end
155
+
156
+ def test_should_return_collection_of_photos
157
+ f = flickr_client
158
+ f.expects(:request).returns(dummy_photos_response)
159
+ photos = f.photos_request('some_method')
160
+ assert_equal 2, photos.size
161
+ assert_kind_of Flickr::Photo, photos.first
162
+ assert_equal "foo123", photos.first.id
163
+ end
164
+
165
+ def test_should_work_with_single_result
166
+ f = flickr_client
167
+ f.expects(:request).returns(dummy_single_photo_response)
168
+ photos = f.photos_request('some_method')
169
+ assert_equal 1, photos.size
170
+ assert_kind_of Flickr::Photo, photos.first
171
+ assert_equal "foo123", photos.first.id
172
+ end
173
+
174
+ def test_should_work_with_empty_result
175
+ f = flickr_client
176
+ f.expects(:request).returns(dummy_zero_photo_response)
177
+ photos = f.photos_request('some_method')
178
+ assert_equal [], photos
179
+ end
180
+
181
+ def test_should_generate_login_url
182
+ f = flickr_client
183
+ f.expects(:signature_from).with('api_key' => 'some_api_key', 'perms' => 'write').returns('validsignature')
184
+ assert_equal 'http://flickr.com/services/auth/?api_key=some_api_key&perms=write&api_sig=validsignature', f.login_url('write')
185
+ end
186
+
187
+ def test_should_get_token_from_frob
188
+ f = flickr_client
189
+ f.expects(:request).with('auth.getToken',:frob => 'some_frob').returns({'auth' => {'token' => 'some_auth_token', 'user' => {}}})
190
+
191
+ auth_token = f.get_token_from('some_frob')
192
+ assert_equal 'some_auth_token', auth_token
193
+ end
194
+
195
+ def test_should_store_auth_token_in_client
196
+ f = flickr_client
197
+ f.expects(:request).returns({'auth' => {'token' => 'some_auth_token','user' => {}}})
198
+ f.get_token_from('some_frob')
199
+ assert_equal 'some_auth_token', f.auth_token
200
+ end
201
+
202
+ def test_should_store_authenticated_user_details_in_client
203
+ f = flickr_client
204
+ f.expects(:request).returns({ 'auth' => { 'token' => 'some_auth_token',
205
+ 'user' => { 'nsid' => 'foo123',
206
+ 'username' => 'some_user', 'fullname' => 'Some User'}}})
207
+ f.get_token_from('some_frob')
208
+ assert_kind_of Flickr::User, user = f.user
209
+ assert_equal 'foo123', user.id
210
+ assert_equal 'some_user', user.username
211
+ assert_equal 'Some User', user.name
212
+ assert_equal f, user.client
213
+ end
214
+
215
+ # photos method tests
216
+ def test_should_get_recent_photos_if_no_params_for_photos
217
+ f = flickr_client
218
+ f.expects(:recent)
219
+ f.photos
220
+ end
221
+
222
+ # photos_search method tests
223
+ def test_should_search_photos
224
+ f = authenticated_flickr_client
225
+ f.expects(:request).with('photos.search', anything).returns(dummy_photos_response)
226
+ photos = f.photos_search
227
+ assert_kind_of Flickr::Photo, photos.first
228
+ end
229
+
230
+ # users method tests
231
+ def test_should_find_user_from_email
232
+ f = flickr_client
233
+ f.expects(:request).with('people.findByEmail', anything).returns(dummy_user_response)
234
+ assert_kind_of Flickr::User, user = f.users("email@test.com")
235
+ assert_equal "12037949632@N01", user.id
236
+ assert_equal "Stewart", user.username
237
+ end
238
+
239
+ def test_should_find_user_from_username_if_fails_to_get_from_email
240
+ f = flickr_client
241
+ f.expects(:request).with('people.findByEmail', anything).raises
242
+ f.expects(:request).with('people.findByUsername', anything).returns(dummy_user_response)
243
+ assert_kind_of Flickr::User, f.users("email@test.com")
244
+ end
245
+
246
+ def test_should_pass_on_flickr_client_when_finding_user
247
+ f = flickr_client
248
+ f.stubs(:request).returns(dummy_user_response)
249
+ user = f.users("email@test.com")
250
+ assert_equal f, user.client
251
+ end
252
+
253
+ # groups method tests
254
+ def test_should_search_for_given_group
255
+ f = flickr_client
256
+ f.expects(:request).with("groups.search", {"text" => "foo"}).returns(dummy_groups_response)
257
+ f.groups("foo")
258
+ end
259
+
260
+ def test_should_search_for_given_group_with_additional_params
261
+ f = flickr_client
262
+ f.expects(:request).with("groups.search", {"text" => "foo", "per_page" => "1"}).returns(dummy_groups_response)
263
+ f.groups("foo", "per_page" => "1")
264
+ end
265
+
266
+ def test_should_instantiate_groups_from_search_response
267
+ f = flickr_client
268
+ f.stubs(:request).returns(dummy_groups_response)
269
+ assert_kind_of Array, groups = f.groups("foo")
270
+ assert_kind_of Flickr::Group, group = groups.first
271
+ assert_equal "group1", group.id
272
+ assert_equal "Group One", group.name
273
+ assert_equal "0", group.eighteenplus
274
+ assert_equal f, group.client
275
+ end
276
+
277
+ def test_should_instantiate_groups_from_search_response_with_single_group_returned
278
+ f = flickr_client
279
+ f.stubs(:request).returns(dummy_single_group_response)
280
+ assert_kind_of Array, groups = f.groups("foo")
281
+ assert_equal 1, groups.size
282
+ assert_equal "group1", groups.first.id
283
+ end
284
+
285
+ # ##### DIRECT MODE
286
+ #
287
+ # def test_test_echo
288
+ # assert_equal @f.test_echo['stat'], 'ok'
289
+ # end
290
+ # def test_test_login
291
+ # assert_equal @f.test_login['stat'], 'ok'
292
+ # end
293
+ #
294
+ #
295
+ # ##### BASICS
296
+ #
297
+ # def test_login
298
+ # assert_equal @username, @f.user.getInfo.username
299
+ # end
300
+ #
301
+ # def test_find_by_url
302
+ # assert_equal @group_id, @f.find_by_url(@group_url).getInfo.id # find group by URL
303
+ # assert_equal @user_id, @f.find_by_url(@user_url).getInfo.id # find user by URL
304
+ # end
305
+ #
306
+ # def test_licenses
307
+ # assert_kind_of Array, @f.licenses # find all licenses
308
+ # end
309
+ #
310
+
311
+ #
312
+ # Flickr#photos tests
313
+ #
314
+
315
+
316
+ # ##### Flickr::User tests
317
+ #
318
+ def test_should_instantiate_user
319
+ user = new_user
320
+ assert_equal 'foo123', user.id
321
+ assert_equal 'some_user', user.username
322
+ assert_equal 'bar', user.instance_variable_get(:@foo) # should collect all other params up and store as instance variables
323
+ end
324
+
325
+ def test_should_instantiate_new_user_with_old_api
326
+ Flickr.any_instance.stubs(:login) # stub logging in
327
+ user = Flickr::User.new('foo123',
328
+ 'some_user',
329
+ 'email@test.com', # email irrelevant since Flickr API no longer supports authentication in this way
330
+ 'password', # password irrelevant since Flickr API no longer supports authentication in this way
331
+ 'bar456')
332
+ assert_equal 'foo123', user.id
333
+ assert_equal 'some_user', user.username
334
+ assert_equal 'email@test.com', user.instance_variable_get(:@email)
335
+ assert_equal 'password', user.instance_variable_get(:@password)
336
+ assert_equal 'bar456', user.client.api_key
337
+ end
338
+
339
+ def test_should_instantiate_new_client_when_instantiating_user_if_no_client_passed_in_params
340
+ f = flickr_client
341
+ Flickr.expects(:new).returns(f)
342
+ user = new_user( 'api_key' => 'an_api_key' )
343
+ assert_equal f, user.client
344
+ end
345
+
346
+ def test_should_not_instantiate_new_client_when_instantiating_user_if_client_passed_in_params
347
+ f = flickr_client
348
+ Flickr.expects(:new).never
349
+ user = new_user( 'client' => f )
350
+ assert_equal f, user.client
351
+ end
352
+
353
+ def test_should_not_instantiate_client_if_no_api_key_passed
354
+ Flickr.expects(:new).never
355
+ user = new_user
356
+ assert_nil user.client
357
+ end
358
+
359
+ def test_should_build_url_for_users_profile_page_using_user_id
360
+ Flickr.any_instance.expects(:http_get).never
361
+ assert_equal "http://www.flickr.com/people/foo123/", new_user.url
362
+ end
363
+
364
+ def test_should_build_url_for_users_photos_page_using_user_id
365
+ Flickr.any_instance.expects(:http_get).never
366
+ assert_equal "http://www.flickr.com/photos/foo123/", new_user.photos_url
367
+ end
368
+
369
+ def test_should_get_pretty_url_for_users_profile_page
370
+ f = flickr_client
371
+ f.expects(:urls_getUserProfile).returns({"user" => {"nsid" => "bar456", "url" => "http://www.flickr.com/people/killer_bob/"}})
372
+
373
+ assert_equal "http://www.flickr.com/people/killer_bob/", new_user( 'client' => f ).pretty_url
374
+ end
375
+
376
+ def test_should_cache_pretty_url_for_users_profile_page
377
+ f = flickr_client
378
+ user = new_user( 'client' => f )
379
+ f.expects(:urls_getUserProfile).returns({"user" => {"nsid" => "bar456", "url" => "http://www.flickr.com/people/killer_bob/"}}) # expects only one call
380
+
381
+ user.pretty_url
382
+ user.pretty_url
383
+ end
384
+
385
+ def test_should_get_users_public_groups
386
+ f = flickr_client
387
+ f.expects(:request).with("people.getPublicGroups", anything).returns(dummy_groups_response)
388
+ new_user( 'client' => f ).groups
389
+ end
390
+
391
+ def test_should_instantiate_users_public_groups
392
+ f = flickr_client
393
+ f.stubs(:request).returns(dummy_groups_response)
394
+ user = new_user( 'client' => f )
395
+
396
+ groups = user.groups
397
+ assert_equal 2, groups.size
398
+ assert_kind_of Flickr::Group, group = groups.first
399
+ assert_equal "group1", group.id
400
+ assert_equal "Group One", group.name
401
+ assert_equal "0", group.eighteenplus
402
+ assert_equal f, group.client
403
+ end
404
+
405
+ def test_should_instantiate_users_public_groups_when_only_one_returned
406
+ f = flickr_client
407
+ f.stubs(:request).returns(dummy_single_group_response)
408
+ user = new_user( 'client' => f )
409
+ groups = user.groups
410
+ assert_equal 1, groups.size
411
+ end
412
+
413
+ def test_should_get_users_tags
414
+ f = flickr_client
415
+ user = new_user( 'client' => f )
416
+ f.expects(:tags_getListUser).with('user_id'=>user.id).returns({"who"=>{"tags"=>{"tag"=>["offf08", "ruby", "rubyonrails", "timoteo", "wbs", "webreakstuff"]}, "id"=>"9259187@N05"}, "stat"=>"ok"})
417
+ tags = user.tags
418
+ assert_kind_of Array, tags
419
+ assert_equal tags, ["offf08", "ruby", "rubyonrails", "timoteo", "wbs", "webreakstuff"]
420
+ end
421
+
422
+ def test_should_get_users_popular_tags
423
+ f = flickr_client
424
+ user = new_user( 'client' => f )
425
+ f.expects(:tags_getListUserPopular).with('user_id' => user.id).with(anything).returns({"who"=>{"tags"=>{"tag"=>[{"content"=>"design", "count"=>"94"}, {"content"=>"offf08", "count"=>"94"}, {"content"=>"ruby", "count"=>"3"}, {"content"=>"rubyonrails", "count"=>"3"}, {"content"=>"wbs", "count"=>"3"}, {"content"=>"webreakstuff", "count"=>"97"}]}, "id"=>"9259187@N05"}, "stat"=>"ok"})
426
+ pop_tags = user.popular_tags
427
+ assert_kind_of Array, pop_tags
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
+ end
430
+
431
+ # def test_getInfo
432
+ # @u.getInfo
433
+ # assert_equal @username, @u.username
434
+ # end
435
+ #
436
+ # def test_groups
437
+ # assert_kind_of Flickr::Group, @u.groups.first # public groups
438
+ # end
439
+ #
440
+ #
441
+ # def test_contacts
442
+ # assert_kind_of Flickr::User, @u.contacts.first # public contacts
443
+ # end
444
+ #
445
+ # def test_favorites
446
+ # assert_kind_of Flickr::Photo, @u.favorites.first # public favorites
447
+ # end
448
+ #
449
+ # def test_photosets
450
+ # assert_kind_of Flickr::Photoset, @u.photosets.first # public photosets
451
+ # end
452
+ #
453
+ # def test_contactsPhotos
454
+ # assert_kind_of Flickr::Photo, @u.contactsPhotos.first # contacts' favorites
455
+ # end
456
+
457
+ # User#photos tests
458
+
459
+ def test_should_get_users_public_photos
460
+ client = mock
461
+ client.expects(:photos_request).with('people.getPublicPhotos', {'user_id' => 'some_id'}).returns([new_photo, new_photo])
462
+ Flickr.expects(:new).at_least_once.returns(client)
463
+
464
+ user = Flickr::User.new("some_id", "some_user", nil, nil, "some_api_key")
465
+
466
+ photos = user.photos
467
+ assert_equal 2, photos.size
468
+ assert_kind_of Flickr::Photo, photos.first
469
+ end
470
+
471
+ def test_should_instantiate_favorite_photos_with_id_and_all_params_returned_by_query
472
+ client = mock
473
+ client.expects(:photos_request).with('favorites.getPublicList', {'user_id' => 'some_id'})
474
+ Flickr.expects(:new).at_least_once.returns(client)
475
+ user = Flickr::User.new("some_id", "some_user", nil, nil, "some_api_key")
476
+ user.favorites
477
+ end
478
+
479
+ def test_should_instantiate_contacts_photos_with_id_and_all_params_returned_by_query
480
+ client = mock
481
+ client.expects(:photos_request).with('photos.getContactsPublicPhotos', {'user_id' => 'some_id'})
482
+ Flickr.expects(:new).at_least_once.returns(client)
483
+ user = Flickr::User.new('some_id', "some_user", nil, nil, "some_api_key")
484
+ user.contactsPhotos
485
+ end
486
+
487
+ # ##### Flickr::Photo tests
488
+
489
+ def test_should_initialize_photo_from_id
490
+ photo = Flickr::Photo.new("foo123")
491
+ assert_equal "foo123", photo.id
492
+ end
493
+
494
+ def test_should_save_extra_params_as_instance_variables
495
+ photo = Flickr::Photo.new('foo123', 'some_api_key', { 'key1' => 'value1', 'key2' => 'value2'})
496
+ assert_equal 'value1', photo.instance_variable_get(:@key1)
497
+ assert_equal 'value2', photo.instance_variable_get(:@key2)
498
+ end
499
+
500
+ def test_should_be_able_to_access_instance_variables_through_hash_like_interface
501
+ photo = Flickr::Photo.new
502
+ photo.instance_variable_set(:@key1, 'value1')
503
+ assert_equal 'value1', photo['key1']
504
+ assert_equal 'value1', photo[:key1]
505
+ assert_nil photo[:key2]
506
+ assert_nil photo['key2']
507
+ end
508
+
509
+ def test_should_get_and_store_other_info_for_photo
510
+ Flickr.any_instance.stubs(:http_get).returns(photo_info_xml_response)
511
+ photo = Flickr::Photo.new('foo123', 'some_api_key')
512
+
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)
515
+ assert_equal "3142", photo.instance_variable_get(:@server)
516
+ assert_equal "ae75bd3111", photo.instance_variable_get(:@secret)
517
+ assert_equal "4", photo.instance_variable_get(:@farm)
518
+ assert_equal "1204145093", photo.instance_variable_get(:@dateuploaded)
519
+ assert_equal "photo", photo.instance_variable_get(:@media)
520
+ assert_equal "0", photo.instance_variable_get(:@isfavorite)
521
+ assert_equal "0", photo.instance_variable_get(:@license)
522
+ assert_equal "0", photo.instance_variable_get(:@rotation)
523
+ assert_equal "1964 Volvo 120 amazon estate spotted in derbyshire.", photo.instance_variable_get(:@description)
524
+ assert_equal( { "w" => "50",
525
+ "x" => "10",
526
+ "y" => "10",
527
+ "authorname" => "Bees",
528
+ "author" => "12037949754@N01",
529
+ "id" => "313",
530
+ "content" => "foo",
531
+ "h" => "50" }, photo.instance_variable_get(:@notes))
532
+ assert_equal "http://www.flickr.com/photos/rootes_arrow/2296968304/", photo.instance_variable_get(:@url)
533
+ assert_equal [ { "id" => "9377979-2296968304-2228", "author" => "9383319@N05", "raw" => "volvo", "machine_tag" => "0", "content" => "volvo" },
534
+ { "id" => "9377979-2296968304-2229", "author" => "9383319@N06", "raw" => "amazon", "machine_tag" => "0", "content" => "amazon"
535
+ } ], photo.instance_variable_get(:@tags)
536
+ assert_equal "1", photo.instance_variable_get(:@comments)
537
+ assert_kind_of Flickr::User, owner = photo.instance_variable_get(:@owner)
538
+ assert_equal "Rootes_arrow_1725", owner.username
539
+ end
540
+
541
+ def test_should_get_and_other_info_for_photo_when_some_attributes_missing
542
+ Flickr.any_instance.stubs(:http_get).returns(sparse_photo_info_xml_response)
543
+ photo = Flickr::Photo.new('foo123', 'some_api_key')
544
+
545
+ assert_equal "1964 120 amazon estate", photo.title # calling #title method triggers getting of info
546
+ assert_equal "1964 120 amazon estate", photo.instance_variable_get(:@title)
547
+ assert_equal( {}, photo.instance_variable_get(:@description))
548
+ assert_nil photo.instance_variable_get(:@notes)
549
+ assert_nil photo.instance_variable_get(:@tags)
550
+ assert_equal "1", photo.instance_variable_get(:@comments)
551
+ end
552
+
553
+ def test_should_not_get_info_more_than_once
554
+ Flickr.any_instance.expects(:http_get).returns(photo_info_xml_response) # expects only one call
555
+ photo = Flickr::Photo.new('foo123', 'some_api_key')
556
+
557
+ photo.description # calling #description method triggers getting of info
558
+ photo.instance_variable_set(:@description, nil) # set description to nil
559
+ photo.description # call #description method again
560
+ end
561
+
562
+ #
563
+ # owner tests
564
+ def test_should_return_owner_when_flickr_user
565
+ user = Flickr::User.new
566
+ photo = new_photo("owner" => user)
567
+
568
+ assert_equal user, photo.owner
569
+ end
570
+
571
+ def test_should_get_info_on_owner_if_not_known
572
+ photo = new_photo("owner" => nil)
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'}}})
576
+
577
+ owner = photo.owner
578
+ assert_kind_of Flickr::User, owner
579
+ assert_equal 'abc123', owner.id
580
+ assert_equal 'SomeUserName', owner.username
581
+ end
582
+
583
+ def test_should_instantiate_flickr_user_from_owner_id_if_we_have_it
584
+ photo = Flickr::Photo.new
585
+ photo.instance_variable_set(:@owner, "some_user_id")
586
+ Flickr.any_instance.expects(:photos_getInfo).never
587
+
588
+ user = photo.owner
589
+ assert_kind_of Flickr::User, user
590
+ assert_equal "some_user_id", user.id
591
+ end
592
+
593
+ def test_should_cache_owner_when_instantiated
594
+ user = Flickr::User.new
595
+ photo = Flickr::Photo.new
596
+ photo.instance_variable_set(:@owner, "some_user_id")
597
+ Flickr::User.expects(:new).returns(user)
598
+
599
+ photo.owner
600
+ photo.owner # call twice but mock expects only one call
601
+ end
602
+
603
+ #
604
+ # image_source_uri_from_self tests
605
+ def test_should_build_image_source_uri_from_self
606
+ assert_equal "http://farm1.static.flickr.com/2/1418878_1e92283336.jpg",
607
+ new_photo.send(:image_source_uri_from_self) # no size specified
608
+ end
609
+
610
+ def test_should_build_image_source_uri_from_self_for_given_size
611
+ assert_equal "http://farm1.static.flickr.com/2/1418878_1e92283336_m.jpg",
612
+ new_photo.send(:image_source_uri_from_self, "Small") # size specified
613
+ end
614
+
615
+ def test_should_build_image_source_uri_from_self_for_default_size_when_explicitly_asked_for
616
+ assert_equal "http://farm1.static.flickr.com/2/1418878_1e92283336.jpg",
617
+ new_photo.send(:image_source_uri_from_self, "Medium") # medium size specified -- the default
618
+ end
619
+
620
+ def test_should_build_image_source_uri_from_self_for_default_size_when_unknown_size_asked_for
621
+ assert_equal "http://farm1.static.flickr.com/2/1418878_1e92283336.jpg",
622
+ new_photo.send(:image_source_uri_from_self, "Dummy") # bad size specified
623
+ end
624
+
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)
627
+ end
628
+
629
+ def test_should_return_nil_for_image_source_uri_if_missing_required_attributes
630
+ assert_nil Flickr::Photo.new("1418878", nil, "farm" => "1").send(:image_source_uri_from_self)
631
+ end
632
+
633
+ def test_image_source_uri_from_self_should_normalize_size
634
+ photo = new_photo
635
+ assert_equal photo.send(:image_source_uri_from_self, 'Large'),
636
+ photo.send(:image_source_uri_from_self, :large)
637
+ end
638
+
639
+ def test_uri_for_photo_from_self_should_normalize_size
640
+ photo = new_photo
641
+ assert_equal photo.send(:uri_for_photo_from_self, 'Large'),
642
+ photo.send(:uri_for_photo_from_self, :large)
643
+ end
644
+
645
+ def test_should_get_source_uri_by_building_from_self_if_possible
646
+ photo = Flickr::Photo.new
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
+ photo.source
649
+ end
650
+
651
+ def test_should_get_source_uri_by_building_from_self_if_possible_requesting_source_for_given_size
652
+ photo = Flickr::Photo.new
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
+ photo.source('Large')
655
+ end
656
+
657
+ def test_should_get_source_uri_by_calling_sizes_method_if_no_luck_building_uri
658
+ photo = Flickr::Photo.new
659
+ photo.stubs(:image_source_uri_from_self) # ...and hence returns nil
660
+ photo.expects(:sizes).with('Medium').returns({})
661
+ photo.source
662
+ end
663
+
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)
666
+ end
667
+
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)
670
+ end
671
+
672
+ def test_should_build_uri_for_photo_from_self_for_given_size
673
+ assert_equal "http://www.flickr.com/photos/abc123/1418878/sizes/s/", new_photo.send(:uri_for_photo_from_self, "Small")
674
+ end
675
+
676
+ def test_should_build_uri_for_photo_from_self_with_unknown_size
677
+ assert_equal "http://www.flickr.com/photos/abc123/1418878", new_photo.send(:uri_for_photo_from_self, "Dummy")
678
+ end
679
+
680
+ def test_should_return_nil_for_uri_for_photo_when_no_user_id
681
+ assert_nil Flickr::Photo.new("1418878", nil).send(:uri_for_photo_from_self)
682
+ end
683
+
684
+ def test_should_return_nil_for_uri_for_photo_when_no_photo_id
685
+ assert_nil Flickr::Photo.new.send(:uri_for_photo_from_self)
686
+ end
687
+
688
+ def test_should_get_uri_for_photo_flickr_page
689
+ photo = new_photo
690
+ assert_equal "http://www.flickr.com/photos/abc123/1418878", photo.url
691
+ end
692
+
693
+ def test_should_return_main_page_for_photo_flickr_page_when_medium_size_requested_as_per_previous_version
694
+ assert_equal "http://www.flickr.com/photos/abc123/1418878", new_photo.url('Medium')
695
+ end
696
+
697
+ def test_should_call_size_url_if_url_given_a_size
698
+ photo = new_photo
699
+ photo.expects(:size_url).with('Large')
700
+ photo.url('Large')
701
+ end
702
+
703
+ def test_should_get_flickr_page_uri_by_building_from_self_if_possible_requesting_source_for_given_size
704
+ photo = new_photo
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
+ photo.size_url('Large')
707
+ end
708
+
709
+ def test_should_get_flickr_page_uri_by_calling_sizes_method_if_no_luck_building_uri
710
+ photo = new_photo
711
+ photo.stubs(:uri_for_photo_from_self) # ...and hence returns nil
712
+ photo.expects(:sizes).with('Large').returns({})
713
+ photo.size_url('Large')
714
+ end
715
+
716
+ def test_should_allow_size_to_be_lowercase_or_symbol
717
+ photo = new_photo
718
+ assert_equal photo.normalize_size('Small'), 'Small'
719
+ assert_equal photo.normalize_size('small'), 'Small'
720
+ assert_equal photo.normalize_size(:small), 'Small'
721
+ assert_equal photo.normalize_size(:Small), 'Small'
722
+ assert_equal photo.normalize_size('smAlL'), 'Small'
723
+
724
+ assert_equal photo.normalize_size(""), ""
725
+ assert_nil photo.normalize_size(nil)
726
+ end
727
+
728
+ def test_size_url_should_normalize_size
729
+ photo = new_photo
730
+ assert_equal photo.size_url('Large'), photo.size_url(:large)
731
+ end
732
+
733
+ def test_url_should_normalize_size
734
+ photo = new_photo
735
+ assert_equal photo.url('Medium'), photo.url(:medium)
736
+ assert_equal photo.url('Small'), photo.url('small')
737
+ end
738
+
739
+ def test_source_should_normalize_size
740
+ photo = new_photo
741
+ assert_equal photo.source('Large'), photo.source(:large)
742
+ end
743
+
744
+ def test_sizes_should_normalize_size
745
+ sizes = {'sizes' => {'size' => [{'label' => 'Small'}, {'label' => 'Large'}]}}
746
+ photo = new_photo
747
+ photo.client.expects(:photos_getSizes).at_least_once.returns(sizes)
748
+ assert_equal photo.sizes('Large'), photo.sizes(:large)
749
+ end
750
+
751
+ # Photo#context tests
752
+ def test_should_call_photos_getContext_to_get_context_photos
753
+ Flickr.any_instance.expects(:photos_getContext).returns({'prevphoto' => {}, 'nextphoto' => {}})
754
+ new_photo.context
755
+ end
756
+
757
+ def test_should_instantiate_context_photos_with_id_and_all_params_returned_by_query
758
+ photo = new_photo
759
+ Flickr.any_instance.expects(:photos_getContext).returns({ 'prevphoto' => {'id' => '123', 'key_1' => 'value_1' },
760
+ 'nextphoto' => {'id' => '456', 'key_2' => 'value_2'}})
761
+ Flickr::Photo.expects(:new).with("123", "foo123", { "key_1" => "value_1"})
762
+ Flickr::Photo.expects(:new).with("456", "foo123", { "key_2" => "value_2"})
763
+
764
+ photo.context
765
+ end
766
+
767
+ def test_should_not_instantiate_context_photos_with_id_of_0
768
+ photo = new_photo
769
+ Flickr.any_instance.expects(:photos_getContext).returns({ 'prevphoto' => {'id' => '123', 'key_1' => 'value_1' },
770
+ 'nextphoto' => {'id' => '0', 'key_2' => 'value_2'}})
771
+ Flickr::Photo.expects(:new).with("123", anything, anything)
772
+ Flickr::Photo.expects(:new).with("0", anything, anything).never
773
+
774
+ photo.context
775
+ end
776
+
777
+ # ##### Flickr::Group tests
778
+ #
779
+ def test_should_instantiate_group_from_id
780
+ group = Flickr::Group.new("group1")
781
+ assert_equal "group1", group.id
782
+ end
783
+
784
+ # tests old api for instantiating groups
785
+ def test_should_instantiate_group_from_id_and_api_key
786
+ f = flickr_client
787
+ Flickr.expects(:new).with("some_api_key").returns(f)
788
+ group = Flickr::Group.new("group1", "some_api_key")
789
+ assert_equal f, group.client
790
+ end
791
+
792
+ # new api for instantiating groups
793
+ def test_should_instantiate_group_from_params_hash
794
+ group = Flickr::Group.new("id" => "group1", "name" => "Group One", "eighteenplus" => "1", "foo" => "bar")
795
+ assert_equal "group1", group.id
796
+ assert_equal "Group One", group.name
797
+ assert_equal "1", group.eighteenplus
798
+ assert_equal "bar", group.instance_variable_get(:@foo)
799
+ end
800
+
801
+ def test_should_use_flickr_client_passed_in_params_hash_when_instantiating_group
802
+ f = flickr_client
803
+ Flickr.expects(:new).never
804
+ group = Flickr::Group.new("id" => "group1", "name" => "Group One", "client" => f)
805
+ assert_equal f, group.client
806
+ end
807
+
808
+ def test_should_provide_id_name_eighteenplus_description_members_online_privacy_reader_methods_for_group
809
+ g = Flickr::Group.new
810
+ %w(id name eighteenplus description members online privacy).each do |m|
811
+ g.instance_variable_set("@#{m}", "foo_#{m}")
812
+ assert_equal "foo_#{m}", g.send(m)
813
+ end
814
+ end
815
+
816
+ # def test_should_initialize_photo_from_id
817
+ # photo = Flickr::Photo.new("foo123")
818
+ # assert_equal "foo123", photo.id
819
+ # end
820
+ #
821
+ # def test_should_save_extra_params_as_instance_variables
822
+ # photo = Flickr::Photo.new('foo123', 'some_api_key', { 'key1' => 'value1', 'key2' => 'value2'})
823
+ # assert_equal 'value1', photo.instance_variable_get(:@key1)
824
+ # assert_equal 'value2', photo.instance_variable_get(:@key2)
825
+ # end
826
+ #
827
+ # def test_should_be_able_to_access_instance_variables_through_hash_like_interface
828
+ # photo = Flickr::Photo.new
829
+ # photo.instance_variable_set(:@key1, 'value1')
830
+ # assert_equal 'value1', photo['key1']
831
+ # assert_equal 'value1', photo[:key1]
832
+ # assert_nil photo[:key2]
833
+ # assert_nil photo['key2']
834
+ # end
835
+
836
+ ## PHOTOSETS
837
+
838
+ def test_should_initialize_photoset_from_id
839
+ photoset = Flickr::Photoset.new("foo123")
840
+ assert_equal "foo123", photoset.id
841
+ end
842
+
843
+ def test_should_initialize_photoset_from_id_and_api_key
844
+ photoset = Flickr::Photoset.new("foo123", "some_api_key")
845
+ assert_equal "some_api_key", photoset.instance_variable_get(:@api_key)
846
+ end
847
+
848
+ def test_should_get_photos_for_specified_photoset
849
+ Flickr.any_instance.expects(:request).with('photosets.getPhotos', {'photoset_id' => 'some_id'}).returns(dummy_photoset_photos_response)
850
+ photoset = Flickr::Photoset.new("some_id", "some_api_key")
851
+
852
+ assert_kind_of Flickr::PhotoCollection, photos = photoset.getPhotos
853
+ assert_equal 2, photos.size
854
+ assert_kind_of Flickr::Photo, photos.first
855
+ end
856
+
857
+
858
+ # def test_photosets_editMeta
859
+ # assert_equal @f.photosets_editMeta('photoset_id'=>@photoset_id, 'title'=>@title)['stat'], 'ok'
860
+ # end
861
+ #
862
+ # def test_photosets_editPhotos
863
+ # assert_equal @f.photosets_editPhotos('photoset_id'=>@photoset_id, 'primary_photo_id'=>@photo_id, 'photo_ids'=>@photo_id)['stat'], 'ok'
864
+ # end
865
+ #
866
+ # def test_photosets_getContext
867
+ # assert_equal @f.photosets_getContext('photoset_id'=>@photoset_id, 'photo_id'=>@photo_id)['stat'], 'ok'
868
+ # end
869
+ #
870
+ # def test_photosets_getContext
871
+ # assert_equal @f.photosets_getContext('photoset_id'=>@photoset_id, 'photo_id'=>@photo_id)['stat'], 'ok'
872
+ # end
873
+ #
874
+ # def test_photosets_getInfo
875
+ # assert_equal @f.photosets_getInfo('photoset_id'=>@photoset_id)['stat'], 'ok'
876
+ # end
877
+ #
878
+ # def test_photosets_getList
879
+ # assert_equal @f.photosets_getList['stat'], 'ok'
880
+ # end
881
+ #
882
+ # def test_photosets_getPhotos
883
+ # assert_equal @f.photosets_getPhotos('photoset_id'=>@photoset_id)['stat'], 'ok'
884
+ # end
885
+ #
886
+ # def test_photosets_orderSets
887
+ # assert_equal @f.photosets_orderSets('photoset_ids'=>@photoset_id)['stat'], 'ok'
888
+ # end
889
+
890
+ def test_related_tags
891
+ f = flickr_client
892
+ tags_response = {
893
+ "tags" => {
894
+ "tag" => [ "zoo", "animal" ],
895
+ "source" => "monkey",
896
+ },
897
+ "stat" => "ok",
898
+ }
899
+ f.expects(:tags_getRelated).with('tag' => 'monkey').returns(tags_response)
900
+ assert_equal f.related_tags('monkey'), %w(zoo animal)
901
+ end
902
+
903
+ # ##### Flickr::PhotoCollection tests
904
+ #
905
+ def test_should_subclass_array_as_photo_collection
906
+ assert_equal Array, Flickr::PhotoCollection.superclass
907
+ end
908
+
909
+ def test_should_make_page_a_reader_method
910
+ assert_equal "3", dummy_photo_collection.page
911
+ end
912
+
913
+ def test_should_make_pages_a_reader_method
914
+ assert_equal "5", dummy_photo_collection.pages
915
+ end
916
+
917
+ def test_should_make_perpage_a_reader_method
918
+ assert_equal "10", dummy_photo_collection.perpage
919
+ end
920
+
921
+ def test_should_make_total_a_reader_method
922
+ assert_equal "42", dummy_photo_collection.total
923
+ end
924
+
925
+ def test_should_instantiate_photo_collection_from_photos_hash
926
+ pc = Flickr::PhotoCollection.new(dummy_photos_response)
927
+ assert_kind_of Flickr::PhotoCollection, pc
928
+ assert_equal 2, pc.size
929
+ assert_kind_of Flickr::Photo, pc.first
930
+ assert_equal "foo123", pc.first["id"]
931
+ end
932
+
933
+ def test_should_instantiate_photo_collection_using_given_api_key
934
+ photo = Flickr::PhotoCollection.new(dummy_photos_response, "some_api_key").first
935
+ assert_equal "some_api_key", photo.instance_variable_get(:@api_key)
936
+ end
937
+
938
+ private
939
+ def flickr_client
940
+ Flickr.new("some_api_key")
941
+ end
942
+
943
+ def authenticated_flickr_client
944
+ f = Flickr.new(:api_key => 'some_api_key', :shared_secret => 'shared_secret_code')
945
+ f.instance_variable_set(:@auth_token, 'some_auth_token')
946
+ f
947
+ end
948
+
949
+ def new_user(options={})
950
+ Flickr::User.new({ 'id' => 'foo123',
951
+ 'username' => 'some_user',
952
+ 'name' => 'Some User',
953
+ 'foo' => 'bar',
954
+ 'auth_token' => 'foobar789'}.merge(options))
955
+
956
+ end
957
+ def new_photo(options={})
958
+ Flickr::Photo.new("1418878",
959
+ "foo123",
960
+ { "farm" => "1",
961
+ "server" => "2",
962
+ "secret" => "1e92283336",
963
+ "owner" => Flickr::User.new("abc123", "some_user", nil, nil, "some_api_key") }.merge(options))
964
+ end
965
+
966
+ def dummy_photo_collection
967
+ Flickr::PhotoCollection.new(dummy_photos_response)
968
+ end
969
+
970
+ def dummy_photos_response
971
+ { "photos" =>
972
+ { "photo" =>
973
+ [{ "id" => "foo123",
974
+ "key1" => "value1",
975
+ "key2" => "value2" },
976
+ { "id" => "bar456",
977
+ "key3" => "value3"}],
978
+ "page"=>"3",
979
+ "pages"=>"5",
980
+ "perpage"=>"10",
981
+ "total"=>"42" } }
982
+ end
983
+
984
+ def dummy_single_photo_response
985
+ { "photos" =>
986
+ { "photo" =>
987
+ { "id" => "foo123",
988
+ "key1" => "value1",
989
+ "key2" => "value2" } } }
990
+ end
991
+
992
+ def dummy_zero_photo_response
993
+ { "photos" => { "total" => 0 } }
994
+ end
995
+
996
+ def dummy_user_response
997
+ { "user" =>
998
+ { "nsid" => "12037949632@N01",
999
+ "username" => "Stewart" }
1000
+ }
1001
+ end
1002
+
1003
+ def dummy_groups_response
1004
+ { "groups" =>
1005
+ { "group" =>
1006
+ [{ "nsid" => "group1",
1007
+ "name" => "Group One",
1008
+ "eighteenplus" => "0" },
1009
+ { "nsid" => "group2",
1010
+ "name" => "Group Two",
1011
+ "eighteenplus" => "1"}] } }
1012
+ end
1013
+
1014
+ def dummy_single_group_response
1015
+ { "groups" =>
1016
+ { "group" =>
1017
+ { "nsid" => "group1",
1018
+ "name" => "Group One",
1019
+ "eighteenplus" => "0" } } }
1020
+ end
1021
+
1022
+ def dummy_photoset_photos_response
1023
+ { "photoset" =>
1024
+ { "photo" =>
1025
+ [{ "id" => "foo123",
1026
+ "key1" => "value1",
1027
+ "key2" => "value2" },
1028
+ { "id" => "bar456",
1029
+ "key3" => "value3"}],
1030
+ "page"=>"3",
1031
+ "pages"=>"5",
1032
+ "perpage"=>"10",
1033
+ "total"=>"42" } }
1034
+ end
1035
+
1036
+ def successful_xml_response
1037
+ <<-EOF
1038
+ <?xml version="1.0" encoding="utf-8" ?>
1039
+ <rsp stat="ok">
1040
+ <contacts page="1" pages="1" perpage="1000" total="2">
1041
+ <contact nsid="12037949629@N01" username="Eric" iconserver="1"
1042
+ realname="Eric Costello"
1043
+ friend="1" family="0" ignored="1" />
1044
+ <contact nsid="12037949631@N01" username="neb" iconserver="1"
1045
+ realname="Ben Cerveny"
1046
+ friend="0" family="0" ignored="0" />
1047
+ </contacts>
1048
+ </rsp>
1049
+ EOF
1050
+ end
1051
+
1052
+ def unsuccessful_xml_response
1053
+ <<-EOF
1054
+ <?xml version="1.0" encoding="utf-8" ?>
1055
+ <rsp stat="fail">
1056
+ <err code="[error-code]" msg="[error-message]" />
1057
+ </rsp>
1058
+ EOF
1059
+ end
1060
+
1061
+ def photo_info_xml_response
1062
+ <<-EOF
1063
+ <?xml version="1.0" encoding="utf-8" ?>
1064
+ <rsp stat="ok">
1065
+ <photo id="22527834" secret="ae75bd3111" server="3142" farm="4" dateuploaded="1204145093" isfavorite="0" license="0" rotation="0" media="photo">
1066
+ <owner nsid="9383319@N05" username="Rootes_arrow_1725" realname="John" location="U.K" />
1067
+ <title>1964 120 amazon estate</title>
1068
+ <description>1964 Volvo 120 amazon estate spotted in derbyshire.</description>
1069
+ <visibility ispublic="1" isfriend="0" isfamily="0" />
1070
+ <dates posted="1204145093" taken="2007-06-10 13:18:27" takengranularity="0" lastupdate="1204166772" />
1071
+ <editability cancomment="0" canaddmeta="0" />
1072
+ <usage candownload="0" canblog="0" canprint="0" />
1073
+ <comments>1</comments>
1074
+ <notes>
1075
+ <note id="313" author="12037949754@N01" authorname="Bees" x="10" y="10" w="50" h="50">foo</note>
1076
+ </notes>
1077
+ <tags>
1078
+ <tag id="9377979-2296968304-2228" author="9383319@N05" raw="volvo" machine_tag="0">volvo</tag>
1079
+ <tag id="9377979-2296968304-2229" author="9383319@N06" raw="amazon" machine_tag="0">amazon</tag>
1080
+ </tags>
1081
+ <urls>
1082
+ <url type="photopage">http://www.flickr.com/photos/rootes_arrow/2296968304/</url>
1083
+ </urls>
1084
+ </photo>
1085
+ </rsp>
1086
+ EOF
1087
+ end
1088
+
1089
+ def sparse_photo_info_xml_response
1090
+ <<-EOF
1091
+ <?xml version="1.0" encoding="utf-8" ?>
1092
+ <rsp stat="ok">
1093
+ <photo id="22527834" secret="ae75bd3111" server="3142" farm="4" dateuploaded="1204145093" isfavorite="0" license="0" rotation="0" media="photo">
1094
+ <owner nsid="9383319@N05" username="Rootes_arrow_1725" realname="John" location="U.K" />
1095
+ <title>1964 120 amazon estate</title>
1096
+ <description/>
1097
+ <visibility ispublic="1" isfriend="0" isfamily="0" />
1098
+ <dates posted="1204145093" taken="2007-06-10 13:18:27" takengranularity="0" lastupdate="1204166772" />
1099
+ <editability cancomment="0" canaddmeta="0" />
1100
+ <usage candownload="0" canblog="0" canprint="0" />
1101
+ <comments>1</comments>
1102
+ <notes/>
1103
+ <tags/>
1104
+ <urls>
1105
+ <url type="photopage">http://www.flickr.com/photos/rootes_arrow/2296968304/</url>
1106
+ </urls>
1107
+ </photo>
1108
+ </rsp>
1109
+ EOF
1110
+ end
1111
+
1112
+ end