flickrie 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/.gitignore +0 -1
  2. data/CHANGELOG.md +10 -0
  3. data/Gemfile +3 -2
  4. data/Rakefile +7 -2
  5. data/flickrie.gemspec +3 -0
  6. data/lib/flickrie/api_methods.rb +5 -0
  7. data/lib/flickrie/client.rb +17 -4
  8. data/lib/flickrie/location.rb +23 -50
  9. data/lib/flickrie/media/exif.rb +4 -0
  10. data/lib/flickrie/media/tag.rb +4 -0
  11. data/lib/flickrie/media/ticket.rb +4 -0
  12. data/lib/flickrie/media/visibility.rb +10 -6
  13. data/lib/flickrie/media.rb +7 -70
  14. data/lib/flickrie/media_count.rb +4 -0
  15. data/lib/flickrie/oauth.rb +5 -3
  16. data/lib/flickrie/set.rb +5 -21
  17. data/lib/flickrie/upload_client.rb +4 -2
  18. data/lib/flickrie/user.rb +4 -1
  19. data/lib/flickrie/version.rb +1 -1
  20. data/lib/flickrie/video.rb +0 -13
  21. data/test/error_test.rb +20 -0
  22. data/test/instance_test.rb +13 -14
  23. data/test/license_test.rb +7 -13
  24. data/test/location_test.rb +11 -2
  25. data/test/media_count_test.rb +20 -12
  26. data/test/media_test.rb +319 -311
  27. data/test/oauth_test.rb +17 -18
  28. data/test/photo_test.rb +78 -60
  29. data/test/set_test.rb +72 -63
  30. data/test/{test.rb → test_helper.rb} +7 -0
  31. data/test/user_test.rb +43 -34
  32. data/test/vcr_cassettes/error/code.yml +1165 -0
  33. data/test/vcr_cassettes/instance/calling_api_methods.yml +182 -0
  34. data/test/vcr_cassettes/license/get_licenses.yml +73 -0
  35. data/test/vcr_cassettes/location/square_brackets.yml +85 -0
  36. data/test/vcr_cassettes/media/delete.yml +1380 -0
  37. data/test/vcr_cassettes/media/from_contacts.yml +155 -0
  38. data/test/vcr_cassettes/media/from_set.yml +276 -0
  39. data/test/vcr_cassettes/media/from_user.yml +275 -0
  40. data/test/vcr_cassettes/media/get_context.yml +73 -0
  41. data/test/vcr_cassettes/media/get_info.yml +167 -0
  42. data/test/vcr_cassettes/media/remove_tag.yml +264 -0
  43. data/test/vcr_cassettes/media/replace.yml +2252 -0
  44. data/test/vcr_cassettes/media/search.yml +275 -0
  45. data/test/vcr_cassettes/media/tags.yml +346 -0
  46. data/test/vcr_cassettes/media_count/get.yml +135 -0
  47. data/test/vcr_cassettes/media_count/square_brackets.yml +69 -0
  48. data/test/vcr_cassettes/oauth/tokens.yml +400 -0
  49. data/test/vcr_cassettes/photo/asynchronous_upload.yml +1693 -0
  50. data/test/vcr_cassettes/photo/from_set.yml +273 -0
  51. data/test/vcr_cassettes/photo/from_user.yml +275 -0
  52. data/test/vcr_cassettes/photo/get_exif.yml +239 -0
  53. data/test/vcr_cassettes/photo/get_sizes.yml +147 -0
  54. data/test/vcr_cassettes/photo/other_api_calls.yml +506 -0
  55. data/test/vcr_cassettes/photo/search.yml +271 -0
  56. data/test/vcr_cassettes/photo/square_brackets.yml +85 -0
  57. data/test/vcr_cassettes/photo/upload.yml +1229 -0
  58. data/test/vcr_cassettes/set/from_user.yml +477 -0
  59. data/test/vcr_cassettes/set/get_info.yml +951 -0
  60. data/test/vcr_cassettes/set/square_brackets.yml +73 -0
  61. data/test/vcr_cassettes/user/find_by_email_or_username.yml +135 -0
  62. data/test/vcr_cassettes/user/get_info.yml +151 -0
  63. data/test/vcr_cassettes/user/square_brackets.yml +77 -0
  64. data/test/vcr_cassettes/video/get_exif.yml +135 -0
  65. data/test/vcr_cassettes/video/get_info.yml +86 -0
  66. data/test/vcr_cassettes/video/get_sizes.yml +151 -0
  67. data/test/vcr_cassettes/video/other_api_calls.yml +643 -0
  68. data/test/vcr_cassettes/video/square_brackets.yml +86 -0
  69. data/test/vcr_cassettes/video/upload.yml +308 -0
  70. data/test/video_test.rb +66 -53
  71. metadata +123 -12
