]> gitweb.michael.orlitzky.com - dead/whatever-dl.git/blobdiff - test/vimeo_test.rb
Added the ability to download Vimeo videos.
[dead/whatever-dl.git] / test / vimeo_test.rb
diff --git a/test/vimeo_test.rb b/test/vimeo_test.rb
new file mode 100644 (file)
index 0000000..6578b8c
--- /dev/null
@@ -0,0 +1,123 @@
+#
+# Copyright Michael Orlitzky
+#
+# http://michael.orlitzky.com/
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# http://www.fsf.org/licensing/licenses/gpl.html
+#
+
+require 'test/unit'
+require 'src/websites/vimeo'
+
+# There are no remote tests for Vimeo because they use
+# an expiration timestamp to change certain values in the
+# URL. Obviously, these tests wouldn't pass after the
+# timestamp expired.
+class VimeoTest < Test::Unit::TestCase
+
+  def test_parse_standard_video_id
+    v = Vimeo.new
+    
+    # First form, with the id at the end.
+    video_id = v.send('parse_video_id', 'http://www.vimeo.com/1561578')
+    assert_equal('1561578', video_id)
+  end
+
+
+  def test_parse_swf_video_id
+    v = Vimeo.new
+    
+    # Second, clip_id= form.
+    video_id = v.send('parse_video_id', 'http://www.vimeo.com/moogaloop.swf?clip_id=1561578&server=www.vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1')
+    assert_equal('1561578', video_id)
+  end
+
+  
+  def test_parse_request_signature
+    v = Vimeo.new
+
+    details_data = nil
+
+    File.open('test/fixtures/vimeo/details_data-1561578.xml') do |f|
+      details_data = f.read
+    end
+
+    actual_result = v.send('parse_request_signature', details_data)
+    expected_result = 'db66311d431bedb4ba997a7b1d1946e2'
+    
+    assert_equal(expected_result, actual_result)
+  end
+  
+
+  def test_parse_request_signature_expires
+    v = Vimeo.new
+
+    details_data = nil
+
+    File.open('test/fixtures/vimeo/details_data-1561578.xml') do |f|
+      details_data = f.read
+    end
+
+    actual_result = v.send('parse_request_signature_expires', details_data)
+    expected_result = '1220068800'
+    
+    assert_equal(expected_result, actual_result)
+  end
+
+
+  def test_parse_quality
+    v = Vimeo.new
+
+    details_data = nil
+
+    File.open('test/fixtures/vimeo/details_data-1561578.xml') do |f|
+      details_data = f.read
+    end
+
+    actual_result = v.send('parse_quality', details_data)
+    expected_result = 'sd'
+    
+    assert_equal(expected_result, actual_result)
+  end
+
+  
+  def test_owns_standard_vimeo_url
+    assert(Vimeo.owns_url?('http://www.vimeo.com/1561578'))
+  end
+
+
+  def test_owns_swf_video_url
+    assert(Vimeo.owns_url?('http://www.vimeo.com/moogaloop.swf?clip_id=1561578&server=www.vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1'))
+  end
+
+  
+  def test_doesnt_own_howcast_urls    
+    assert(!Vimeo.owns_url?('http://www.howcast.com/videos/6807-2twr'))
+    assert(!Vimeo.owns_url?('www.howcast.com/videos/6807-2dgfdg'))
+    assert(!Vimeo.owns_url?('http://howcast.com/videos/6807-cse'))
+    assert(!Vimeo.owns_url?('howcast.com/videos/6807-asdgasd'))
+  end
+
+  
+  def test_doesnt_own_redtube_urls
+    assert(!Vimeo.owns_url?('http://www.redtube.com/6807'))
+    assert(!Vimeo.owns_url?('www.redtube.com/6807'))
+    assert(!Vimeo.owns_url?('http://redtube.com/6807'))
+    assert(!Vimeo.owns_url?('redtube.com/6807'))
+  end
+
+  def test_doesnt_own_misc_urls
+    assert(!Vimeo.owns_url?('http://www.howcast.com/abc'))
+  end
+  
+end