]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/blob - test/youtube_test.rb
Added the ability to download Youtube videos.
[dead/whatever-dl.git] / test / youtube_test.rb
1 #
2 # Copyright Michael Orlitzky
3 #
4 # http://michael.orlitzky.com/
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # http://www.fsf.org/licensing/licenses/gpl.html
17 #
18
19 require 'test/unit'
20 require 'src/websites/youtube'
21
22 class YoutubeTest < Test::Unit::TestCase
23
24 def test_owns_youtube_urls
25 assert(Youtube.owns_url?('http://www.youtube.com/watch?v=SudixyugiX4'))
26 assert(Youtube.owns_url?('http://www.youtube.com/watch?v=SudixyugiX4&hl=en'))
27 assert(Youtube.owns_url?('http://youtube.com/watch?v=SudixyugiX4&hl=en'))
28 assert(Youtube.owns_url?('http://www.youtube.com/v/SudixyugiX4'))
29 assert(Youtube.owns_url?('http://www.youtube.com/v/SudixyugiX4&hl=en'))
30 assert(Youtube.owns_url?('http://youtube.com/v/SudixyugiX4&hl=en'))
31 end
32
33
34 def test_doesnt_own_redtube_urls
35 assert(!Youtube.owns_url?('http://www.redtube.com/6807'))
36 assert(!Youtube.owns_url?('www.redtube.com/6807'))
37 assert(!Youtube.owns_url?('http://redtube.com/6807'))
38 assert(!Youtube.owns_url?('redtube.com/6807'))
39 end
40
41
42 def test_parse_video_id
43 yt = Youtube.new()
44 expected_result = 'SudixyugiX4'
45 actual_result = yt.send('parse_video_id', 'http://www.youtube.com/watch?v=SudixyugiX4')
46 assert_equal(expected_result, actual_result)
47 end
48
49
50 def test_parse_t_parameter
51 yt = Youtube.new()
52
53 page_data = nil
54
55 File.open('test/fixtures/youtube/SudixyugiX4.html') do |f|
56 page_data = f.read
57 end
58
59 expected_result = 'OEgsToPDskLQUAntWWpzhEMhBMlgqHdo'
60 actual_result = yt.send('parse_t_parameter', page_data)
61 assert_equal(expected_result, actual_result)
62 end
63
64 end