data/test/media_test.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'test'
3
2
 
4
3
  Flickrie::Photo.instance_eval do
5
4
  def public_new(*args)
@@ -20,296 +19,220 @@ class MediaTest < Test::Unit::TestCase
20
19
  url_sq url_q url_t url_s url_n url_m url_z url_c url_l url_o]
21
20
  end
22
21
 
23
- def test_get_media_info
24
- get_info_assertions(Flickrie.get_media_info(@media_id))
25
- get_info_assertions(Flickrie::Photo.public_new('id' => @media_id.to_s).get_info)
22
+ def test_get_info
23
+ VCR.use_cassette 'media/get_info' do
24
+ [Flickrie.get_media_info(@media_id),
25
+ Flickrie::Photo.public_new('id' => @media_id.to_s).get_info].
26
+ each do |media|
27
+ assert_equal '6946979188', media.id
28
+ assert_equal '25bb44852b', media.secret
29
+ assert_equal '7049', media.server
30
+ assert_equal 8, media.farm
31
+ assert_equal 'IMG_0796', media.title
32
+
33
+ assert_equal 'luka', media.tags.join(' ')
34
+ assert_equal @user_nsid, media.tags.first.author.nsid
35
+ assert_equal 'luka', media.tags.first.raw
36
+ assert_equal false, media.tags.first.machine_tag?
37
+
38
+ assert_equal 2, media.views_count
39
+ assert_equal 1, media.comments_count
40
+ assert_equal '0', media.license.id
41
+ assert_equal 0, media.safety_level
42
+ assert_equal 90, media.rotation
43
+ assert_equal 'Test', media.description
44
+ assert_not_nil media.url
45
+
46
+ # Time
47
+ assert_instance_of Time, media.uploaded_at
48
+ assert_instance_of Time, media.updated_at
49
+ assert_instance_of Time, media.taken_at
50
+ assert_equal 0, media.taken_at_granularity
51
+ assert_instance_of Time, media.posted_at
52
+
53
+ # Owner
54
+ assert_equal '67131352@N04', media.owner.nsid
55
+ assert_equal 'Janko Marohnić', media.owner.username
56
+ assert_equal 'Janko Marohnić', media.owner.real_name
57
+ assert_equal 'Zagreb, Croatia', media.owner.location
58
+ assert_equal '5464', media.owner.icon_server
59
+ assert_equal 6, media.owner.icon_farm
60
+ refute media.owner.buddy_icon_url.empty?
61
+
62
+ # Predicates
63
+ assert_equal true, media.visibility.public?
64
+ assert_equal false, media.visibility.friends?
65
+ assert_equal false, media.visibility.family?
66
+ assert_equal nil, media.visibility.contacts?
67
+
68
+ assert_equal true, media.can_comment?
69
+ assert_equal true, media.can_add_meta?
70
+ assert_equal true, media.can_everyone_comment?
71
+ assert_equal false, media.can_everyone_add_meta?
72
+
73
+ assert_equal true, media.can_download?
74
+ assert_equal true, media.can_blog?
75
+ assert_equal true, media.can_print?
76
+ assert_equal false, media.can_share?
77
+
78
+ assert_equal false, media.has_people?
79
+
80
+ assert_equal true, media.safe?
81
+ assert_equal false, media.moderate?
82
+ assert_equal false, media.restricted?
83
+
84
+ assert_equal false, media.favorite?
85
+
86
+ assert_equal true, media.geo_permissions.public?
87
+ assert_equal false, media.geo_permissions.contacts?
88
+ assert_equal false, media.geo_permissions.friends?
89
+ assert_equal false, media.geo_permissions.family?
90
+
91
+ # Notes
92
+ note = media.notes.first
93
+ assert_equal '72157629487842968', note.id
94
+ assert_equal '67131352@N04', note.author.nsid
95
+ assert_equal 'Janko Marohnić', note.author.username
96
+ assert_equal [316, 0], note.coordinates
97
+ assert_equal [59, 50], [note.width, note.height]
98
+ assert_equal 'Test', note.content
99
+
100
+ # Location
101
+ location = media.location
102
+
103
+ assert_equal 45.807258, location.latitude
104
+ assert_equal 15.967599, location.longitude
105
+ assert_equal '11', location.accuracy
106
+ assert_equal '0', location.context
107
+
108
+ assert_equal nil, location.neighbourhood
109
+ assert_equal 'Zagreb', location.locality.name
110
+ assert_equal '00j4IylZV7scWik', location.locality.place_id
111
+ assert_equal '851128', location.locality.woeid
112
+ assert_equal 'Zagreb', location.county.name
113
+ assert_equal '306dHrhQV7o6jm.ZUQ', location.county.place_id
114
+ assert_equal '15022257', location.county.woeid
115
+ assert_equal 'Grad Zagreb', location.region.name
116
+ assert_equal 'Js1DU.pTUrpBCIKhVw', location.region.place_id
117
+ assert_equal '20070170', location.region.woeid
118
+ assert_equal 'Croatia', location.country.name
119
+ assert_equal 'FunRCI5TUb6a6soTyw', location.country.place_id
120
+ assert_equal '23424843', location.country.woeid
121
+
122
+ assert_equal '00j4IylZV7scWik', location.place_id
123
+ assert_equal '851128', location.woeid
124
+ end
125
+ end
26
126
  end
