ctagg-flickr 1.0.8

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