tests: fix broken tests.

* Fix a bug where creating posts failed if IQDB wasn't configured.
* Fix broken Skeb test caused by changed URL.
* Fix broken IP geolocation tests caused by API returning different data.
* Fix broken post regeneration tests.
This commit is contained in:
evazion
2022-01-31 14:14:09 -06:00
parent 65b7c08e33
commit 2bb5ad78fb
4 changed files with 11 additions and 9 deletions

View File

@@ -16,6 +16,10 @@ class IqdbClient
@http = http
end
def enabled?
iqdb_url.present?
end
concerning :QueryMethods do
# Search for an image by file, URL, hash, or post ID.
def search(post_id: nil, media_asset_id: nil, file: nil, hash: nil, url: nil, image_url: nil, file_url: nil, similarity: 0.0, high_similarity: 65.0, limit: 20)
@@ -85,7 +89,7 @@ class IqdbClient
# Add a post to IQDB.
# @param post [Post] the post to add
def add_post(post)
return unless post.has_preview?
return unless enabled? && post.has_preview?
preview_file = post.file(:preview)
add(post.id, preview_file)
end
@@ -125,7 +129,7 @@ class IqdbClient
# @param url [String] the IQDB url
# @param options [Hash] the URL params to send
def request(method, url, **options)
return [] if iqdb_url.blank? # do nothing if iqdb isn't configured
return [] if !enabled?
response = http.timeout(30).send(method, "#{iqdb_url}/#{url}", **options)
raise Error, "IQDB error: #{response.parse}" if response.status != 200
response.parse

View File

@@ -4,8 +4,7 @@ class PostRegenerationsControllerTest < ActionDispatch::IntegrationTest
context "The post regenerations controller" do
setup do
@mod = create(:moderator_user, name: "yukari", created_at: 1.month.ago)
@upload = assert_successful_upload("test/files/test.jpg", user: @mod)
@post = @upload.post
@post = create(:post_with_file, filename: "test.jpg")
perform_enqueued_jobs # add post to iqdb
end
@@ -60,8 +59,7 @@ class PostRegenerationsControllerTest < ActionDispatch::IntegrationTest
end
should "fix the width and height of exif-rotated images" do
@upload = assert_successful_upload("test/files/test-rotation-90cw.jpg", user: @mod)
@post = @upload.post
@post = create(:post_with_file, filename: "test-rotation-90cw.jpg")
post_auth post_regenerations_path, @mod, params: { post_id: @post.id }
perform_enqueued_jobs

View File

@@ -57,13 +57,13 @@ class IpGeolocationTest < ActiveSupport::TestCase
should "work for a proxy IP" do
@ip = IpGeolocation.create_or_update!("31.214.184.59")
assert_equal("Soluciones Corporativas IP, SL", @ip.organization)
assert_match(/Soluciones Corporativas IP, SL/i, @ip.organization.downcase)
assert_equal(true, @ip.is_proxy?)
end
should "work for a cloud hosting IP" do
@ip = IpGeolocation.create_or_update!("157.230.244.215")
assert_equal("DigitalOcean, LLC", @ip.organization)
assert_match(/DigitalOcean, LLC/i, @ip.organization)
assert_equal(true, @ip.is_proxy?)
end

View File

@@ -84,7 +84,7 @@ module Sources
context "A post with a video" do
should "get it correctly" do
site = Sources::Strategies.find("https://skeb.jp/@kaisouafuro/works/112")
assert_equal(site.image_url, "https://skeb-production.s3.ap-northeast-1.amazonaws.com/uploads/outputs/20f9d68f-50ec-44ae-8630-173fc38a2d6a?response-content-disposition=attachment%3B%20filename%3D%22458093-1.output.mp4%22%3B%20filename%2A%3DUTF-8%27%27458093-1.output.mp4&response-content-type=video%2Fmp4&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIVPUTFQBBL7UDSUA%2F20220113%2Fap-northeast-1%2Fs3%2Faws4_request&X-Amz-Date=20220113T141927Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=260c90b0755d894493fef478f806ac3fac0b94f4c8efb3df4f4f2a98309d09f0")
assert_match(%r{\Ahttps://skeb-production.s3.ap-northeast-1.amazonaws.com/uploads/outputs/20f9d68f-50ec-44ae-8630-173fc38a2d6a\?response-content-disposition=attachment%3B%20filename%3D%22458093-1.output.mp4%22%3B%20filename%2A%3DUTF-8%27%27458093-1.output.mp4&response-content-type=video%2Fmp4&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=.*&X-Amz-Date=.*&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=.*}, site.image_url)
end
end