tests: fix test failures when running without API keys.
Fix the test suite failing when trying to run it in the default state with no config file or API keys configured. Most source sites require API keys or login credentials to be set in order to work. Skip these tests when credentials aren't configured.
This commit is contained in:
@@ -81,6 +81,8 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
context "for a direct link twitter post" do
|
context "for a direct link twitter post" do
|
||||||
setup do
|
setup do
|
||||||
|
skip "Twitter credentials not configured" unless Sources::Strategies::Twitter.enabled?
|
||||||
|
|
||||||
@ref = "https://twitter.com/onsen_musume_jp/status/865534101918330881"
|
@ref = "https://twitter.com/onsen_musume_jp/status/865534101918330881"
|
||||||
@source = "https://pbs.twimg.com/media/DAL-ntWV0AEbhes.jpg:orig"
|
@source = "https://pbs.twimg.com/media/DAL-ntWV0AEbhes.jpg:orig"
|
||||||
end
|
end
|
||||||
@@ -116,6 +118,7 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
context "for a pixiv post" do
|
context "for a pixiv post" do
|
||||||
setup do
|
setup do
|
||||||
|
skip "Pixiv credentials not configured" unless Sources::Strategies::Pixiv.enabled?
|
||||||
@ref = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=49270482"
|
@ref = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=49270482"
|
||||||
@source = "https://i.pximg.net/img-original/img/2015/03/14/17/53/32/49270482_p0.jpg"
|
@source = "https://i.pximg.net/img-original/img/2015/03/14/17/53/32/49270482_p0.jpg"
|
||||||
end
|
end
|
||||||
@@ -253,6 +256,8 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
context "for a 2+ minute long video" do
|
context "for a 2+ minute long video" do
|
||||||
should "allow the upload if the user is an admin" do
|
should "allow the upload if the user is an admin" do
|
||||||
|
skip "Twitter keys are not set" unless Danbooru.config.twitter_api_key
|
||||||
|
|
||||||
@source = "https://twitter.com/7u_NABY/status/1269599527700295681"
|
@source = "https://twitter.com/7u_NABY/status/1269599527700295681"
|
||||||
post_auth uploads_path, create(:admin_user, created_at: 1.week.ago), params: { upload: { tag_string: "aaa", rating: "q", source: @source }}
|
post_auth uploads_path, create(:admin_user, created_at: 1.week.ago), params: { upload: { tag_string: "aaa", rating: "q", source: @source }}
|
||||||
assert_redirected_to Upload.last
|
assert_redirected_to Upload.last
|
||||||
@@ -323,8 +328,8 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
should_upload_successfully("https://nijie.info/view_popup.php?id=213043")
|
should_upload_successfully("https://nijie.info/view_popup.php?id=213043")
|
||||||
should_upload_successfully("https://pic.nijie.net/03/nijie_picture/728995_20170505014820_0.jpg")
|
should_upload_successfully("https://pic.nijie.net/03/nijie_picture/728995_20170505014820_0.jpg")
|
||||||
|
|
||||||
should_upload_successfully("https://pawoo.net/web/statuses/1202176")
|
should_upload_successfully("https://pawoo.net/web/statuses/1202176") if Danbooru.config.pawoo_client_id.present? # XXX
|
||||||
should_upload_successfully("https://img.pawoo.net/media_attachments/files/000/128/953/original/4c0a06087b03343f.png")
|
should_upload_successfully("https://img.pawoo.net/media_attachments/files/000/128/953/original/4c0a06087b03343f.png") if Danbooru.config.pawoo_client_id.present? # XXX
|
||||||
|
|
||||||
should_upload_successfully("https://www.pixiv.net/en/artworks/64476642")
|
should_upload_successfully("https://www.pixiv.net/en/artworks/64476642")
|
||||||
should_upload_successfully("https://i.pximg.net/img-original/img/2017/08/18/00/09/21/64476642_p0.jpg")
|
should_upload_successfully("https://i.pximg.net/img-original/img/2017/08/18/00/09/21/64476642_p0.jpg")
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ module UploadTestHelper
|
|||||||
|
|
||||||
def assert_successful_upload(source_or_file_path, user: @user, **params)
|
def assert_successful_upload(source_or_file_path, user: @user, **params)
|
||||||
if source_or_file_path =~ %r{\Ahttps?://}i
|
if source_or_file_path =~ %r{\Ahttps?://}i
|
||||||
|
return "Login credentials not configured for #{source_or_file_path}" unless Sources::Strategies.find(source_or_file_path).class.enabled?
|
||||||
source = { source: source_or_file_path }
|
source = { source: source_or_file_path }
|
||||||
else
|
else
|
||||||
file = Rack::Test::UploadedFile.new(Rails.root.join(source_or_file_path))
|
file = Rack::Test::UploadedFile.new(Rails.root.join(source_or_file_path))
|
||||||
|
|||||||
@@ -348,6 +348,7 @@ class ArtistTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "find the artist" do
|
should "find the artist" do
|
||||||
|
skip "Nijie credentials not configured" unless Sources::Strategies::Nijie.enabled?
|
||||||
assert_artist_found("evazion", "http://nijie.info/view.php?id=218944")
|
assert_artist_found("evazion", "http://nijie.info/view.php?id=218944")
|
||||||
assert_artist_found("728995", "http://nijie.info/view.php?id=213043")
|
assert_artist_found("728995", "http://nijie.info/view.php?id=213043")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,10 +14,11 @@ class DmailTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "that is spam" do
|
context "that is spam" do
|
||||||
should "be automatically reported and deleted" do
|
should "be automatically reported and deleted" do
|
||||||
|
skip "Rakismet credentials not configured" unless SpamDetector.enabled?
|
||||||
|
|
||||||
@recipient = create(:user)
|
@recipient = create(:user)
|
||||||
@spammer = create(:user, created_at: 2.weeks.ago, email_address: build(:email_address, address: "akismet-guaranteed-spam@example.com"))
|
@spammer = create(:user, created_at: 2.weeks.ago, email_address: build(:email_address, address: "akismet-guaranteed-spam@example.com"))
|
||||||
|
|
||||||
SpamDetector.stubs(:enabled?).returns(true)
|
|
||||||
dmail = create(:dmail, owner: @recipient, from: @spammer, to: @recipient, creator_ip_addr: "127.0.0.1")
|
dmail = create(:dmail, owner: @recipient, from: @spammer, to: @recipient, creator_ip_addr: "127.0.0.1")
|
||||||
|
|
||||||
assert_equal(1, dmail.moderation_reports.count)
|
assert_equal(1, dmail.moderation_reports.count)
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ module Downloads
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "download the full size image instead of the HTML page" do
|
should "download the full size image instead of the HTML page" do
|
||||||
|
skip "Pixiv credentials not configured" unless Sources::Strategies::Pixiv.enabled?
|
||||||
|
|
||||||
assert_rewritten(@p0_full_size_image, @medium_page)
|
assert_rewritten(@p0_full_size_image, @medium_page)
|
||||||
assert_rewritten(@p0_full_size_image, @manga_page)
|
assert_rewritten(@p0_full_size_image, @manga_page)
|
||||||
assert_rewritten(@p1_full_size_image, @manga_big_p1_page)
|
assert_rewritten(@p1_full_size_image, @manga_big_p1_page)
|
||||||
@@ -63,6 +65,8 @@ module Downloads
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "download the full size image instead of the thumbnail" do
|
should "download the full size image instead of the thumbnail" do
|
||||||
|
skip "Pixiv credentials not configured" unless Sources::Strategies::Pixiv.enabled?
|
||||||
|
|
||||||
assert_rewritten(@p0_full_size_image, @p0_large_thumbnail)
|
assert_rewritten(@p0_full_size_image, @p0_large_thumbnail)
|
||||||
assert_rewritten(@p1_full_size_image, @p1_large_thumbnail)
|
assert_rewritten(@p1_full_size_image, @p1_large_thumbnail)
|
||||||
assert_downloaded(@p0_file_size, @p0_large_thumbnail)
|
assert_downloaded(@p0_file_size, @p0_large_thumbnail)
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class IpGeolocationTest < ActiveSupport::TestCase
|
class IpGeolocationTest < ActiveSupport::TestCase
|
||||||
|
setup do
|
||||||
|
skip "IP Registry credentials not configured" unless IpLookup.enabled?
|
||||||
|
end
|
||||||
|
|
||||||
context "IpGeolocation: " do
|
context "IpGeolocation: " do
|
||||||
context "the create_or_update! method" do
|
context "the create_or_update! method" do
|
||||||
should "create a new record if the IP record doesn't already exist" do
|
should "create a new record if the IP record doesn't already exist" do
|
||||||
|
|||||||
@@ -146,6 +146,8 @@ module Sources
|
|||||||
|
|
||||||
context "A deleted or invalid source" do
|
context "A deleted or invalid source" do
|
||||||
setup do
|
setup do
|
||||||
|
skip "Pawoo keys not set" unless Danbooru.config.pawoo_client_id
|
||||||
|
|
||||||
@site1 = Sources::Strategies.find("https://pawoo.net/@nantokakun/105643037682139899") # 404
|
@site1 = Sources::Strategies.find("https://pawoo.net/@nantokakun/105643037682139899") # 404
|
||||||
@site2 = Sources::Strategies.find("https://img.pawoo.net/media_attachments/files/001/297/997/original/c4272a09570757c2.png")
|
@site2 = Sources::Strategies.find("https://img.pawoo.net/media_attachments/files/001/297/997/original/c4272a09570757c2.png")
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ require 'test_helper'
|
|||||||
|
|
||||||
module Sources
|
module Sources
|
||||||
class NicoSeigaTest < ActiveSupport::TestCase
|
class NicoSeigaTest < ActiveSupport::TestCase
|
||||||
|
setup do
|
||||||
|
skip "NicoSeiga credentials not configured" unless Sources::Strategies::NicoSeiga.enabled?
|
||||||
|
end
|
||||||
|
|
||||||
context "The source site for nico seiga" do
|
context "The source site for nico seiga" do
|
||||||
setup do
|
setup do
|
||||||
@site_1 = Sources::Strategies.find("http://lohas.nicoseiga.jp/o/910aecf08e542285862954017f8a33a8c32a8aec/1433298801/4937663")
|
@site_1 = Sources::Strategies.find("http://lohas.nicoseiga.jp/o/910aecf08e542285862954017f8a33a8c32a8aec/1433298801/4937663")
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ require 'test_helper'
|
|||||||
module Sources
|
module Sources
|
||||||
class NijieTest < ActiveSupport::TestCase
|
class NijieTest < ActiveSupport::TestCase
|
||||||
setup do
|
setup do
|
||||||
|
skip "Nijie credentials not configured" unless Sources::Strategies::Nijie.enabled?
|
||||||
# Add a random delay to work around test failures due to rate limiting by Nijie.
|
# Add a random delay to work around test failures due to rate limiting by Nijie.
|
||||||
sleep (3..5).to_a.sample
|
sleep (3..5).to_a.sample
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ require 'test_helper'
|
|||||||
|
|
||||||
module Sources
|
module Sources
|
||||||
class PixivTest < ActiveSupport::TestCase
|
class PixivTest < ActiveSupport::TestCase
|
||||||
|
setup do
|
||||||
|
skip "Pixiv credentials not configured" unless Sources::Strategies::Pixiv.enabled?
|
||||||
|
end
|
||||||
|
|
||||||
def assert_illust_id(illust_id, url)
|
def assert_illust_id(illust_id, url)
|
||||||
site = Sources::Strategies.find(url)
|
site = Sources::Strategies.find(url)
|
||||||
assert_equal(illust_id, site.illust_id)
|
assert_equal(illust_id, site.illust_id)
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "for a pixiv" do
|
context "for a pixiv" do
|
||||||
setup do
|
setup do
|
||||||
|
skip "Pixiv credentials not configured" unless Sources::Strategies::Pixiv.enabled?
|
||||||
|
|
||||||
@source = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350"
|
@source = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247350"
|
||||||
@upload = Upload.new
|
@upload = Upload.new
|
||||||
@upload.source = @source
|
@upload.source = @source
|
||||||
@@ -48,6 +50,8 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "for a pixiv ugoira" do
|
context "for a pixiv ugoira" do
|
||||||
setup do
|
setup do
|
||||||
|
skip "Pixiv credentials not configured" unless Sources::Strategies::Pixiv.enabled?
|
||||||
|
|
||||||
@source = "https://i.pximg.net/img-zip-ugoira/img/2017/04/04/08/57/38/62247364_ugoira1920x1080.zip"
|
@source = "https://i.pximg.net/img-zip-ugoira/img/2017/04/04/08/57/38/62247364_ugoira1920x1080.zip"
|
||||||
@referer = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364"
|
@referer = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364"
|
||||||
@upload = Upload.new
|
@upload = Upload.new
|
||||||
@@ -122,6 +126,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "for twitter" do
|
context "for twitter" do
|
||||||
setup do
|
setup do
|
||||||
|
skip "Twitter credentials not configured" unless Sources::Strategies::Twitter.enabled?
|
||||||
@source = "https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:large"
|
@source = "https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:large"
|
||||||
@ref = "https://twitter.com/nounproject/status/540944400767922176"
|
@ref = "https://twitter.com/nounproject/status/540944400767922176"
|
||||||
end
|
end
|
||||||
@@ -140,6 +145,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "for pixiv" do
|
context "for pixiv" do
|
||||||
setup do
|
setup do
|
||||||
|
skip "Pixiv credentials not configured" unless Sources::Strategies::Pixiv.enabled?
|
||||||
@source = "https://i.pximg.net/img-original/img/2014/10/29/09/27/19/46785915_p0.jpg"
|
@source = "https://i.pximg.net/img-original/img/2014/10/29/09/27/19/46785915_p0.jpg"
|
||||||
@ref = "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=46785915"
|
@ref = "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=46785915"
|
||||||
end
|
end
|
||||||
@@ -159,6 +165,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "for pixiv ugoira" do
|
context "for pixiv ugoira" do
|
||||||
setup do
|
setup do
|
||||||
|
skip "Pixiv credentials not configured" unless Sources::Strategies::Pixiv.enabled?
|
||||||
@source = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364"
|
@source = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -237,6 +244,7 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "#finish!" do
|
context "#finish!" do
|
||||||
setup do
|
setup do
|
||||||
|
skip "Twitter credentials not configured" unless Sources::Strategies::Twitter.enabled?
|
||||||
CurrentUser.user = travel_to(1.month.ago) do
|
CurrentUser.user = travel_to(1.month.ago) do
|
||||||
FactoryBot.create(:user)
|
FactoryBot.create(:user)
|
||||||
end
|
end
|
||||||
@@ -350,6 +358,8 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "for a twitter source replacement" do
|
context "for a twitter source replacement" do
|
||||||
setup do
|
setup do
|
||||||
|
skip "Twitter credentials not configured" unless Sources::Strategies::Twitter.enabled?
|
||||||
|
|
||||||
@new_url = "https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:orig"
|
@new_url = "https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:orig"
|
||||||
|
|
||||||
travel_to(1.month.ago) do
|
travel_to(1.month.ago) do
|
||||||
@@ -516,6 +526,10 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "a post with a pixiv html source" do
|
context "a post with a pixiv html source" do
|
||||||
|
setup do
|
||||||
|
skip "Pixiv credentials not configured" unless Sources::Strategies::Pixiv.enabled?
|
||||||
|
end
|
||||||
|
|
||||||
should "replace with the full size image" do
|
should "replace with the full size image" do
|
||||||
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")
|
||||||
@@ -546,6 +560,8 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
context "a post that is replaced by a ugoira" do
|
context "a post that is replaced by a ugoira" do
|
||||||
should "save the frame data" do
|
should "save the frame data" do
|
||||||
skip unless MediaFile::Ugoira.videos_enabled?
|
skip unless MediaFile::Ugoira.videos_enabled?
|
||||||
|
skip "Pixiv credentials not configured" unless Sources::Strategies::Pixiv.enabled?
|
||||||
|
|
||||||
begin
|
begin
|
||||||
as(@user) { @post.replace!(replacement_url: "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364") }
|
as(@user) { @post.replace!(replacement_url: "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364") }
|
||||||
@post.reload
|
@post.reload
|
||||||
@@ -566,6 +582,8 @@ 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
|
||||||
skip unless MediaFile::Ugoira.videos_enabled?
|
skip unless MediaFile::Ugoira.videos_enabled?
|
||||||
|
skip "Pixiv credentials not configured" unless Sources::Strategies::Pixiv.enabled?
|
||||||
|
|
||||||
@post.unstub(:queue_delete_files)
|
@post.unstub(:queue_delete_files)
|
||||||
|
|
||||||
# this is called thrice to delete the file for 62247364
|
# this is called thrice to delete the file for 62247364
|
||||||
@@ -594,6 +612,8 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "two posts that have had their files swapped" do
|
context "two posts that have had their files swapped" do
|
||||||
setup do
|
setup do
|
||||||
|
skip "Pixiv credentials not configured" unless Sources::Strategies::Pixiv.enabled?
|
||||||
|
|
||||||
as(@user) do
|
as(@user) do
|
||||||
@post1 = FactoryBot.create(:post)
|
@post1 = FactoryBot.create(:post)
|
||||||
@post2 = FactoryBot.create(:post)
|
@post2 = FactoryBot.create(:post)
|
||||||
@@ -636,6 +656,8 @@ class UploadServiceTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
context "a post with notes" do
|
context "a post with notes" do
|
||||||
setup do
|
setup do
|
||||||
|
skip "Pixiv credentials not configured" unless Sources::Strategies::Pixiv.enabled?
|
||||||
|
|
||||||
Note.any_instance.stubs(:merge_version?).returns(false)
|
Note.any_instance.stubs(:merge_version?).returns(false)
|
||||||
|
|
||||||
as(@user) do
|
as(@user) do
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ class UserUpgradeTest < ActiveSupport::TestCase
|
|||||||
context "for a gifted upgrade" do
|
context "for a gifted upgrade" do
|
||||||
context "to Gold" do
|
context "to Gold" do
|
||||||
should "prefill the Stripe checkout page with the purchaser's email address" do
|
should "prefill the Stripe checkout page with the purchaser's email address" do
|
||||||
|
skip "Stripe API keys not configured" unless UserUpgrade.enabled?
|
||||||
|
|
||||||
@user = create(:user, email_address: build(:email_address))
|
@user = create(:user, email_address: build(:email_address))
|
||||||
@user_upgrade = create(:gift_gold_upgrade, purchaser: @user)
|
@user_upgrade = create(:gift_gold_upgrade, purchaser: @user)
|
||||||
@checkout = @user_upgrade.create_checkout!
|
@checkout = @user_upgrade.create_checkout!
|
||||||
|
|||||||
Reference in New Issue
Block a user