2015-07-26 00:02:35 -05:00
|
|
|
require 'minitest/autorun'
|
|
|
|
|
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
|
|
|
|
|
|
2016-08-16 11:47:57 -05:00
|
|
|
def test_backup_name_being_set
|
|
|
|
|
assert_equal 'www.onlyfreegames.net', @wayback_machine_downloader.backup_name
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_backup_name_being_set_when_base_url_is_domain
|
|
|
|
|
@wayback_machine_downloader.base_url = 'www.onlyfreegames.net'
|
|
|
|
|
assert_equal 'www.onlyfreegames.net', @wayback_machine_downloader.backup_name
|
|
|
|
|
end
|
|
|
|
|
|
2015-08-08 16:15:38 -05:00
|
|
|
def test_file_list_curated
|
2016-09-26 10:35:38 -07:00
|
|
|
assert_equal 20060711191226, @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 = {
|
2016-09-26 10:51:02 -07:00
|
|
|
file_url: "http://www.onlyfreegames.net:80/strat.html",
|
|
|
|
|
timestamp: 20060111084756,
|
|
|
|
|
file_id: "strat.html"
|
2015-08-15 15:38:29 -05:00
|
|
|
}
|
2016-09-26 10:51:02 -07:00
|
|
|
assert_equal file_expected, @wayback_machine_downloader.get_file_list_by_timestamp[-2]
|
2015-08-15 15:38:29 -05:00
|
|
|
end
|
|
|
|
|
|
2015-11-19 15:28:50 -06:00
|
|
|
def test_file_list_only_filter_without_matches
|
|
|
|
|
@wayback_machine_downloader.only_filter = 'abc123'
|
|
|
|
|
assert_equal 0, @wayback_machine_downloader.get_file_list_curated.size
|
2015-11-06 13:11:26 -05:00
|
|
|
end
|
|
|
|
|
|
2015-11-19 15:28:50 -06:00
|
|
|
def test_file_list_only_filter_with_1_match
|
|
|
|
|
@wayback_machine_downloader.only_filter = 'menu.html'
|
|
|
|
|
assert_equal 1, @wayback_machine_downloader.get_file_list_curated.size
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_file_list_only_filter_with_a_regex
|
|
|
|
|
@wayback_machine_downloader.only_filter = '/\.(gif|je?pg|bmp)$/i'
|
|
|
|
|
assert_equal 37, @wayback_machine_downloader.get_file_list_curated.size
|
2015-11-06 13:11:26 -05:00
|
|
|
end
|
|
|
|
|
|
2016-07-28 18:00:18 -05:00
|
|
|
def test_file_list_exclude_filter_without_matches
|
|
|
|
|
@wayback_machine_downloader.exclude_filter = 'abc123'
|
2016-07-30 14:09:46 -05:00
|
|
|
assert_equal 68, @wayback_machine_downloader.get_file_list_curated.size
|
2016-07-28 18:00:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_file_list_exclude_filter_with_1_match
|
|
|
|
|
@wayback_machine_downloader.exclude_filter = 'menu.html'
|
2016-07-30 14:09:46 -05:00
|
|
|
assert_equal 67, @wayback_machine_downloader.get_file_list_curated.size
|
2016-07-28 18:00:18 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_file_list_exclude_filter_with_a_regex
|
|
|
|
|
@wayback_machine_downloader.exclude_filter = '/\.(gif|je?pg|bmp)$/i'
|
2016-07-30 14:09:46 -05:00
|
|
|
assert_equal 31, @wayback_machine_downloader.get_file_list_curated.size
|
2016-07-28 18:00:18 -05:00
|
|
|
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
|
|
|
|
|
|
2016-07-30 14:09:46 -05:00
|
|
|
def test_from_timestamp_being_respected
|
|
|
|
|
@wayback_machine_downloader.from_timestamp = 20050716231334
|
|
|
|
|
file_url = @wayback_machine_downloader.get_file_list_curated["linux.htm"][:file_url]
|
2016-09-26 10:35:38 -07:00
|
|
|
assert_equal "http://www.onlyfreegames.net:80/linux.htm", file_url
|
2016-07-30 14:09:46 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_to_timestamp_being_respected
|
|
|
|
|
@wayback_machine_downloader.to_timestamp = 20050716231334
|
2015-08-09 22:34:01 -05:00
|
|
|
assert_nil @wayback_machine_downloader.get_file_list_curated["linux.htm"]
|
2015-08-08 16:15:38 -05:00
|
|
|
end
|
|
|
|
|
|
2016-07-31 09:51:27 -05:00
|
|
|
def test_file_list_exclude_filter_with_a_regex
|
|
|
|
|
@wayback_machine_downloader.all = true
|
|
|
|
|
assert_equal 69, @wayback_machine_downloader.get_file_list_curated.size
|
|
|
|
|
end
|
2017-02-15 10:50:12 +00:00
|
|
|
|
|
|
|
|
# Testing encoding conflicts needs a different base_url
|
|
|
|
|
def test_nonascii_suburls_download
|
|
|
|
|
@wayback_machine_downloader = WaybackMachineDownloader.new base_url: 'https://en.wikipedia.org/wiki/%C3%84'
|
2017-02-15 10:58:40 +00:00
|
|
|
# Once just for the downloading...
|
|
|
|
|
@wayback_machine_downloader.download_files
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_nonascii_suburls_already_present
|
|
|
|
|
@wayback_machine_downloader = WaybackMachineDownloader.new base_url: 'https://en.wikipedia.org/wiki/%C3%84'
|
|
|
|
|
# ... twice to test the "is already present" case
|
2017-02-15 10:50:12 +00:00
|
|
|
@wayback_machine_downloader.download_files
|
|
|
|
|
@wayback_machine_downloader.download_files
|
|
|
|
|
end
|
2016-07-31 09:51:27 -05:00
|
|
|
|
2015-07-26 00:02:35 -05:00
|
|
|
end
|