# # 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/efukt' class EfuktTest < Test::Unit::TestCase def test_owns_efukt_urls assert(Efukt.owns_url?('http://www.efukt.com/2308_How_To_Fuck_Like_A_King.html')) assert(Efukt.owns_url?('http://www.efukt.com/2304_The_Dumbest_Porno_Ever_Made.html')) end def test_doesnt_own_infoq_urls assert(!Efukt.owns_url?('http://www.infoq.com/interviews/jim-weirich-discusses-rake')) end def test_get_video_filename_works_on_good_urls ef = Efukt.new('http://www.efukt.com/2308_How_To_Fuck_Like_A_King.html') expected_filename = '2308_How_To_Fuck_Like_A_King.flv' actual_filename = ef.get_video_filename() assert_equal(expected_filename, actual_filename) end def test_get_video_filename_works_on_weird_urls # The regex looks for an html extension, so this should # not match. Instead, it should fall back on everything # between the final slash and that last period. In this # case, the filename should be the same as if the extension # were html. ef = Efukt.new('http://www.efukt.com/2308_How_To_Fuck_Like_A_King.broken') expected_filename = '2308_How_To_Fuck_Like_A_King.flv' actual_filename = ef.get_video_filename() assert_equal(expected_filename, actual_filename) end def test_parse_video_url ef = Efukt.new(nil) page_data = nil File.open('test/fixtures/efukt/2304_The_Dumbest_Porno_Ever_Made.html') do |f| page_data = f.read end test_result = ef.send('parse_video_url', page_data) assert_equal('http://64.62.222.195/video/370c4a4662071261ccd5b833c4d83201/4918d88d/63563562.flv', test_result) # There are two different filename patterns. # This tests the second one. No, there aren't # any non-embarrasing videos on eFukt that I could # use for fixtures. File.open('test/fixtures/efukt/1592_Riding_Bear_Back.html') do |f| page_data = f.read end test_result = ef.send('parse_video_url', page_data) assert_equal('http://74.82.53.202/video/798309ad4e6b598204aae617bbdf3090/4a99e23f/158.wmv', test_result) end end