27
127
 
28
- def get_info_assertions(media)
29
- assert_equal '6946979188', media.id
30
- assert_equal '25bb44852b', media.secret
31
- assert_equal '7049', media.server
32
- assert_equal 8, media.farm
33
- assert_equal 'IMG_0796', media.title
34
-
35
- assert_equal 'luka', media.tags.join(' ')
36
- assert_equal @user_nsid, media.tags.first.author.nsid
37
- assert_equal 'luka', media.tags.first.raw
38
- assert_equal false, media.tags.first.machine_tag?
39
-
40
- assert_equal 2, media.views_count
41
- assert_equal 1, media.comments_count
42
- assert_equal '0', media.license.id
43
- assert_equal 0, media.safety_level
44
- assert_equal 90, media.rotation
45
- assert_equal 'Test', media.description
46
- assert_not_nil media.url
47
-
48
- # Time
49
- assert_instance_of Time, media.uploaded_at
50
- assert_instance_of Time, media.updated_at
51
- assert_instance_of Time, media.taken_at
52
- assert_equal 0, media.taken_at_granularity
53
- assert_instance_of Time, media.posted_at
54
-
55
- # Owner
56
- assert_equal '67131352@N04', media.owner.nsid
57
- assert_equal 'Janko Marohnić', media.owner.username
58
- assert_equal 'Janko Marohnić', media.owner.real_name
59
- assert_equal 'Zagreb, Croatia', media.owner.location
60
- assert_equal '5464', media.owner.icon_server
61
- assert_equal 6, media.owner.icon_farm
62
- refute media.owner.buddy_icon_url.empty?
63
-
64
- # Predicates
65
- assert_equal true, media.visibility.public?
66
- assert_equal false, media.visibility.friends?
67
- assert_equal false, media.visibility.family?
68
- assert_equal nil, media.visibility.contacts?
69
-
70
- assert_equal true, media.can_comment?
71
- assert_equal true, media.can_add_meta?
72
- assert_equal true, media.can_everyone_comment?
73
- assert_equal false, media.can_everyone_add_meta?
74
-
75
- assert_equal true, media.can_download?
76
- assert_equal true, media.can_blog?
77
- assert_equal true, media.can_print?
78
- assert_equal false, media.can_share?
79
-
80
- assert_equal false, media.has_people?
81
-
82
- assert_equal true, media.safe?
83
- assert_equal false, media.moderate?
84
- assert_equal false, media.restricted?
85
-
86
- assert_equal false, media.favorite?
87
-
88
- assert_equal true, media.geo_permissions.public?
89
- assert_equal false, media.geo_permissions.contacts?
90
- assert_equal false, media.geo_permissions.friends?
91
- assert_equal false, media.geo_permissions.family?
92
-
93
- # Notes
94
- note = media.notes.first
95
- assert_equal '72157629487842968', note.id
96
- assert_equal '67131352@N04', note.author.nsid
97
- assert_equal 'Janko Marohnić', note.author.username
98
- assert_equal [316, 0], note.coordinates
99
- assert_equal [59, 50], [note.width, note.height]
100
- assert_equal 'Test', note.content
101
-
102
- # Location
103
- location = media.location
104
-
105
- assert_equal 45.807258, location.latitude
106
- assert_equal 15.967599, location.longitude
107
- assert_equal '11', location.accuracy
108
- assert_equal '0', location.context
109
-
110
- assert_equal nil, location.neighbourhood
111
- assert_equal 'Zagreb', location.locality.name
112
- assert_equal '00j4IylZV7scWik', location.locality.place_id
113
- assert_equal '851128', location.locality.woeid
114
- assert_equal 'Zagreb', location.county.name
115
- assert_equal '306dHrhQV7o6jm.ZUQ', location.county.place_id
116
- assert_equal '15022257', location.county.woeid
117
- assert_equal 'Grad Zagreb', location.region.name
118
- assert_equal 'Js1DU.pTUrpBCIKhVw', location.region.place_id
119
- assert_equal '20070170', location.region.woeid
120
- assert_equal 'Croatia', location.country.name
121
- assert_equal 'FunRCI5TUb6a6soTyw', location.country.place_id
122
- assert_equal '23424843', location.country.woeid
123
-
124
- assert_equal '00j4IylZV7scWik', location.place_id
125
- assert_equal '851128', location.woeid
126
- end
128
+ def test_from_set
129
+ VCR.use_cassette 'media/from_set' do
130
+ media = Flickrie.media_from_set(@set_id, :extras => @all_extras).
131
+ find { |media| media.id.to_i == @media_id }
127
132
 
