]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/blob - test/youtube_test.rb
b5de6a8ca348babc7bc1a1850bed09f7d3b58089
[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 assert(Youtube.owns_url?('http://www.youtube.com/watch?v=K9iDMcmm0tE'))
32 assert(Youtube.owns_url?('http://www.youtube.com/watch?v=K9iDMcmm0tE#'))
33 assert(Youtube.owns_url?('http://www.youtube.com/v/K9iDMcmm0tE'))
34 end
35
36
37 def test_doesnt_own_redtube_urls
38 assert(!Youtube.owns_url?('http://www.redtube.com/6807'))
39 assert(!Youtube.owns_url?('www.redtube.com/6807'))
40 assert(!Youtube.owns_url?('http://redtube.com/6807'))
41 assert(!Youtube.owns_url?('redtube.com/6807'))
42 end
43
44
45 def test_parse_video_id
46 yt = Youtube.new()
47 expected_result = 'SudixyugiX4'
48 actual_result = yt.send('parse_video_id', 'http://www.youtube.com/watch?v=SudixyugiX4')
49 assert_equal(expected_result, actual_result)
50 end
51
52
53 def test_parse_video_id_again
54 yt = Youtube.new()
55 expected_result = 'K9iDMcmm0tE'
56 actual_result = yt.send('parse_video_id', 'http://www.youtube.com/watch?v=K9iDMcmm0tE')
57 assert_equal(expected_result, actual_result)
58 end
59
60
61 def test_parse_t_parameter
62 yt = Youtube.new()
63
64 page_data = nil
65
66 File.open('test/fixtures/youtube/SudixyugiX4.html') do |f|
67 page_data = f.read
68 end
69
70 expected_result = 'OEgsToPDskLQUAntWWpzhEMhBMlgqHdo'
71 actual_result = yt.send('parse_t_parameter', page_data)
72 assert_equal(expected_result, actual_result)
73 end
74
75
76 def test_parse_t_parameter_again
77 # This was failing once because my regex missed a hyphen.
78 # I modified the regex to match anything between the pair
79 # of quotes, so it should now catch the hyphen and underscore.
80 yt = Youtube.new()
81
82 page_data = nil
83
84 File.open('test/fixtures/youtube/K9iDMcmm0tE.html') do |f|
85 page_data = f.read
86 end
87
88 expected_result = 'O_EgsToPDskJsXVvAXpAct1zug-lBJBz'
89 actual_result = yt.send('parse_t_parameter', page_data)
90 assert_equal(expected_result, actual_result)
91 end
92
93 end