skip pixiv-related tests that throw networking errors

This commit is contained in:
Albert Yi
2018-05-14 11:02:22 -07:00
parent 8d5db3723b
commit 8b16934aaa
7 changed files with 143 additions and 101 deletions

View File

@@ -2,44 +2,32 @@ require 'test_helper'
class ArtistsControllerTest < ActionDispatch::IntegrationTest
def assert_artist_found(expected_artist, source_url = nil)
tries = 0
begin
if source_url
get_auth finder_artists_path(format: "json", url: source_url), @user
end
assert_response :success
json = JSON.parse(response.body)
assert_equal(1, json.size, "Testing URL: #{source_url}")
assert_equal(expected_artist, json[0]["name"])
rescue Net::OpenTimeout
tries += 1
if tries == 3
if source_url
get_auth finder_artists_path(format: "json", url: source_url), @user
puts response.body
if response.body =~ /Net::OpenTimeout/
skip "Remote connection to #{source_url} failed"
else
sleep(tries ** 2)
retry
return
end
end
assert_response :success
json = JSON.parse(response.body)
assert_equal(1, json.size, "Testing URL: #{source_url}")
assert_equal(expected_artist, json[0]["name"])
end
def assert_artist_not_found(source_url)
tries = 0
begin
get_auth finder_artists_path(format: "json", url: source_url), @user
assert_response :success
json = JSON.parse(response.body)
assert_equal(0, json.size, "Testing URL: #{source_url}")
rescue Net::OpenTimeout
tries += 1
if tries == 3
skip "Remote connection to #{source_url} failed"
else
sleep(tries ** 2)
retry
end
get_auth finder_artists_path(format: "json", url: source_url), @user
if response.body =~ /Net::OpenTimeout/
skip "Remote connection to #{source_url} failed"
return
end
assert_response :success
json = JSON.parse(response.body)
assert_equal(0, json.size, "Testing URL: #{source_url}")
end
context "An artists controller" do

View File

@@ -4,8 +4,12 @@ class SourcesControllerTest < ActionDispatch::IntegrationTest
context "The sources controller" do
context "show action" do
should "work for a pixiv URL" do
get source_path, params: { url: "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=14901720", format: "json" }
assert_response :success
begin
get source_path, params: { url: "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=14901720", format: "json" }
assert_response :success
rescue Net::OpenTimeout
skip "Remote connection failed to Pixiv failed"
end
end
should "work for a direct twitter URL with referer" do