128
- def test_media_from_set
129
- media = Flickrie.media_from_set(@set_id, :extras => @all_extras).
130
- find { |media| media.id.to_i == @media_id }
131
-
132
- assert_equal '6946979188', media.id
133
- assert_equal '25bb44852b', media.secret
134
- assert_equal '7049', media.server
135
- assert_equal 8, media.farm
136
- assert_equal 'IMG_0796', media.title
137
- assert_equal 'luka', media.tags.join(' ')
138
- assert_equal '', media.machine_tags.join(' ')
139
- assert_equal 2, media.views_count
140
- assert_equal '0', media.license.id
141
- assert_equal true, media.primary?
142
- assert_not_nil media.url
143
- assert_equal 'ready', media.media_status
144
-
145
- # Time
146
- assert_instance_of Time, media.uploaded_at
147
- assert_instance_of Time, media.updated_at
148
- assert_instance_of Time, media.taken_at
149
- assert_equal 0, media.taken_at_granularity
150
-
151
- # Location
152
- assert_equal 45.807258, media.location.latitude
153
- assert_equal 15.967599, media.location.longitude
154
- assert_equal '11', media.location.accuracy
155
- assert_equal '0', media.location.context.to_s
156
- assert_equal '00j4IylZV7scWik', media.location.place_id
157
- assert_equal '851128', media.location.woeid
158
- assert_equal true, media.geo_permissions.public?
159
- assert_equal false, media.geo_permissions.contacts?
160
- assert_equal false, media.geo_permissions.friends?
161
- assert_equal false, media.geo_permissions.family?
162
-
163
- # Owner
164
- assert_equal '67131352@N04', media.owner.nsid
165
- assert_equal 'Janko Marohnić', media.owner.username
166
- assert_equal '5464', media.owner.icon_server
167
- assert_equal 6, media.owner.icon_farm
168
- refute media.owner.buddy_icon_url.empty?
169
- end
133
+ assert_equal '6946979188', media.id
134
+ assert_equal '25bb44852b', media.secret
135
+ assert_equal '7049', media.server
136
+ assert_equal 8, media.farm
137
+ assert_equal 'IMG_0796', media.title
138
+ assert_equal 'luka', media.tags.join(' ')
139
+ assert_equal '', media.machine_tags.join(' ')
140
+ assert_equal 2, media.views_count
141
+ assert_equal '0', media.license.id
142
+ assert_equal true, media.primary?
143
+ assert_not_nil media.url
144
+ assert_equal 'ready', media.media_status
170
145
 
