tests: remove unnecessary rescueing of Net::OpenTimeout errors.
These exceptions are no longer thrown now that we've switched from HTTParty to http.rb. Swallowing unexpected exceptions during testing was a bad practice anyway.
This commit is contained in:
@@ -4,11 +4,8 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
def assert_artist_found(expected_artist, source_url = nil)
|
def assert_artist_found(expected_artist, source_url = nil)
|
||||||
if source_url
|
if source_url
|
||||||
get_auth artists_path(format: "json", search: { url_matches: source_url }), @user
|
get_auth artists_path(format: "json", search: { url_matches: source_url }), @user
|
||||||
if response.body =~ /Net::OpenTimeout/
|
|
||||||
skip "Remote connection to #{source_url} failed"
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_response :success
|
assert_response :success
|
||||||
json = JSON.parse(response.body)
|
json = JSON.parse(response.body)
|
||||||
assert_equal(1, json.size, "Testing URL: #{source_url}")
|
assert_equal(1, json.size, "Testing URL: #{source_url}")
|
||||||
@@ -17,10 +14,6 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
def assert_artist_not_found(source_url)
|
def assert_artist_not_found(source_url)
|
||||||
get_auth artists_path(format: "json", search: { url_matches: source_url }), @user
|
get_auth artists_path(format: "json", search: { url_matches: source_url }), @user
|
||||||
if response.body =~ /Net::OpenTimeout/
|
|
||||||
skip "Remote connection to #{source_url} failed"
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
assert_response :success
|
assert_response :success
|
||||||
json = JSON.parse(response.body)
|
json = JSON.parse(response.body)
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ module DownloadTestHelper
|
|||||||
strategy = Sources::Strategies.find(source, referer)
|
strategy = Sources::Strategies.find(source, referer)
|
||||||
file = strategy.download_file!
|
file = strategy.download_file!
|
||||||
assert_equal(expected_filesize, file.size, "Tested source URL: #{source}")
|
assert_equal(expected_filesize, file.size, "Tested source URL: #{source}")
|
||||||
rescue Net::OpenTimeout
|
|
||||||
skip "Remote connection to #{source} failed"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_rewritten(expected_source, test_source, test_referer = nil)
|
def assert_rewritten(expected_source, test_source, test_referer = nil)
|
||||||
|
|||||||
@@ -6,15 +6,11 @@ class ArtistTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
assert_equal(1, artists.size)
|
assert_equal(1, artists.size)
|
||||||
assert_equal(expected_name, artists.first.name, "Testing URL: #{source_url}")
|
assert_equal(expected_name, artists.first.name, "Testing URL: #{source_url}")
|
||||||
rescue Net::OpenTimeout, PixivApiClient::Error
|
|
||||||
skip "Remote connection failed for #{source_url}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_artist_not_found(source_url)
|
def assert_artist_not_found(source_url)
|
||||||
artists = ArtistFinder.find_artists(source_url).to_a
|
artists = ArtistFinder.find_artists(source_url).to_a
|
||||||
assert_equal(0, artists.size, "Testing URL: #{source_url}")
|
assert_equal(0, artists.size, "Testing URL: #{source_url}")
|
||||||
rescue Net::OpenTimeout
|
|
||||||
skip "Remote connection failed for #{source_url}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "An artist" do
|
context "An artist" do
|
||||||
@@ -172,15 +168,11 @@ class ArtistTest < ActiveSupport::TestCase
|
|||||||
a2 = FactoryBot.create(:artist, :name => "subway", :url_string => "http://subway.com/x/test.jpg")
|
a2 = FactoryBot.create(:artist, :name => "subway", :url_string => "http://subway.com/x/test.jpg")
|
||||||
a3 = FactoryBot.create(:artist, :name => "minko", :url_string => "https://minko.com/x/test.jpg")
|
a3 = FactoryBot.create(:artist, :name => "minko", :url_string => "https://minko.com/x/test.jpg")
|
||||||
|
|
||||||
begin
|
|
||||||
assert_artist_found("rembrandt", "http://rembrandt.com/x/test.jpg")
|
assert_artist_found("rembrandt", "http://rembrandt.com/x/test.jpg")
|
||||||
assert_artist_found("rembrandt", "http://rembrandt.com/x/another.jpg")
|
assert_artist_found("rembrandt", "http://rembrandt.com/x/another.jpg")
|
||||||
assert_artist_not_found("http://nonexistent.com/test.jpg")
|
assert_artist_not_found("http://nonexistent.com/test.jpg")
|
||||||
assert_artist_found("minko", "https://minko.com/x/test.jpg")
|
assert_artist_found("minko", "https://minko.com/x/test.jpg")
|
||||||
assert_artist_found("minko", "http://minko.com/x/test.jpg")
|
assert_artist_found("minko", "http://minko.com/x/test.jpg")
|
||||||
rescue Net::OpenTimeout
|
|
||||||
skip "network failure"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "be case-insensitive to domains when finding matches by url" do
|
should "be case-insensitive to domains when finding matches by url" do
|
||||||
|
|||||||
@@ -15,10 +15,7 @@ module Sources
|
|||||||
|
|
||||||
def get_source(source)
|
def get_source(source)
|
||||||
@site = Sources::Strategies.find(source)
|
@site = Sources::Strategies.find(source)
|
||||||
|
|
||||||
@site
|
@site
|
||||||
rescue Net::OpenTimeout
|
|
||||||
skip "Remote connection to #{source} failed"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "in all cases" do
|
context "in all cases" do
|
||||||
|
|||||||
@@ -131,12 +131,9 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "download the file" do
|
should "download the file" do
|
||||||
begin
|
|
||||||
@service = UploadService::Preprocessor.new(source: @source, referer_url: @ref)
|
@service = UploadService::Preprocessor.new(source: @source, referer_url: @ref)
|
||||||
@upload = @service.start!
|
@upload = @service.start!
|
||||||
rescue Net::OpenTimeout
|
|
||||||
skip "network failure"
|
|
||||||
end
|
|
||||||
assert_equal("preprocessed", @upload.status)
|
assert_equal("preprocessed", @upload.status)
|
||||||
assert_equal(294591, @upload.file_size)
|
assert_equal(294591, @upload.file_size)
|
||||||
assert_equal("jpg", @upload.file_ext)
|
assert_equal("jpg", @upload.file_ext)
|
||||||
@@ -155,11 +152,8 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
skip unless MediaFile::Ugoira.videos_enabled?
|
skip unless MediaFile::Ugoira.videos_enabled?
|
||||||
|
|
||||||
@service = UploadService::Preprocessor.new(source: @source)
|
@service = UploadService::Preprocessor.new(source: @source)
|
||||||
begin
|
|
||||||
@upload = @service.start!
|
@upload = @service.start!
|
||||||
rescue Net::OpenTimeout
|
|
||||||
skip "network problems"
|
|
||||||
end
|
|
||||||
assert_equal("preprocessed", @upload.status)
|
assert_equal("preprocessed", @upload.status)
|
||||||
assert_equal(2804, @upload.file_size)
|
assert_equal(2804, @upload.file_size)
|
||||||
assert_equal("zip", @upload.file_ext)
|
assert_equal("zip", @upload.file_ext)
|
||||||
@@ -176,11 +170,8 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
should "download the file" do
|
should "download the file" do
|
||||||
@service = UploadService::Preprocessor.new(source: @source)
|
@service = UploadService::Preprocessor.new(source: @source)
|
||||||
begin
|
|
||||||
@upload = @service.start!
|
@upload = @service.start!
|
||||||
rescue Net::OpenTimeout
|
|
||||||
skip "network problems"
|
|
||||||
end
|
|
||||||
assert_equal("preprocessed", @upload.status)
|
assert_equal("preprocessed", @upload.status)
|
||||||
assert_equal(181309, @upload.file_size)
|
assert_equal(181309, @upload.file_size)
|
||||||
assert_equal("jpg", @upload.file_ext)
|
assert_equal("jpg", @upload.file_ext)
|
||||||
@@ -512,7 +503,6 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "a post with a pixiv html source" do
|
context "a post with a pixiv html source" do
|
||||||
should "replace with the full size image" do
|
should "replace with the full size image" do
|
||||||
begin
|
|
||||||
as(@user) do
|
as(@user) do
|
||||||
@post.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350")
|
@post.replace!(replacement_url: "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350")
|
||||||
end
|
end
|
||||||
@@ -525,13 +515,9 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
assert_equal("4ceadc314938bc27f3574053a3e1459a", Digest::MD5.file(@post.file).hexdigest)
|
assert_equal("4ceadc314938bc27f3574053a3e1459a", Digest::MD5.file(@post.file).hexdigest)
|
||||||
assert_equal("https://i.pximg.net/img-original/img/2017/04/04/08/54/15/62247350_p0.png", @post.replacements.last.replacement_url)
|
assert_equal("https://i.pximg.net/img-original/img/2017/04/04/08/54/15/62247350_p0.png", @post.replacements.last.replacement_url)
|
||||||
assert_equal("https://i.pximg.net/img-original/img/2017/04/04/08/54/15/62247350_p0.png", @post.source)
|
assert_equal("https://i.pximg.net/img-original/img/2017/04/04/08/54/15/62247350_p0.png", @post.source)
|
||||||
rescue Net::OpenTimeout
|
|
||||||
skip "Remote connection to Pixiv failed"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "delete the old files after thirty days" do
|
should "delete the old files after thirty days" do
|
||||||
begin
|
|
||||||
@post.unstub(:queue_delete_files)
|
@post.unstub(:queue_delete_files)
|
||||||
FileUtils.expects(:rm_f).times(3)
|
FileUtils.expects(:rm_f).times(3)
|
||||||
|
|
||||||
@@ -540,9 +526,6 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
travel_to((PostReplacement::DELETION_GRACE_PERIOD + 1).days.from_now) do
|
travel_to((PostReplacement::DELETION_GRACE_PERIOD + 1).days.from_now) do
|
||||||
perform_enqueued_jobs
|
perform_enqueued_jobs
|
||||||
end
|
end
|
||||||
rescue Net::OpenTimeout
|
|
||||||
skip "Remote connection to Pixiv failed"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -568,7 +551,6 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "a post that is replaced to another file then replaced back to the original file" do
|
context "a post that is replaced to another file then replaced back to the original file" do
|
||||||
should "not delete the original files" do
|
should "not delete the original files" do
|
||||||
begin
|
|
||||||
skip unless MediaFile::Ugoira.videos_enabled?
|
skip unless MediaFile::Ugoira.videos_enabled?
|
||||||
@post.unstub(:queue_delete_files)
|
@post.unstub(:queue_delete_files)
|
||||||
|
|
||||||
@@ -593,9 +575,6 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
assert_nothing_raised { @post.file(:original) }
|
assert_nothing_raised { @post.file(:original) }
|
||||||
assert_nothing_raised { @post.file(:preview) }
|
assert_nothing_raised { @post.file(:preview) }
|
||||||
rescue Net::OpenTimeout
|
|
||||||
skip "Remote connection to Pixiv failed"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -609,7 +588,6 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
should "not delete the still active files" do
|
should "not delete the still active files" do
|
||||||
# swap the images between @post1 and @post2.
|
# swap the images between @post1 and @post2.
|
||||||
begin
|
|
||||||
as(@user) do
|
as(@user) do
|
||||||
skip unless MediaFile::Ugoira.videos_enabled?
|
skip unless MediaFile::Ugoira.videos_enabled?
|
||||||
|
|
||||||
@@ -639,9 +617,6 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
assert_nothing_raised { @post1.file(:original) }
|
assert_nothing_raised { @post1.file(:original) }
|
||||||
assert_nothing_raised { @post2.file(:original) }
|
assert_nothing_raised { @post2.file(:original) }
|
||||||
rescue Net::OpenTimeout
|
|
||||||
skip "Remote connection to Pixiv failed"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -885,12 +860,8 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "record the canonical source" do
|
should "record the canonical source" do
|
||||||
begin
|
|
||||||
post = subject.new({}).create_post_from_upload(@upload)
|
post = subject.new({}).create_post_from_upload(@upload)
|
||||||
assert_equal(@source, post.source)
|
assert_equal(@source, post.source)
|
||||||
rescue Net::OpenTimeout
|
|
||||||
skip "network failure"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user