From ac12efb63633a06b6f460597febf957779e0bd12 Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 22 Sep 2021 03:49:05 -0500 Subject: [PATCH] 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. --- test/functional/uploads_controller_test.rb | 9 +++++++-- test/test_helpers/upload_test_helper.rb | 1 + test/unit/artist_test.rb | 1 + test/unit/dmail_test.rb | 3 ++- test/unit/downloads/pixiv_test.rb | 4 ++++ test/unit/ip_geolocation_test.rb | 4 ++++ test/unit/sources/mastodon_test.rb | 2 ++ test/unit/sources/nico_seiga_test.rb | 4 ++++ test/unit/sources/nijie_test.rb | 1 + test/unit/sources/pixiv_test.rb | 4 ++++ test/unit/upload_service_test.rb | 22 ++++++++++++++++++++++ test/unit/user_upgrade_test.rb | 2 ++ 12 files changed, 54 insertions(+), 3 deletions(-) diff --git a/test/functional/uploads_controller_test.rb b/test/functional/uploads_controller_test.rb index 59e5d1c6f..34327158d 100644 --- a/test/functional/uploads_controller_test.rb +++ b/test/functional/uploads_controller_test.rb @@ -81,6 +81,8 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest context "for a direct link twitter post" do setup do + skip "Twitter credentials not configured" unless Sources::Strategies::Twitter.enabled? + @ref = "https://twitter.com/onsen_musume_jp/status/865534101918330881" @source = "https://pbs.twimg.com/media/DAL-ntWV0AEbhes.jpg:orig" end @@ -116,6 +118,7 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest context "for a pixiv post" 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" @source = "https://i.pximg.net/img-original/img/2015/03/14/17/53/32/49270482_p0.jpg" end @@ -253,6 +256,8 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest context "for a 2+ minute long video" 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" 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 @@ -323,8 +328,8 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest 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://pawoo.net/web/statuses/1202176") - should_upload_successfully("https://img.pawoo.net/media_attachments/files/000/128/953/original/4c0a06087b03343f.png") + 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") if Danbooru.config.pawoo_client_id.present? # XXX 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") diff --git a/test/test_helpers/upload_test_helper.rb b/test/test_helpers/upload_test_helper.rb index fc05a9989..0e9f37f7a 100644 --- a/test/test_helpers/upload_test_helper.rb +++ b/test/test_helpers/upload_test_helper.rb @@ -16,6 +16,7 @@ module UploadTestHelper def assert_successful_upload(source_or_file_path, user: @user, **params) 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 } else file = Rack::Test::UploadedFile.new(Rails.root.join(source_or_file_path)) diff --git a/test/unit/artist_test.rb b/test/unit/artist_test.rb index 454470845..1b0d91b17 100644 --- a/test/unit/artist_test.rb +++ b/test/unit/artist_test.rb @@ -348,6 +348,7 @@ class ArtistTest < ActiveSupport::TestCase end 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("728995", "http://nijie.info/view.php?id=213043") end diff --git a/test/unit/dmail_test.rb b/test/unit/dmail_test.rb index ec4458e13..156564d32 100644 --- a/test/unit/dmail_test.rb +++ b/test/unit/dmail_test.rb @@ -14,10 +14,11 @@ class DmailTest < ActiveSupport::TestCase context "that is spam" do should "be automatically reported and deleted" do + skip "Rakismet credentials not configured" unless SpamDetector.enabled? + @recipient = create(:user) @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") assert_equal(1, dmail.moderation_reports.count) diff --git a/test/unit/downloads/pixiv_test.rb b/test/unit/downloads/pixiv_test.rb index 11dcf78c2..00248c1d6 100644 --- a/test/unit/downloads/pixiv_test.rb +++ b/test/unit/downloads/pixiv_test.rb @@ -54,6 +54,8 @@ module Downloads end 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, @manga_page) assert_rewritten(@p1_full_size_image, @manga_big_p1_page) @@ -63,6 +65,8 @@ module Downloads end 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(@p1_full_size_image, @p1_large_thumbnail) assert_downloaded(@p0_file_size, @p0_large_thumbnail) diff --git a/test/unit/ip_geolocation_test.rb b/test/unit/ip_geolocation_test.rb index 9235700bb..b71470512 100644 --- a/test/unit/ip_geolocation_test.rb +++ b/test/unit/ip_geolocation_test.rb @@ -1,6 +1,10 @@ require 'test_helper' class IpGeolocationTest < ActiveSupport::TestCase + setup do + skip "IP Registry credentials not configured" unless IpLookup.enabled? + end + context "IpGeolocation: " do context "the create_or_update! method" do should "create a new record if the IP record doesn't already exist" do diff --git a/test/unit/sources/mastodon_test.rb b/test/unit/sources/mastodon_test.rb index 5c1ae8bb6..28cd43d01 100644 --- a/test/unit/sources/mastodon_test.rb +++ b/test/unit/sources/mastodon_test.rb @@ -146,6 +146,8 @@ module Sources context "A deleted or invalid source" do setup do + skip "Pawoo keys not set" unless Danbooru.config.pawoo_client_id + @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") diff --git a/test/unit/sources/nico_seiga_test.rb b/test/unit/sources/nico_seiga_test.rb index fb517076a..303b14b2b 100644 --- a/test/unit/sources/nico_seiga_test.rb +++ b/test/unit/sources/nico_seiga_test.rb @@ -2,6 +2,10 @@ require 'test_helper' module Sources 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 setup do @site_1 = Sources::Strategies.find("http://lohas.nicoseiga.jp/o/910aecf08e542285862954017f8a33a8c32a8aec/1433298801/4937663") diff --git a/test/unit/sources/nijie_test.rb b/test/unit/sources/nijie_test.rb index 2c888adc0..96f1fc373 100644 --- a/test/unit/sources/nijie_test.rb +++ b/test/unit/sources/nijie_test.rb @@ -3,6 +3,7 @@ require 'test_helper' module Sources class NijieTest < ActiveSupport::TestCase 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. sleep (3..5).to_a.sample end diff --git a/test/unit/sources/pixiv_test.rb b/test/unit/sources/pixiv_test.rb index 4cc4ebe8c..87b89f9d9 100644 --- a/test/unit/sources/pixiv_test.rb +++ b/test/unit/sources/pixiv_test.rb @@ -2,6 +2,10 @@ require 'test_helper' module Sources class PixivTest < ActiveSupport::TestCase + setup do + skip "Pixiv credentials not configured" unless Sources::Strategies::Pixiv.enabled? + end + def assert_illust_id(illust_id, url) site = Sources::Strategies.find(url) assert_equal(illust_id, site.illust_id) diff --git a/test/unit/upload_service_test.rb b/test/unit/upload_service_test.rb index f3026d092..e03f7dbe5 100644 --- a/test/unit/upload_service_test.rb +++ b/test/unit/upload_service_test.rb @@ -32,6 +32,8 @@ class UploadServiceTest < ActiveSupport::TestCase context "for a pixiv" 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" @upload = Upload.new @upload.source = @source @@ -48,6 +50,8 @@ class UploadServiceTest < ActiveSupport::TestCase context "for a pixiv ugoira" 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" @referer = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364" @upload = Upload.new @@ -122,6 +126,7 @@ class UploadServiceTest < ActiveSupport::TestCase context "for twitter" do setup do + skip "Twitter credentials not configured" unless Sources::Strategies::Twitter.enabled? @source = "https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:large" @ref = "https://twitter.com/nounproject/status/540944400767922176" end @@ -140,6 +145,7 @@ class UploadServiceTest < ActiveSupport::TestCase context "for pixiv" 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" @ref = "https://www.pixiv.net/member_illust.php?mode=medium&illust_id=46785915" end @@ -159,6 +165,7 @@ class UploadServiceTest < ActiveSupport::TestCase context "for pixiv ugoira" 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" end @@ -237,6 +244,7 @@ class UploadServiceTest < ActiveSupport::TestCase context "#finish!" do setup do + skip "Twitter credentials not configured" unless Sources::Strategies::Twitter.enabled? CurrentUser.user = travel_to(1.month.ago) do FactoryBot.create(:user) end @@ -350,6 +358,8 @@ class UploadServiceTest < ActiveSupport::TestCase context "for a twitter source replacement" do setup do + skip "Twitter credentials not configured" unless Sources::Strategies::Twitter.enabled? + @new_url = "https://pbs.twimg.com/media/B4HSEP5CUAA4xyu.png:orig" travel_to(1.month.ago) do @@ -516,6 +526,10 @@ class UploadServiceTest < ActiveSupport::TestCase end 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 as(@user) do @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 should "save the frame data" do skip unless MediaFile::Ugoira.videos_enabled? + skip "Pixiv credentials not configured" unless Sources::Strategies::Pixiv.enabled? + begin as(@user) { @post.replace!(replacement_url: "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364") } @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 should "not delete the original files" do skip unless MediaFile::Ugoira.videos_enabled? + skip "Pixiv credentials not configured" unless Sources::Strategies::Pixiv.enabled? + @post.unstub(:queue_delete_files) # 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 setup do + skip "Pixiv credentials not configured" unless Sources::Strategies::Pixiv.enabled? + as(@user) do @post1 = FactoryBot.create(:post) @post2 = FactoryBot.create(:post) @@ -636,6 +656,8 @@ class UploadServiceTest < ActiveSupport::TestCase context "a post with notes" do setup do + skip "Pixiv credentials not configured" unless Sources::Strategies::Pixiv.enabled? + Note.any_instance.stubs(:merge_version?).returns(false) as(@user) do diff --git a/test/unit/user_upgrade_test.rb b/test/unit/user_upgrade_test.rb index 99d9ccf96..84b1f7961 100644 --- a/test/unit/user_upgrade_test.rb +++ b/test/unit/user_upgrade_test.rb @@ -44,6 +44,8 @@ class UserUpgradeTest < ActiveSupport::TestCase context "for a gifted upgrade" do context "to Gold" 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_upgrade = create(:gift_gold_upgrade, purchaser: @user) @checkout = @user_upgrade.create_checkout!