171
- def test_public_media_from_user
172
- media = Flickrie.public_media_from_user(@user_nsid, :extras => @all_extras).
173
- find { |media| media.id.to_i == @media_id }
174
-
175
- assert_equal '6946979188', media.id
176
- assert_equal '25bb44852b', media.secret
177
- assert_equal '7049', media.server
178
- assert_equal 8, media.farm
179
- assert_equal 'IMG_0796', media.title
180
- assert_equal 'luka', media.tags.join(' ')
181
- assert_equal '', media.machine_tags.join(' ')
182
- assert_equal 2, media.views_count
183
- assert_equal '0', media.license.id
184
- assert_not_nil media.url
185
- assert_equal 'ready', media.media_status
186
-
187
- # Time
188
- assert_instance_of Time, media.uploaded_at
189
- assert_instance_of Time, media.updated_at
190
- assert_instance_of Time, media.taken_at
191
- assert_equal 0, media.taken_at_granularity
192
-
193
- # Location
194
- assert_equal 45.807258, media.location.latitude
195
- assert_equal 15.967599, media.location.longitude
196
- assert_equal '11', media.location.accuracy
197
- assert_equal '0', media.location.context.to_s
198
- assert_equal '00j4IylZV7scWik', media.location.place_id
199
- assert_equal '851128', media.location.woeid
200
- assert_equal true, media.geo_permissions.public?
201
- assert_equal false, media.geo_permissions.contacts?
202
- assert_equal false, media.geo_permissions.friends?
203
- assert_equal false, media.geo_permissions.family?
204
-
205
- # Owner
206
- assert_equal '67131352@N04', media.owner.nsid
207
- assert_equal 'Janko Marohnić', media.owner.username
208
- assert_equal '5464', media.owner.icon_server
209
- assert_equal 6, media.owner.icon_farm
210
- refute media.owner.buddy_icon_url.empty?
211
-
212
- # Visibility (This is the difference from Flickrie.media_from_set)
213
- assert_equal true, media.visibility.public?
214
- assert_equal false, media.visibility.friends?
215
- assert_equal false, media.visibility.family?
216
- assert_equal nil, media.visibility.contacts?
217
- end
146
+ # Time
147
+ assert_instance_of Time, media.uploaded_at
148
+ assert_instance_of Time, media.updated_at
149
+ assert_instance_of Time, media.taken_at
150
+ assert_equal 0, media.taken_at_granularity
218
151
 
219
- def test_search_media
220
- media = Flickrie.search_media(:user_id => @user_nsid, :extras => @all_extras).
221
- find { |media| media.id.to_i == @media_id }
222
-
223
- assert_equal '6946979188', media.id
224
- assert_equal '25bb44852b', media.secret
225
- assert_equal '7049', media.server
226
- assert_equal 8, media.farm
227
- assert_equal 'IMG_0796', media.title
228
- assert_equal 'luka', media.tags.join(' ')
229
- assert_equal '', media.machine_tags.join(' ')
230
- assert_equal 2, media.views_count
231
- assert_equal '0', media.license.id
232
- assert_not_nil media.url
233
- assert_equal 'ready', media.media_status
234
-
235
- # Time
236
- assert_instance_of Time, media.uploaded_at
237
- assert_instance_of Time, media.updated_at
238
- assert_instance_of Time, media.taken_at
239
- assert_equal 0, media.taken_at_granularity
240
-
241
- # Location
242
- assert_equal 45.807258, media.location.latitude
243
- assert_equal 15.967599, media.location.longitude
244
- assert_equal '11', media.location.accuracy
245
- assert_equal '0', media.location.context.to_s
246
- assert_equal '00j4IylZV7scWik', media.location.place_id
247
- assert_equal '851128', media.location.woeid
248
- assert_equal true, media.geo_permissions.public?
249
- assert_equal false, media.geo_permissions.contacts?
250
- assert_equal false, media.geo_permissions.friends?
251
- assert_equal false, media.geo_permissions.family?
252
-
253
- # Owner
254
- assert_equal '67131352@N04', media.owner.nsid
255
- assert_equal 'Janko Marohnić', media.owner.username
256
- assert_equal '5464', media.owner.icon_server
257
- assert_equal 6, media.owner.icon_farm
258
- refute media.owner.buddy_icon_url.empty?
259
-
260
- # Visibility (This is the difference from Flickrie.media_from_set)
261
- assert_equal true, media.visibility.public?
262
- assert_equal false, media.visibility.friends?
263
- assert_equal false, media.visibility.family?
264
- assert_equal nil, media.visibility.contacts?
265
- end
152
+ # Location
153
+ assert_equal 45.807258, media.location.latitude
154
+ assert_equal 15.967599, media.location.longitude
155
+ assert_equal '11', media.location.accuracy
156
+ assert_equal '0', media.location.context.to_s
157
+ assert_equal '00j4IylZV7scWik', media.location.place_id
158
+ assert_equal '851128', media.location.woeid
159
+ assert_equal true, media.geo_permissions.public?
160
+ assert_equal false, media.geo_permissions.contacts?
161
+ assert_equal false, media.geo_permissions.friends?
162
+ assert_equal false, media.geo_permissions.family?
266
163
 
