From 77854349e58afb947bdefd870b7c51e4c5088ecc Mon Sep 17 00:00:00 2001 From: Albert Yi Date: Wed, 25 Jul 2018 11:04:50 -0700 Subject: [PATCH] testing --- .../upload_service/controller_helper.rb | 2 +- app/logical/upload_service/utils.rb | 3 +- app/models/artist_url.rb | 2 +- test/functional/uploads_controller_test.rb | 14 ++++++++ test/unit/artist_test.rb | 2 +- test/unit/downloads/pixiv_test.rb | 36 +++++++++---------- 6 files changed, 37 insertions(+), 22 deletions(-) diff --git a/app/logical/upload_service/controller_helper.rb b/app/logical/upload_service/controller_helper.rb index 8984f81e2..a456e6b44 100644 --- a/app/logical/upload_service/controller_helper.rb +++ b/app/logical/upload_service/controller_helper.rb @@ -5,7 +5,7 @@ class UploadService if Utils.is_downloadable?(url) && file.nil? download = Downloads::File.new(url) - normalized_url, _, _ = download.before_download(url, {}) + normalized_url = download.rewrite_url() post = if normalized_url.nil? Post.where("SourcePattern(lower(posts.source)) = ?", url).first else diff --git a/app/logical/upload_service/utils.rb b/app/logical/upload_service/utils.rb index 01d01cd7e..1c4ce2b6a 100644 --- a/app/logical/upload_service/utils.rb +++ b/app/logical/upload_service/utils.rb @@ -222,7 +222,8 @@ class UploadService def download_for_upload(source, upload) file = download_from_source(source, referer_url: upload.referer_url) do |context| upload.downloaded_source = context[:downloaded_source] - upload.source = context[:source] + puts "source: #{source} -> #{context[:source]}" + #upload.source = context[:source] if context[:ugoira] upload.context = { ugoira: context[:ugoira] } diff --git a/app/models/artist_url.rb b/app/models/artist_url.rb index d77c2e12e..98a2b54c7 100644 --- a/app/models/artist_url.rb +++ b/app/models/artist_url.rb @@ -115,7 +115,7 @@ class ArtistUrl < ApplicationRecord def validate_url_format uri = Addressable::URI.parse(url) - errors[:url] << " #{uri} must begin with http:// or https://" if !uri.scheme.in?(%w[http https]) + errors[:url] << "#{uri} must begin with http:// or https://" if !uri.scheme.in?(%w[http https]) rescue Addressable::URI::InvalidURIError => error errors[:url] << "is malformed: #{error}" end diff --git a/test/functional/uploads_controller_test.rb b/test/functional/uploads_controller_test.rb index 20880e3c2..4e5593a0e 100644 --- a/test/functional/uploads_controller_test.rb +++ b/test/functional/uploads_controller_test.rb @@ -68,6 +68,20 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest end end + context "for a pixiv post" do + setup do + @source = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=14901720" + end + + should "set the correct url" do + get_auth new_upload_path, @user, params: {url: @source} + assert_response :success + Delayed::Worker.new.work_off + upload = Upload.last + assert_equal(@source, upload.source) + end + end + context "for a twitter post" do should "render" do skip "Twitter keys are not set" unless Danbooru.config.twitter_api_key diff --git a/test/unit/artist_test.rb b/test/unit/artist_test.rb index f9998aa35..2f73b25b7 100644 --- a/test/unit/artist_test.rb +++ b/test/unit/artist_test.rb @@ -168,7 +168,7 @@ class ArtistTest < ActiveSupport::TestCase should "not allow invalid urls" do artist = FactoryBot.create(:artist, :url_string => "blah") assert_equal(false, artist.valid?) - assert_equal(["Url must begin with http:// or https://"], artist.errors[:url]) + assert_equal(["blah must begin with http:// or https://"], artist.errors[:url]) end should "make sure old urls are deleted" do diff --git a/test/unit/downloads/pixiv_test.rb b/test/unit/downloads/pixiv_test.rb index 512932336..d19bd67e5 100644 --- a/test/unit/downloads/pixiv_test.rb +++ b/test/unit/downloads/pixiv_test.rb @@ -12,24 +12,6 @@ module Downloads super end - context "An ugoira site for pixiv" do - setup do - @download = Downloads::File.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364") - @tempfile = @download.download! - @tempfile.close! - end - - should "capture the data" do - assert_equal("https://i.pximg.net/img-zip-ugoira/img/2017/04/04/08/57/38/62247364_ugoira1920x1080.zip", @download.source) - assert_equal(2, @download.data[:ugoira_frame_data].size) - if @download.data[:ugoira_frame_data][0]["file"] - assert_equal([{"file"=>"000000.jpg", "delay"=>125}, {"file"=>"000001.jpg", "delay"=>125}], @download.data[:ugoira_frame_data]) - else - assert_equal([{"delay_msec"=>125}, {"delay_msec"=>125}], @download.data[:ugoira_frame_data]) - end - end - end - context "in all cases" do # Test an old illustration (one uploaded before 2014-09-16). New # /img-original/ and /img-master/ URLs currently don't work for images @@ -195,5 +177,23 @@ module Downloads end end end + + context "An ugoira site for pixiv" do + setup do + @download = Downloads::File.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364") + @tempfile = @download.download! + @tempfile.close! + end + + should "capture the data" do + assert_equal("https://i.pximg.net/img-zip-ugoira/img/2017/04/04/08/57/38/62247364_ugoira1920x1080.zip", @download.source) + assert_equal(2, @download.data[:ugoira_frame_data].size) + if @download.data[:ugoira_frame_data][0]["file"] + assert_equal([{"file"=>"000000.jpg", "delay"=>125}, {"file"=>"000001.jpg", "delay"=>125}], @download.data[:ugoira_frame_data]) + else + assert_equal([{"delay_msec"=>125}, {"delay_msec"=>125}], @download.data[:ugoira_frame_data]) + end + end + end end end