Fix #5221: Trying to upload an unsupported url shows ai tags error.

This commit is contained in:
evazion
2022-07-01 18:13:36 -05:00
parent a7755a7469
commit 67798c9ece
4 changed files with 33 additions and 4 deletions

View File

@@ -245,6 +245,19 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
assert_equal(source2, upload.source)
end
should "save the AI tags" do
mock_autotagger_evaluate({ "1girl": 0.5 })
upload = assert_successful_upload("test/files/test.jpg")
assert_equal(1, upload.media_assets.first.ai_tags.count)
end
should "save the EXIF metadata" do
upload = assert_successful_upload("test/files/test.jpg")
assert_equal(true, upload.media_assets.first.media_metadata.present?)
end
context "uploading a file from your computer" do
should_upload_successfully("test/files/test.jpg")
should_upload_successfully("test/files/test.png")

View File

@@ -23,6 +23,7 @@ class ActiveSupport::TestCase
extend PostArchiveTestHelper
extend PoolArchiveTestHelper
include ReportbooruHelper
include AutotaggerHelper
include DownloadTestHelper
include IqdbTestHelper
include UploadTestHelper

View File

@@ -0,0 +1,11 @@
module AutotaggerHelper
def mock_autotagger_evaluate(tags, http: Danbooru::Http.any_instance)
tags.keys.each { |name| create(:tag, name: name) }
Danbooru.config.stubs(:autotagger_url).returns("http://localhost:5000")
body = [{ filename: "test.jpg", tags: tags }]
response = HTTP::Response.new(status: 200, body: body.to_json, version: "1.1", request: nil, headers: { "Content-Type": "application/json" })
http.stubs(:post).with("http://localhost:5000/evaluate", anything).returns(response)
end
end