267
- def test_add_media_tags
268
- media = Flickrie.get_media_info(@media_id)
269
- tags_before_change = media.tags.join(' ')
270
- Flickrie.add_media_tags(@media_id, "janko")
271
- media.get_info
272
- assert_equal [tags_before_change, "janko"].join(' '),
273
- media.tags.join(' ')
274
- tag_id = media.tags.find { |tag| tag.content == "janko" }.id
275
- Flickrie.remove_media_tag(tag_id)
164
+ # Owner
165
+ assert_equal '67131352@N04', media.owner.nsid
166
+ assert_equal 'Janko Marohnić', media.owner.username
167
+ assert_equal '5464', media.owner.icon_server
168
+ assert_equal 6, media.owner.icon_farm
169
+ refute media.owner.buddy_icon_url.empty?
170
+ end
276
171
  end
277
172
 
278
- def test_remove_media_tag
279
- Flickrie.add_media_tags(@media_id, "janko")
280
- media = Flickrie.get_media_info(@media_id)
281
- tags_before_change = media.tags.join(' ')
282
- tag_id = media.tags.find { |tag| tag.content == "janko" }.id
283
- Flickrie.remove_media_tag(tag_id)
284
- media.get_info
285
- assert_equal media.tags.join(' '), tags_before_change.chomp("janko").rstrip
286
- end
173
+ def test_public_from_user
174
+ VCR.use_cassette 'media/from_user' do
175
+ media = Flickrie.public_media_from_user(@user_nsid, :extras => @all_extras).
176
+ find { |media| media.id.to_i == @media_id }
177
+
178
+ assert_equal '6946979188', media.id
179
+ assert_equal '25bb44852b', media.secret
180
+ assert_equal '7049', media.server
181
+ assert_equal 8, media.farm
182
+ assert_equal 'IMG_0796', media.title
183
+ assert_equal 'luka', media.tags.join(' ')
184
+ assert_equal '', media.machine_tags.join(' ')
185
+ assert_equal 2, media.views_count
186
+ assert_equal '0', media.license.id
187
+ assert_not_nil media.url
188
+ assert_equal 'ready', media.media_status
189
+
190
+ # Time
191
+ assert_instance_of Time, media.uploaded_at
192
+ assert_instance_of Time, media.updated_at
193
+ assert_instance_of Time, media.taken_at
194
+ assert_equal 0, media.taken_at_granularity
195
+
196
+ # Location
197
+ assert_equal 45.807258, media.location.latitude
198
+ assert_equal 15.967599, media.location.longitude
199
+ assert_equal '11', media.location.accuracy
200
+ assert_equal '0', media.location.context.to_s
201
+ assert_equal '00j4IylZV7scWik', media.location.place_id
202
+ assert_equal '851128', media.location.woeid
203
+ assert_equal true, media.geo_permissions.public?
204
+ assert_equal false, media.geo_permissions.contacts?
205
+ assert_equal false, media.geo_permissions.friends?
206
+ assert_equal false, media.geo_permissions.family?
207
+
208
+ # Owner
209
+ assert_equal '67131352@N04', media.owner.nsid
210
+ assert_equal 'Janko Marohnić', media.owner.username
211
+ assert_equal '5464', media.owner.icon_server
212
+ assert_equal 6, media.owner.icon_farm
213
+ refute media.owner.buddy_icon_url.empty?
287
214
 
288
- def test_delete_media
289
- media_path = File.join(File.expand_path(File.dirname(__FILE__)), 'photo.jpg')
290
- media_id = Flickrie.upload(media_path)
291
- assert_includes Flickrie.public_media_from_user(@user_nsid).map(&:id), media_id
292
- Flickrie.delete_media(media_id)
293
- refute_includes Flickrie.public_media_from_user(@user_nsid).map(&:id), media_id
215
+ # Visibility (This is the difference from Flickrie.media_from_set)
216
+ assert_equal true, media.visibility.public?
217
+ assert_equal false, media.visibility.friends?
218
+ assert_equal false, media.visibility.family?
219
+ assert_equal nil, media.visibility.contacts?
220
+ end
294
221
  end
