2015-07-26 00:02:35 -05:00
|
|
|
require 'minitest/autorun'
|
2015-11-04 13:48:44 -06:00
|
|
|
require 'pry-rescue/minitest' unless ENV["TRAVIS"]
|
2015-07-26 00:02:35 -05:00
|
|
|
require 'wayback_machine_downloader'
|
|
|
|
|
|
2015-08-10 01:14:19 -05:00
|
|
|
class WaybackMachineDownloaderTest < Minitest::Test
|
2015-08-08 16:15:38 -05:00
|
|
|
|
|
|
|
|
def setup
|
|
|
|
|
@wayback_machine_downloader = WaybackMachineDownloader.new base_url: 'http://www.onlyfreegames.net'
|
2015-08-09 22:34:01 -05:00
|
|
|
$stdout = StringIO.new
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
|
FileUtils.rm_rf(@wayback_machine_downloader.backup_path)
|
2015-07-26 00:02:35 -05:00
|
|
|
end
|
2015-08-08 16:15:38 -05:00
|
|
|
|
|
|
|
|
def test_base_url_being_set
|
|
|
|
|
assert_equal 'http://www.onlyfreegames.net', @wayback_machine_downloader.base_url
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_file_list_curated
|
2015-08-09 21:27:14 -05:00
|
|
|
assert_equal 20081120203712, @wayback_machine_downloader.get_file_list_curated["linux.htm"][:timestamp]
|
2015-08-08 16:15:38 -05:00
|
|
|
end
|
|
|
|
|
|
2015-08-15 15:38:29 -05:00
|
|
|
def test_file_list_by_timestamp
|
|
|
|
|
file_expected = {
|
|
|
|
|
file_id: "Fs-06.jpg",
|
|
|
|
|
file_url: "http://www.onlyfreegames.net:80/Fs-06.jpg",
|
|
|
|
|
timestamp: 20060716125343
|
|
|
|
|
}
|
|
|
|
|
assert_equal file_expected, @wayback_machine_downloader.file_list_by_timestamp[-1]
|
|
|
|
|
end
|
|
|
|
|
|
2015-08-08 16:15:38 -05:00
|
|
|
def test_file_download
|
|
|
|
|
@wayback_machine_downloader.download_files
|
2015-08-09 22:34:01 -05:00
|
|
|
linux_page = open 'websites/www.onlyfreegames.net/linux.htm'
|
|
|
|
|
assert_includes linux_page.read, "Linux Games"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_timestamp_being_respected
|
|
|
|
|
@wayback_machine_downloader.timestamp = 20050716231334
|
|
|
|
|
assert_nil @wayback_machine_downloader.get_file_list_curated["linux.htm"]
|
2015-08-08 16:15:38 -05:00
|
|
|
end
|
|
|
|
|
|
2015-07-26 00:02:35 -05:00
|
|
|
end
|