forked from kylejginavan/youtube_it
/
test_video_feed_parser.rb
262 lines (222 loc) · 6.63 KB
/
test_video_feed_parser.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
require File.expand_path(File.dirname(__FILE__) + '/helper')
class TestVideoFeedParser < Test::Unit::TestCase
# VIDEO ATTRIBUTES AFFECTED BY PARSING
def test_should_display_unique_id_correctly_after_parsing
with_video_response do |parser|
video = parser.parse
assert_equal "AbC123DeFgH", video.unique_id
end
end
# PARSED VIDEO ATTRIBUTES
def test_should_parse_duration_correctly
with_video_response do |parser|
video = parser.parse
assert_equal 356, video.duration
end
end
def test_should_parse_widescreen_correctly
with_video_response do |parser|
video = parser.parse
assert_equal true, video.widescreen?
end
end
def test_should_parse_noembed_correctly
with_video_response do |parser|
video = parser.parse
assert_equal false, video.noembed
end
end
def test_should_parse_racy_correctly
with_video_response do |parser|
video = parser.parse
assert_equal false, video.racy
end
end
def test_should_parse_video_id_correctly
with_video_response do |parser|
video = parser.parse
assert_equal "tag:youtube.com,2008:video:AbC123DeFgH", video.video_id
end
end
def test_should_parse_published_at_correctly
with_video_response do |parser|
video = parser.parse
assert_equal Time.parse("Wed Dec 29 13:57:49 UTC 2010"), video.published_at
end
end
def test_should_parse_updated_at_correctly
with_video_response do |parser|
video = parser.parse
assert_equal Time.parse("Wed Feb 23 13:54:16 UTC 2011"), video.updated_at
end
end
def test_should_parse_categories_correctly
with_video_response do |parser|
video = parser.parse
assert_equal "Test", video.categories.first.label
assert_equal "Test", video.categories.first.term
end
end
def test_should_parse_keywords_correctly
with_video_response do |parser|
video = parser.parse
assert_equal ["test"], video.keywords
end
end
def test_should_parse_description_correctly
with_video_response do |parser|
video = parser.parse
assert_equal "Youtube Test Video", video.description
end
end
def test_should_parse_title_correctly
with_video_response do |parser|
video = parser.parse
assert_equal "YouTube Test Video", video.title
end
end
def test_should_parse_html_content_correctly
with_video_response do |parser|
video = parser.parse
assert_equal nil, video.html_content
end
end
def test_should_parse_thumbnails_correctly
with_video_response do |parser|
video = parser.parse
thumbnail = video.thumbnails.first
assert_equal 90, thumbnail.height
assert_equal "00:02:58", thumbnail.time
assert_equal "http://i.ytimg.com/vi/AbC123DeFgH/default.jpg", thumbnail.url
assert_equal 120, thumbnail.width
end
end
def test_should_parse_player_url_correctly
with_video_response do |parser|
video = parser.parse
assert_equal "http://www.youtube.com/watch?v=AbC123DeFgH&feature=youtube_gdata_player", video.player_url
end
end
def test_should_parse_view_count_correctly
with_video_response do |parser|
video = parser.parse
assert_equal 240000, video.view_count
end
end
def test_should_parse_favorite_count_correctly
with_video_response do |parser|
video = parser.parse
assert_equal 200, video.favorite_count
end
end
# RATING
def test_should_parse_average_correctly
with_video_response do |parser|
video = parser.parse
assert_equal 4.305027, video.rating.average
end
end
def test_should_parse_max_correctly
with_video_response do |parser|
video = parser.parse
assert_equal 5, video.rating.max
end
end
def test_should_parse_min_correctly
with_video_response do |parser|
video = parser.parse
assert_equal 1, video.rating.min
end
end
def test_should_parse_rater_count_correctly
with_video_response do |parser|
video = parser.parse
assert_equal 2049, video.rating.rater_count
end
end
def test_should_parse_likes_correctly
with_video_response do |parser|
video = parser.parse
assert_equal 1700, video.rating.likes
end
end
def test_should_parse_dislikes_correctly
with_video_response do |parser|
video = parser.parse
assert_equal 350, video.rating.dislikes
end
end
# TOD: GEODATA
def test_should_parse_where_geodata_correctly
with_video_response do |parser|
video = parser.parse
assert_equal nil, video.where
end
end
def test_should_parse_position_geodata_correctly
with_video_response do |parser|
video = parser.parse
assert_equal nil, video.position
end
end
def test_should_parse_latitude_geodata_correctly
with_video_response do |parser|
video = parser.parse
assert_equal nil, video.latitude
end
end
def test_should_parse_longitude_geodata_correctly
with_video_response do |parser|
video = parser.parse
assert_equal nil, video.longitude
end
end
# AUTHOR
def test_should_parse_author_name_correctly
with_video_response do |parser|
video = parser.parse
assert_equal "Test user", video.author.name
end
end
def test_should_parse_author_uri_correctly
with_video_response do |parser|
video = parser.parse
assert_equal "http://gdata.youtube.com/feeds/api/users/test_user", video.author.uri
end
end
# MEDIA CONTENT
def test_should_parse_if_media_content_is_default_content_correctly
with_video_response do |parser|
video = parser.parse
content = video.media_content.first
assert_equal true, content.default
end
end
def test_should_parse_duration_of_media_contents_correctly
with_video_response do |parser|
video = parser.parse
content = video.media_content.first
assert_equal 356, content.duration
end
end
def test_should_parse_mime_type_of_media_content_correctly
with_video_response do |parser|
video = parser.parse
content = video.media_content.first
assert_equal "application/x-shockwave-flash", content.mime_type
end
end
def test_should_parse_url_of_media_content_correctly
with_video_response do |parser|
video = parser.parse
content = video.media_content.first
assert_equal "http://www.youtube.com/v/AbC123DeFgH?f=videos&app=youtube_gdata", content.url
end
end
def with_video_response &block
File.open(File.dirname(__FILE__) + '/files/youtube_video_response.xml') do |xml|
parser = YouTubeIt::Parser::VideoFeedParser.new xml.read
yield parser
end
end
end