295
222
 
296
- def test_media_from_contacts
297
- medias = [
298
- Flickrie.media_from_contacts(
299
- :include_self => 1, :single_photo => 1, :extras => @all_extras).first,
300
- Flickrie.public_media_from_user_contacts(@user_nsid,
301
- :include_self => 1, :single_photo => 1, :extras => @all_extras).first
302
- ]
303
-
304
- medias.each do |media|
305
- assert_equal '7093101501', media.id
306
- assert_equal '9337f28800', media.secret
307
- assert_equal '7090', media.server
223
+ def test_search
224
+ VCR.use_cassette 'media/search' do
225
+ media = Flickrie.search_media(:user_id => @user_nsid, :extras => @all_extras).
226
+ find { |media| media.id.to_i == @media_id }
227
+
228
+ assert_equal '6946979188', media.id
229
+ assert_equal '25bb44852b', media.secret
230
+ assert_equal '7049', media.server
308
231
  assert_equal 8, media.farm
309
- assert_equal 'IMG_0917', media.title
310
- assert_equal '', media.tags.join(' ')
232
+ assert_equal 'IMG_0796', media.title
233
+ assert_equal 'luka', media.tags.join(' ')
311
234
  assert_equal '', media.machine_tags.join(' ')
312
- assert_equal 0, media.views_count
235
+ assert_equal 2, media.views_count
313
236
  assert_equal '0', media.license.id
314
237
  assert_not_nil media.url
315
238
  assert_equal 'ready', media.media_status
@@ -321,7 +244,16 @@ class MediaTest < Test::Unit::TestCase
321
244
  assert_equal 0, media.taken_at_granularity
322
245
 
323
246
  # Location
324
- assert_nil media.location
247
+ assert_equal 45.807258, media.location.latitude
248
+ assert_equal 15.967599, media.location.longitude
249
+ assert_equal '11', media.location.accuracy
250
+ assert_equal '0', media.location.context.to_s
251
+ assert_equal '00j4IylZV7scWik', media.location.place_id
252
+ assert_equal '851128', media.location.woeid
253
+ assert_equal true, media.geo_permissions.public?
254
+ assert_equal false, media.geo_permissions.contacts?
255
+ assert_equal false, media.geo_permissions.friends?
256
+ assert_equal false, media.geo_permissions.family?
325
257
 
326
258
  # Owner
327
259
  assert_equal '67131352@N04', media.owner.nsid
@@ -338,42 +270,118 @@ class MediaTest < Test::Unit::TestCase
338
270
  end
339
271
  end
340
272
 
341
- def test_get_media_context
342
- context = Flickrie.get_media_context(@media_id)
343
-
344
- assert_equal 98, context['count']
345
-
346
- previous_media = context['prevphoto']
347
- assert_equal '6946978706', previous_media.id
348
- assert_equal 'b38270bbd6', previous_media.secret
349
- assert_equal '7216', previous_media.server
350
- assert_equal 8, previous_media.farm
351
- assert_equal 'IMG_0795', previous_media.title
352
- refute previous_media.url.empty?
353
- assert_equal '0', previous_media.license.id
354
- assert_equal false, previous_media.faved?
355
-
356
- next_media = context['nextphoto']
357
- assert_equal '6946979704', next_media.id
358
- assert_equal '74513ff732', next_media.secret
359
- assert_equal '7234', next_media.server
360
- assert_equal 8, next_media.farm
361
- assert_equal 'IMG_0797', next_media.title
362
- refute next_media.url.empty?
363
- assert_equal '0', next_media.license.id
364
- assert_equal false, next_media.faved?
273
+ def test_tags
274
+ VCR.use_cassette 'media/tags' do
275
+ media = Flickrie.get_media_info(@media_id)
276
+ tags_before_change = media.tags.join(' ')
277
+ Flickrie.add_media_tags(@media_id, "janko")
278
+ media.get_info
279
+ assert_equal [tags_before_change, "janko"].join(' '),
280
+ media.tags.join(' ')
281
+ tag_id = media.tags.find { |tag| tag.content == "janko" }.id
282
+ Flickrie.remove_media_tag(tag_id)
283
+ media.get_info
284
+ assert_equal tags_before_change, media.tags.join(' ')
285
+ end
365
286
  end
366
287
 
367
- def test_media_replace
368
- media_path = File.join(File.expand_path(File.dirname(__FILE__)), 'photo.jpg')
369
- begin
288
+ def test_delete
289
+ VCR.use_cassette 'media/delete' do
290
+ media_path = File.join(File.expand_path(File.dirname(__FILE__)), 'photo.jpg')
370
291
  media_id = Flickrie.upload(media_path)
371
- Flickrie.replace(media_path, media_id)
372
- flunk
373
- rescue => exception
374
- assert_equal "Not a pro account", exception.message
375
- ensure
292
+ assert_includes Flickrie.public_media_from_user(@user_nsid).map(&:id), media_id
376
293
  Flickrie.delete_media(media_id)
294
+ refute_includes Flickrie.public_media_from_user(@user_nsid).map(&:id), media_id
295
+ end
296
+ end
297
+
298
+ def test_from_contacts
299
+ VCR.use_cassette 'media/from_contacts' do
300
+ medias = [
301
+ Flickrie.media_from_contacts(
302
+ :include_self => 1, :single_photo => 1, :extras => @all_extras).first,
303
+ Flickrie.public_media_from_user_contacts(@user_nsid,
304
+ :include_self => 1, :single_photo => 1, :extras => @all_extras).first
305
+ ]
306
+
307
+ medias.each do |media|
308
+ assert_equal '7093101501', media.id
309
+ assert_equal '9337f28800', media.secret
310
+ assert_equal '7090', media.server
311
+ assert_equal 8, media.farm
312
+ assert_equal 'IMG_0917', media.title
313
+ assert_equal '', media.tags.join(' ')
314
+ assert_equal '', media.machine_tags.join(' ')
315
+ assert_equal 0, media.views_count
316
+ assert_equal '0', media.license.id
317
+ assert_not_nil media.url
318
+ assert_equal 'ready', media.media_status
319
+
320
+ # Time
321
+ assert_instance_of Time, media.uploaded_at
322
+ assert_instance_of Time, media.updated_at
323
+ assert_instance_of Time, media.taken_at
324
+ assert_equal 0, media.taken_at_granularity
325
+
326
+ # Location
327
+ assert_nil media.location
328
+
329
+ # Owner
330
+ assert_equal '67131352@N04', media.owner.nsid
331
+ assert_equal 'Janko Marohnić', media.owner.username
332
+ assert_equal '5464', media.owner.icon_server
333
+ assert_equal 6, media.owner.icon_farm
334
+ refute media.owner.buddy_icon_url.empty?
335
+
336
+ # Visibility (This is the difference from Flickrie.media_from_set)
337
+ assert_equal true, media.visibility.public?
338
+ assert_equal false, media.visibility.friends?
339
+ assert_equal false, media.visibility.family?
340
+ assert_equal nil, media.visibility.contacts?
341
+ end
342
+ end
343
+ end
344
+
345
+ def test_get_context
346
+ VCR.use_cassette 'media/get_context' do
347
+ context = Flickrie.get_media_context(@media_id)
348
+
349
+ assert_equal 98, context['count']
350
+
351
+ previous_media = context['prevphoto']
352
+ assert_equal '6946978706', previous_media.id
353
+ assert_equal 'b38270bbd6', previous_media.secret
354
+ assert_equal '7216', previous_media.server
355
+ assert_equal 8, previous_media.farm
356
+ assert_equal 'IMG_0795', previous_media.title
357
+ refute previous_media.url.empty?
358
+ assert_equal '0', previous_media.license.id
359
+ assert_equal false, previous_media.faved?
360
+
361
+ next_media = context['nextphoto']
362
+ assert_equal '6946979704', next_media.id
363
+ assert_equal '74513ff732', next_media.secret
364
+ assert_equal '7234', next_media.server
365
+ assert_equal 8, next_media.farm
366
+ assert_equal 'IMG_0797', next_media.title
367
+ refute next_media.url.empty?
368
+ assert_equal '0', next_media.license.id
369
+ assert_equal false, next_media.faved?
370
+ end
371
+ end
372
+
373
+ def test_replace
374
+ VCR.use_cassette 'media/replace' do
375
+ media_path = File.join(File.expand_path(File.dirname(__FILE__)), 'photo.jpg')
376
+ begin
377
+ media_id = Flickrie.upload(media_path)
378
+ Flickrie.replace(media_path, media_id)
379
+ flunk
380
+ rescue => exception
381
+ assert_equal "Not a pro account", exception.message
382
+ ensure
383
+ Flickrie.delete_media(media_id)
384
+ end
377
385
  end
378
386
  end
379
387