fix pixiv tests

This commit is contained in:
r888888888
2014-10-20 20:49:17 -07:00
parent 260de869b1
commit 8d4c9d7955
95 changed files with 146368 additions and 31275 deletions

View File

@@ -3,6 +3,7 @@ require 'test_helper'
class AliasAndImplicationImporterTest < ActiveSupport::TestCase
context "The alias and implication importer" do
setup do
Delayed::Worker.delay_jobs = true
@user = FactoryGirl.create(:user)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"

View File

@@ -26,8 +26,8 @@ module Downloads
end
should "stream a file from an HTTP source" do
VCR.use_cassette("download-file-http", :record => :once) do
@download.http_get_streaming do |resp|
VCR.use_cassette("download-file-http", :record => :none) do
@download.http_get_streaming(@source) do |resp|
assert_equal("200", resp.code)
assert(resp["Content-Length"].to_i > 0, "File should be larger than 0 bytes")
end
@@ -36,15 +36,15 @@ module Downloads
should "throw an exception when the file is larger than the maximum" do
assert_raise(Downloads::File::Error) do
VCR.use_cassette("download-file-http", :record => :once) do
@download.http_get_streaming(:max_size => 1) do |resp|
VCR.use_cassette("download-file-http", :record => :none) do
@download.http_get_streaming(@source, {}, :max_size => 1) do |resp|
end
end
end
end
should "store the file in the tempfile path" do
VCR.use_cassette("download-file-http", :record => :once) do
VCR.use_cassette("download-file-http", :record => :none) do
@download.download!
end
@@ -74,8 +74,8 @@ module Downloads
end
should "stream a file from an HTTPS source" do
VCR.use_cassette("download-file-https", :record => :once) do
@download.http_get_streaming do |resp|
VCR.use_cassette("download-file-https", :record => :none) do
@download.http_get_streaming(@source) do |resp|
assert_equal("200", resp.code)
assert(resp["Content-Length"].to_i > 0, "File should be larger than 0 bytes")
end

View File

@@ -2,11 +2,13 @@ require 'test_helper'
module Downloads
class PixivTest < ActiveSupport::TestCase
PHPSESSID = "696859_60ab47b3a9a11b41d833853881cc5e40"
def assert_downloaded(expected_filesize, source, cassette)
tempfile = Tempfile.new("danbooru-test")
download = Downloads::File.new(source, tempfile.path)
VCR.use_cassette(cassette, :record => :once) do
VCR.use_cassette(cassette, :record => :none) do
assert_nothing_raised(Downloads::File::Error) do
download.download!
end
@@ -15,23 +17,26 @@ module Downloads
assert_equal(expected_filesize, tempfile.size, "Tested source URL: #{source}")
end
def assert_rewritten(expected_source, test_source)
def assert_rewritten(expected_source, test_source, cassette)
tempfile = Tempfile.new("danbooru-test")
download = Downloads::File.new(test_source, tempfile.path)
rewritten_source, headers = download.before_download(test_source, {})
assert_equal(expected_source, rewritten_source, "Tested source URL: #{test_source}")
VCR.use_cassette(cassette, :record => :none) do
rewritten_source, headers, _ = download.before_download(test_source, {}, {})
assert_equal(expected_source, rewritten_source, "Tested source URL: #{test_source}")
end
end
def assert_not_rewritten(source)
assert_rewritten(source, source)
def assert_not_rewritten(source, cassette)
assert_rewritten(source, source, cassette)
end
context "An ugoira site for pixiv" do
setup do
Delayed::Worker.delay_jobs = false
@tempfile = Tempfile.new("danbooru-test")
@download = Downloads::File.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46378654", @tempfile.path)
VCR.use_cassette("ugoira-converter", :record => :new_episodes) do
VCR.use_cassette("download-ugoira-converter", :record => :none) do
@download.download!
end
end
@@ -49,244 +54,213 @@ module Downloads
end
end
# Test an old illustration (one uploaded before 2014-09-16). New
# /img-original/ and /img-master/ URLs currently don't work for images
# uploaded before this date. Only old /imgXX/img/username/ URLs work.
context "downloading an old PNG illustration" do
context "in all cases" do
setup do
@medium_page = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=14901720"
@big_page = "http://www.pixiv.net/member_illust.php?mode=big&illust_id=14901720"
@old_small_thumbnail = "http://i2.pixiv.net/img18/img/evazion/14901720_s.png"
@old_medium_thumbnail = "http://i2.pixiv.net/img18/img/evazion/14901720_m.png"
@old_full_size_image = "http://i2.pixiv.net/img18/img/evazion/14901720.png"
@new_small_thumbnail = "http://i1.pixiv.net/c/150x150/img-master/img/2010/11/30/08/39/58/14901720_p0_master1200.jpg"
@new_medium_thumbnail = "http://i1.pixiv.net/c/600x600/img-master/img/2010/11/30/08/39/58/14901720_p0_master1200.jpg"
@new_full_size_image = "http://i1.pixiv.net/img-original/img/2010/11/30/08/39/58/14901720_p0.png"
@file_size = 1_083
PixivWebAgent.stubs(:phpsessid).returns(PHPSESSID)
end
should "download the full size image" do
assert_not_rewritten(@full_size_image)
assert_downloaded(@file_size, @old_full_size_image, "download-pixiv-old-png-full-size")
end
# Test an old illustration (one uploaded before 2014-09-16). New
# /img-original/ and /img-master/ URLs currently don't work for images
# uploaded before this date. Only old /imgXX/img/username/ URLs work.
context "downloading an old PNG illustration" do
setup do
@medium_page = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=14901720"
@big_page = "http://www.pixiv.net/member_illust.php?mode=big&illust_id=14901720"
should "download the full size image instead of the HTML page" do
VCR.use_cassette("rewrite-pixiv-old-png-html-pages", :record => :once) do
assert_rewritten(@old_full_size_image, @medium_page)
assert_rewritten(@old_full_size_image, @big_page)
@old_small_thumbnail = "http://i2.pixiv.net/img18/img/evazion/14901720_s.png"
@old_medium_thumbnail = "http://i2.pixiv.net/img18/img/evazion/14901720_m.png"
@old_full_size_image = "http://i2.pixiv.net/img18/img/evazion/14901720.png"
@new_small_thumbnail = "http://i1.pixiv.net/c/150x150/img-master/img/2010/11/30/08/39/58/14901720_p0_master1200.jpg"
@new_medium_thumbnail = "http://i1.pixiv.net/c/600x600/img-master/img/2010/11/30/08/39/58/14901720_p0_master1200.jpg"
@new_full_size_image = "http://i1.pixiv.net/img-original/img/2010/11/30/08/39/58/14901720_p0.png"
@file_size = 1_083
end
assert_downloaded(@file_size, @medium_page, "download-pixiv-old-png-medium-html")
assert_downloaded(@file_size, @big_page, "download-pixiv-old-png-big-html")
end
should "download the full size image instead of the thumbnail" do
VCR.use_cassette("rewrite-pixiv-old-png-thumbnails", :record => :once) do
assert_rewritten(@old_full_size_image, @old_small_thumbnail)
assert_rewritten(@old_full_size_image, @old_medium_thumbnail)
should "download the full size image" do
assert_not_rewritten(@full_size_image, "rewrite-pixiv-old-png-full-size")
assert_downloaded(@file_size, @old_full_size_image, "download-pixiv-old-png-full-size")
end
assert_downloaded(@file_size, @old_small_thumbnail, "download-pixiv-old-png-old-small-thumbnail")
assert_downloaded(@file_size, @old_medium_thumbnail, "download-pixiv-old-png-old-medium-thumbnail")
end
# These tests aren't expected to pass. This is just to test if Pixiv has changed to using new URLs for old images.
should_eventually "work when using new URLs" do
# Don't know the actual file size of the thumbnails since they don't work.
assert_downloaded(42, @new_small_thumbnail, "download-pixiv-old-png-new-small-thumbnail")
assert_downloaded(42, @new_medium_thumbnail, "download-pixiv-old-png-new-medium-thumbnail")
assert_downloaded(@file_size, @new_full_size_image, "download-pixiv-old-png-new-full-size")
end
end
# Test a new illustration (one uploaded after 2014-09-30). New illustrations
# must use /img-original/ for full size URLs. Old /imgXX/img/username/ style URLs
# don't work for images uploaded after this date.
context "downloading a new PNG illustration" do
setup do
@medium_page = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46337015"
@big_page = "http://www.pixiv.net/member_illust.php?mode=big&illust_id=46337015"
@medium_thumbnail = "http://i2.pixiv.net/c/600x600/img-master/img/2014/10/04/03/59/52/46337015_p0_master1200.jpg"
@full_size_image = "http://i2.pixiv.net/img-original/img/2014/10/04/03/59/52/46337015_p0.png"
@file_size = 5_141
end
should "download the full size image" do
assert_not_rewritten(@full_size_image)
assert_downloaded(@file_size, @full_size_image, "download-pixiv-new-png-full-size")
end
should "download the full size image instead of the HTML page" do
VCR.use_cassette("rewrite-pixiv-new-png-html-pages", :record => :once) do
assert_rewritten(@full_size_image, @medium_page)
assert_rewritten(@full_size_image, @big_page)
should "download the full size image instead of the HTML page" do
assert_rewritten(@old_full_size_image, @medium_page, "rewrite-pixiv-old-png-medium-html")
assert_rewritten(@old_full_size_image, @big_page, "rewrite-pixiv-old-png-big-html")
assert_downloaded(@file_size, @medium_page, "download-pixiv-old-png-medium-html")
assert_downloaded(@file_size, @big_page, "download-pixiv-old-png-big-html")
end
assert_downloaded(@file_size, @medium_page, "download-pixiv-new-png-medium-html")
assert_downloaded(@file_size, @big_page, "download-pixiv-new-png-big-html")
end
should "download the full size image instead of the thumbnail" do
VCR.use_cassette("rewrite-pixiv-new-png-thumbnails", :record => :once) do
assert_rewritten(@full_size_image, @medium_thumbnail)
should "download the full size image instead of the thumbnail" do
assert_rewritten(@old_full_size_image, @old_small_thumbnail, "rewrite-pixiv-old-png-old-small-thumbnail")
assert_rewritten(@old_full_size_image, @old_medium_thumbnail, "rewrite-pixiv-old-png-old-medium-thumbnail")
assert_downloaded(@file_size, @old_small_thumbnail, "download-pixiv-old-png-old-small-thumbnail")
assert_downloaded(@file_size, @old_medium_thumbnail, "download-pixiv-old-png-old-medium-thumbnail")
end
assert_downloaded(@file_size, @medium_thumbnail, "download-pixiv-new-png-medium-thumbnail")
end
end
# These tests aren't expected to pass. This is just to test if Pixiv has changed to using new URLs for old images.
should_eventually "work when using new URLs" do
# Don't know the actual file size of the thumbnails since they don't work.
assert_downloaded(42, @new_small_thumbnail, "download-pixiv-old-png-new-small-thumbnail")
assert_downloaded(42, @new_medium_thumbnail, "download-pixiv-old-png-new-medium-thumbnail")
assert_downloaded(@file_size, @new_full_size_image, "download-pixiv-old-png-new-full-size")
context "downloading an old manga image" do
setup do
@medium_page = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=18557054"
@manga_page = "http://www.pixiv.net/member_illust.php?mode=manga&illust_id=18557054"
@manga_big_p1_page = "http://www.pixiv.net/member_illust.php?mode=manga_big&illust_id=18557054&page=1"
@p0_tiny_thumbnail = "http://i1.pixiv.net/img-inf/img/2011/05/01/23/28/04/18557054_64x64.jpg"
@p0_small_thumbnail = "http://i1.pixiv.net/img-inf/img/2011/05/01/23/28/04/18557054_s.png"
@p0_medium_thumbnail = "http://i1.pixiv.net/img07/img/pasirism/18557054_m.png"
@p0_large_thumbnail = "http://i1.pixiv.net/img07/img/pasirism/18557054_p0.png"
@p1_large_thumbnail = "http://i1.pixiv.net/img07/img/pasirism/18557054_p1.png"
@p0_full_size_image = "http://i1.pixiv.net/img07/img/pasirism/18557054_big_p0.png"
@p1_full_size_image = "http://i1.pixiv.net/img07/img/pasirism/18557054_big_p1.png"
@p0_file_size = 1964
@p1_file_size = 1927
end
end
should "download the full size image" do
assert_not_rewritten(@p0_full_size_image)
assert_not_rewritten(@p1_full_size_image)
assert_downloaded(@p0_file_size, @p0_full_size_image, "download-pixiv-old-manga-p0-full-size")
assert_downloaded(@p1_file_size, @p1_full_size_image, "download-pixiv-old-manga-p1-full-size")
end
should "download the full size image instead of the HTML page" do
VCR.use_cassette("rewrite-pixiv-old-manga-html-pages", :record => :once) do
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)
# Test a new illustration (one uploaded after 2014-09-30). New illustrations
# must use /img-original/ for full size URLs. Old /imgXX/img/username/ style URLs
# don't work for images uploaded after this date.
context "downloading a new PNG illustration" do
setup do
@medium_page = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46337015"
@big_page = "http://www.pixiv.net/member_illust.php?mode=big&illust_id=46337015"
@medium_thumbnail = "http://i2.pixiv.net/c/600x600/img-master/img/2014/10/04/03/59/52/46337015_p0_master1200.jpg"
@full_size_image = "http://i2.pixiv.net/img-original/img/2014/10/04/03/59/52/46337015_p0.png"
@file_size = 5_141
end
assert_downloaded(@p0_file_size, @medium_page, "download-pixiv-old-manga-p0-medium-html")
assert_downloaded(@p0_file_size, @manga_page, "download-pixiv-old-manga-p0-big-html")
assert_downloaded(@p1_file_size, @manga_big_p1_page, "download-pixiv-old-manga-p1-big-html")
end
should "download the full size image instead of the thumbnail" do
VCR.use_cassette("rewrite-pixiv-old-manga-thumbnails", :record => :once) do
assert_rewritten(@p0_full_size_image, @p0_tiny_thumbnail)
assert_rewritten(@p0_full_size_image, @p0_small_thumbnail)
assert_rewritten(@p0_full_size_image, @p0_large_thumbnail)
assert_rewritten(@p1_full_size_image, @p1_large_thumbnail)
should "download the full size image" do
assert_not_rewritten(@full_size_image, "rewrite-pixiv-new-png-full-size")
assert_downloaded(@file_size, @full_size_image, "download-pixiv-new-png-full-size")
end
assert_downloaded(@p0_file_size, @p0_tiny_thumbnail, "download-pixiv-old-manga-p0-tiny-thumbnail")
assert_downloaded(@p0_file_size, @p0_small_thumbnail, "download-pixiv-old-manga-p0-small-thumbnail")
assert_downloaded(@p0_file_size, @p0_large_thumbnail, "download-pixiv-old-manga-p0-large-thumbnail")
assert_downloaded(@p1_file_size, @p1_large_thumbnail, "download-pixiv-old-manga-p1-large-thumbnail")
end
should "download the full size image instead of the medium thumbnail" do
VCR.use_cassette("rewrite-pixiv-old-manga-medium-thumbnail", :record => :once) do
assert_rewritten(@p0_full_size_image, @p0_medium_thumbnail)
should "download the full size image instead of the HTML page" do
assert_rewritten(@full_size_image, @medium_page, "rewrite-pixiv-new-png-medium-html")
assert_rewritten(@full_size_image, @big_page, "rewrite-pixiv-new-png-big-html")
assert_downloaded(@file_size, @medium_page, "download-pixiv-new-png-medium-html")
assert_downloaded(@file_size, @big_page, "download-pixiv-new-png-big-html")
end
assert_downloaded(@p0_file_size, @p0_medium_thumbnail, "download-pixiv-old-manga-p0-medium-thumbnail")
end
end
context "downloading a new manga image" do
setup do
@medium_page = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46304614"
@manga_page = "http://www.pixiv.net/member_illust.php?mode=manga&illust_id=46304614"
@manga_big_p1_page = "http://www.pixiv.net/member_illust.php?mode=manga_big&illust_id=46304614&page=1"
@p0_large_thumbnail = "http://i1.pixiv.net/c/1200x1200/img-master/img/2014/10/02/14/21/39/46304614_p0_master1200.jpg"
@p1_large_thumbnail = "http://i1.pixiv.net/c/1200x1200/img-master/img/2014/10/02/14/21/39/46304614_p1_master1200.jpg"
@p0_full_size_image = "http://i1.pixiv.net/img-original/img/2014/10/02/14/21/39/46304614_p0.gif"
@p1_full_size_image = "http://i1.pixiv.net/img-original/img/2014/10/02/14/21/39/46304614_p1.gif"
@p0_file_size = 61_131
@p1_file_size = 46_818
should "download the full size image instead of the thumbnail" do
assert_rewritten(@full_size_image, @medium_thumbnail, "rewrite-pixiv-new-png-medium-thumbnail")
assert_downloaded(@file_size, @medium_thumbnail, "download-pixiv-new-png-medium-thumbnail")
end
end
should "download the full size image" do
assert_not_rewritten(@p0_full_size_image)
assert_not_rewritten(@p1_full_size_image)
context "downloading an old manga image" do
setup do
@medium_page = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=18557054"
@manga_page = "http://www.pixiv.net/member_illust.php?mode=manga&illust_id=18557054"
@manga_big_p1_page = "http://www.pixiv.net/member_illust.php?mode=manga_big&illust_id=18557054&page=1"
assert_downloaded(@p0_file_size, @p0_full_size_image, "download-pixiv-new-manga-p0-full-size")
assert_downloaded(@p1_file_size, @p1_full_size_image, "download-pixiv-new-manga-p1-full-size")
end
@p0_tiny_thumbnail = "http://i1.pixiv.net/img-inf/img/2011/05/01/23/28/04/18557054_64x64.jpg"
@p0_small_thumbnail = "http://i1.pixiv.net/img-inf/img/2011/05/01/23/28/04/18557054_s.png"
@p0_medium_thumbnail = "http://i1.pixiv.net/img07/img/pasirism/18557054_m.png"
@p0_large_thumbnail = "http://i1.pixiv.net/img07/img/pasirism/18557054_p0.png"
@p1_large_thumbnail = "http://i1.pixiv.net/img07/img/pasirism/18557054_p1.png"
should "download the full size image instead of the HTML page" do
VCR.use_cassette("rewrite-pixiv-new-manga-html-pages", :record => :once) do
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)
@p0_full_size_image = "http://i1.pixiv.net/img07/img/pasirism/18557054_big_p0.png"
@p1_full_size_image = "http://i1.pixiv.net/img07/img/pasirism/18557054_big_p1.png"
@p0_file_size = 1964
@p1_file_size = 1927
end
assert_downloaded(@p0_file_size, @medium_page, "download-pixiv-new-manga-p0-medium-html")
assert_downloaded(@p0_file_size, @manga_page, "download-pixiv-new-manga-p0-big-html")
assert_downloaded(@p1_file_size, @manga_big_p1_page, "download-pixiv-new-manga-p1-big-html")
end
should "download the full size image instead of the thumbnail" do
VCR.use_cassette("rewrite-pixiv-new-manga-thumbnails", :record => :once) do
assert_rewritten(@p0_full_size_image, @p0_large_thumbnail)
assert_rewritten(@p1_full_size_image, @p1_large_thumbnail)
should "download the full size image" do
assert_not_rewritten(@p0_full_size_image, "rewrite-pixiv-old-manga-p0-full-size")
assert_not_rewritten(@p1_full_size_image, "rewrite-pixiv-old-manga-p1-full-size")
assert_downloaded(@p0_file_size, @p0_full_size_image, "download-pixiv-old-manga-p0-full-size")
assert_downloaded(@p1_file_size, @p1_full_size_image, "download-pixiv-old-manga-p1-full-size")
end
assert_downloaded(@p0_file_size, @p0_large_thumbnail, "download-pixiv-new-manga-p0-large-thumbnail")
assert_downloaded(@p1_file_size, @p1_large_thumbnail, "download-pixiv-new-manga-p1-large-thumbnail")
end
end
context "downloading a ugoira" do
setup do
@medium_page = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46323924"
@small_thumbnail = "http://i1.pixiv.net/img-inf/img/2014/10/03/17/29/16/46323924_s.jpg"
@zip_file = "http://i1.pixiv.net/img-zip-ugoira/img/2014/10/03/17/29/16/46323924_ugoira1920x1080.zip"
@file_size = 41_171
end
should "download the zip file instead of the HTML page" do
VCR.use_cassette("rewrite-pixiv-ugoira-html-pages", :record => :once) do
assert_rewritten(@zip_file, @medium_page)
should "download the full size image instead of the HTML page" do
assert_rewritten(@p0_full_size_image, @medium_page, "rewrite-pixiv-old-manga-p0-medium-html")
assert_rewritten(@p0_full_size_image, @manga_page, "rewrite-pixiv-old-manga-p0-big-html")
assert_rewritten(@p1_full_size_image, @manga_big_p1_page, "rewrite-pixiv-old-manga-p1-big-html")
assert_downloaded(@p0_file_size, @medium_page, "download-pixiv-old-manga-p0-medium-html")
assert_downloaded(@p0_file_size, @manga_page, "download-pixiv-old-manga-p0-big-html")
assert_downloaded(@p1_file_size, @manga_big_p1_page, "download-pixiv-old-manga-p1-big-html")
end
assert_downloaded(@file_size, @medium_page, "download-pixiv-ugoira-medium-page")
end
should "download the zip file instead of the thumbnail" do
VCR.use_cassette("rewrite-pixiv-ugoira-thumbnails", :record => :once) do
assert_rewritten(@zip_file, @small_thumbnail)
should "download the full size image instead of the thumbnail" do
assert_rewritten(@p0_full_size_image, @p0_tiny_thumbnail, "download-pixiv-old-manga-p0-tiny-thumbnail")
assert_rewritten(@p0_full_size_image, @p0_small_thumbnail, "download-pixiv-old-manga-p0-small-thumbnail")
assert_rewritten(@p0_full_size_image, @p0_large_thumbnail, "download-pixiv-old-manga-p0-large-thumbnail")
assert_rewritten(@p1_full_size_image, @p1_large_thumbnail, "download-pixiv-old-manga-p1-large-thumbnail")
assert_downloaded(@p0_file_size, @p0_tiny_thumbnail, "download-pixiv-old-manga-p0-tiny-thumbnail")
assert_downloaded(@p0_file_size, @p0_small_thumbnail, "download-pixiv-old-manga-p0-small-thumbnail")
assert_downloaded(@p0_file_size, @p0_large_thumbnail, "download-pixiv-old-manga-p0-large-thumbnail")
assert_downloaded(@p1_file_size, @p1_large_thumbnail, "download-pixiv-old-manga-p1-large-thumbnail")
end
assert_downloaded(@file_size, @small_thumbnail, "download-pixiv-ugoira-small-thumbnail")
should "download the full size image instead of the medium thumbnail" do
assert_rewritten(@p0_full_size_image, @p0_medium_thumbnail, "rewrite-pixiv-old-manga-p0-medium-thumbnail")
assert_downloaded(@p0_file_size, @p0_medium_thumbnail, "download-pixiv-old-manga-p0-medium-thumbnail")
end
end
should "download the zip file" do
assert_not_rewritten(@zip_file)
assert_downloaded(@file_size, @zip_file, "download-pixiv-ugoira-zip-file")
context "downloading a new manga image" do
setup do
@medium_page = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46304614"
@manga_page = "http://www.pixiv.net/member_illust.php?mode=manga&illust_id=46304614"
@manga_big_p1_page = "http://www.pixiv.net/member_illust.php?mode=manga_big&illust_id=46304614&page=1"
@p0_large_thumbnail = "http://i1.pixiv.net/c/1200x1200/img-master/img/2014/10/02/14/21/39/46304614_p0_master1200.jpg"
@p1_large_thumbnail = "http://i1.pixiv.net/c/1200x1200/img-master/img/2014/10/02/14/21/39/46304614_p1_master1200.jpg"
@p0_full_size_image = "http://i1.pixiv.net/img-original/img/2014/10/02/14/21/39/46304614_p0.gif"
@p1_full_size_image = "http://i1.pixiv.net/img-original/img/2014/10/02/14/21/39/46304614_p1.gif"
@p0_file_size = 61_131
@p1_file_size = 46_818
end
should "download the full size image" do
assert_not_rewritten(@p0_full_size_image, "rewrite-pixiv-new-manga-p0-full-size")
assert_not_rewritten(@p1_full_size_image, "rewrite-pixiv-new-manga-p1-full-size")
assert_downloaded(@p0_file_size, @p0_full_size_image, "download-pixiv-new-manga-p0-full-size")
assert_downloaded(@p1_file_size, @p1_full_size_image, "download-pixiv-new-manga-p1-full-size")
end
should "download the full size image instead of the HTML page" do
assert_rewritten(@p0_full_size_image, @medium_page, "rewrite-pixiv-new-manga-p0-medium-html")
assert_rewritten(@p0_full_size_image, @manga_page, "rewrite-pixiv-new-manga-p0-big-html")
assert_rewritten(@p1_full_size_image, @manga_big_p1_page, "rewrite-pixiv-new-manga-p1-big-html")
assert_downloaded(@p0_file_size, @medium_page, "download-pixiv-new-manga-p0-medium-html")
assert_downloaded(@p0_file_size, @manga_page, "download-pixiv-new-manga-p0-big-html")
assert_downloaded(@p1_file_size, @manga_big_p1_page, "download-pixiv-new-manga-p1-big-html")
end
should "download the full size image instead of the thumbnail" do
assert_rewritten(@p0_full_size_image, @p0_large_thumbnail, "rewrite-pixiv-new-manga-p0-large-thumbnail")
assert_rewritten(@p1_full_size_image, @p1_large_thumbnail, "rewrite-pixiv-new-manga-p1-large-thumbnail")
assert_downloaded(@p0_file_size, @p0_large_thumbnail, "download-pixiv-new-manga-p0-large-thumbnail")
assert_downloaded(@p1_file_size, @p1_large_thumbnail, "download-pixiv-new-manga-p1-large-thumbnail")
end
end
context "downloading a ugoira" do
setup do
@medium_page = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46323924"
@small_thumbnail = "http://i1.pixiv.net/img-inf/img/2014/10/03/17/29/16/46323924_s.jpg"
@zip_file = "http://i1.pixiv.net/img-zip-ugoira/img/2014/10/03/17/29/16/46323924_ugoira1920x1080.zip"
@file_size = 41_171
end
should "download the zip file instead of the HTML page" do
assert_rewritten(@zip_file, @medium_page, "rewrite-pixiv-ugoira-medium-page")
assert_downloaded(@file_size, @medium_page, "download-pixiv-ugoira-medium-page")
end
should "download the zip file instead of the thumbnail" do
assert_rewritten(@zip_file, @small_thumbnail, "rewrite-pixiv-ugoira-small-thumbnail")
assert_downloaded(@file_size, @small_thumbnail, "download-pixiv-ugoira-small-thumbnail")
end
should "download the zip file" do
assert_not_rewritten(@zip_file, "rewrite-pixiv-ugoira-zip-file")
assert_downloaded(@file_size, @zip_file, "download-pixiv-ugoira-zip-file")
end
end
end
end

View File

@@ -1,43 +0,0 @@
require 'test_helper'
module Downloads
class TwitpicTest < ActiveSupport::TestCase
context "a download for a twitpic html page" do
setup do
@source = "http://twitpic.com/cpprns"
@tempfile = Tempfile.new("danbooru-test")
@download = Downloads::File.new(@source, @tempfile.path)
VCR.use_cassette("download-twitpic-html", :record => :new_episodes) do
@download.download!
end
end
should "set the direct image link as the source" do
assert_equal("http://d3j5vwomefv46c.cloudfront.net/photos/large/768786760.jpg?1368245083", @download.source)
end
should "work" do
assert_equal(89_409, ::File.size(@tempfile.path))
end
end
context "a download for a twitpic thumbnail" do
setup do
@source = "http://d3j5vwomefv46c.cloudfront.net/photos/thumb/768786760.jpg?1368245083"
@tempfile = Tempfile.new("danbooru-test")
@download = Downloads::File.new(@source, @tempfile.path)
VCR.use_cassette("download-twitpic-thumb", :record => :new_episodes) do
@download.download!
end
end
should "instead download the original version" do
assert_equal("http://d3j5vwomefv46c.cloudfront.net/photos/large/768786760.jpg?1368245083", @download.source)
end
should "work" do
assert_equal(89_409, ::File.size(@tempfile.path))
end
end
end
end

View File

@@ -21,7 +21,7 @@ class PixivUgoiraConverterTest < ActiveSupport::TestCase
end
should "output to webm" do
@converter = PixivUgoiraConverter.new
@converter = PixivUgoiraConverter
@converter.convert(@zipped_body, @write_file.path, @preview_write_file.path, @frame_data)
assert_operator(File.size(@write_file.path), :>, 1_000)
assert_operator(File.size(@preview_write_file.path), :>, 0)

View File

@@ -6,12 +6,12 @@ module Sources
class NicoSeigaTest < ActiveSupport::TestCase
context "The source site for nico seiga" do
setup do
VCR.use_cassette("source-nico-seiga-unit-test-1", :record => :new_episodes) do
VCR.use_cassette("source-nico-seiga-unit-test-1", :record => :none) do
@site_1 = Sources::Site.new("http://lohas.nicoseiga.jp/priv/9a7b691a4696cd970e4e762fbb7c07c19b29f22b/1398877469/3329388")
@site_1.get
end
VCR.use_cassette("source-nico-seiga-unit-test-2", :record => :new_episodes) do
VCR.use_cassette("source-nico-seiga-unit-test-2", :record => :none) do
@site_2 = Sources::Site.new("http://seiga.nicovideo.jp/seiga/im3324796")
@site_2.get
end
@@ -28,8 +28,8 @@ module Sources
end
should "get the image url" do
assert_equal("http://lohas.nicoseiga.jp/priv/6d168c4fb6eb2f1d522606e961704bd0a9271961/1398887476/3329388", @site_1.image_url)
assert_equal("http://lohas.nicoseiga.jp/priv/eda0bab8cbab69d6aa884c28f1b1b45c61d88f30/1398887483/3324796", @site_2.image_url)
assert_equal("http://lohas.nicoseiga.jp/priv/63d3abda3e8c613f731869c3ba2c483564f8a2f3/1414023626/3329388", @site_1.image_url)
assert_equal("http://lohas.nicoseiga.jp/priv/19c9c6504fca0e199c4cfa651475be8b93ab9e59/1414023628/3324796", @site_2.image_url)
end
should "get the tags" do

View File

@@ -4,119 +4,127 @@ require 'test_helper'
module Sources
class PixivTest < ActiveSupport::TestCase
PHPSESSID = "696859_60ab47b3a9a11b41d833853881cc5e40"
def get_source(source, cassette)
VCR.use_cassette(cassette, :record => :once) do
VCR.use_cassette(cassette, :record => :none) do
@site = Sources::Site.new(source)
@site.get
@site
end
end
context "An ugoira source site for pixiv" do
context "in all cases" do
setup do
VCR.use_cassette("ugoira-converter") do
@site = Sources::Site.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46378654")
@site.get
PixivWebAgent.stubs(:phpsessid).returns(PHPSESSID)
end
context "An ugoira source site for pixiv" do
setup do
VCR.use_cassette("ugoira-converter", :record => :none) do
@site = Sources::Site.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46378654")
@site.get
end
end
should "get the file url" do
assert_equal("http://i1.pixiv.net/img-zip-ugoira/img/2014/10/05/23/42/23/46378654_ugoira1920x1080.zip", @site.file_url)
end
should "capture the frame data" do
assert_equal([{"file"=>"000000.jpg", "delay"=>200}, {"file"=>"000001.jpg", "delay"=>200}, {"file"=>"000002.jpg", "delay"=>200}, {"file"=>"000003.jpg", "delay"=>200}, {"file"=>"000004.jpg", "delay"=>250}], @site.ugoira_frame_data)
end
should "capture the image dimensions" do
assert_equal(60, @site.ugoira_width)
assert_equal(60, @site.ugoira_height)
end
end
should "get the file url" do
assert_equal("http://i1.pixiv.net/img-zip-ugoira/img/2014/10/05/23/42/23/46378654_ugoira1920x1080.zip", @site.file_url)
end
context "fetching source data for a new manga image" do
setup do
get_source("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46324488", "source-pixiv-new-manga")
end
should "capture the frame data" do
assert_equal([{"file"=>"000000.jpg", "delay"=>200}, {"file"=>"000001.jpg", "delay"=>200}, {"file"=>"000002.jpg", "delay"=>200}, {"file"=>"000003.jpg", "delay"=>200}, {"file"=>"000004.jpg", "delay"=>250}], @site.ugoira_frame_data)
end
should "get the profile" do
assert_equal("http://www.pixiv.net/member.php?id=339253", @site.profile_url)
end
should "capture the image dimensions" do
assert_equal(60, @site.ugoira_width)
assert_equal(60, @site.ugoira_height)
end
end
should "get the artist name" do
assert_equal("evazion", @site.artist_name)
end
context "fetching source data for a new manga image" do
setup do
get_source("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46324488", "source-pixiv-new-manga")
end
should "get the full size image url" do
assert_equal("http://i1.pixiv.net/img-original/img/2014/10/03/18/10/20/46324488_p0.png", @site.image_url)
end
should "get the profile" do
assert_equal("http://www.pixiv.net/member.php?id=339253", @site.profile_url)
end
should "get the page count" do
assert_equal(3, @site.page_count)
end
should "get the artist name" do
assert_equal("evazion", @site.artist_name)
end
should "get the tags" do
pixiv_tags = @site.tags.map(&:first)
pixiv_links = @site.tags.map(&:last)
should "get the full size image url" do
assert_equal("http://i1.pixiv.net/img-original/img/2014/10/03/18/10/20/46324488_p0.png", @site.image_url)
end
assert_equal(%w(R-18G derp tag1 tag2 オリジナル), pixiv_tags)
assert_contains(pixiv_links, /search\.php/)
end
should "get the page count" do
assert_equal(3, @site.page_count)
end
should "get the tags" do
pixiv_tags = @site.tags.map(&:first)
pixiv_links = @site.tags.map(&:last)
assert_equal(%w(R-18G derp tag1 tag2 オリジナル), pixiv_tags)
assert_contains(pixiv_links, /search\.php/)
end
should "convert a page into a json representation" do
assert_nothing_raised do
@site.to_json
should "convert a page into a json representation" do
assert_nothing_raised do
@site.to_json
end
end
end
end
context "fetching source data for an old manga image" do
setup do
get_source("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=45792845", "source-pixiv-old-manga")
context "fetching source data for an old manga image" do
setup do
get_source("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=45792845", "source-pixiv-old-manga")
end
should "get the page count" do
assert_equal(3, @site.page_count)
end
should "get the full size image url" do
assert_equal("http://i2.pixiv.net/img18/img/ringo78/45792845_big_p0.jpg", @site.image_url)
end
end
should "get the page count" do
assert_equal(3, @site.page_count)
context "fetching source data for a new illustration" do
setup do
get_source("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46337015", "source-pixiv-new-illust")
end
should "get the page count" do
assert_equal(1, @site.page_count)
end
should "get the full size image url" do
assert_equal("http://i2.pixiv.net/img-original/img/2014/10/04/03/59/52/46337015_p0.png", @site.image_url)
end
end
should "get the full size image url" do
assert_equal("http://i2.pixiv.net/img18/img/ringo78/45792845_big_p0.jpg", @site.image_url)
end
end
context "fetching source data for an old illustration" do
setup do
get_source("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=14901720", "source-pixiv-old-illust")
end
context "fetching source data for a new illustration" do
setup do
get_source("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46337015", "source-pixiv-new-illust")
end
should "get the page count" do
assert_equal(1, @site.page_count)
end
should "get the page count" do
assert_equal(1, @site.page_count)
end
should "get the full size image url" do
assert_equal("http://i2.pixiv.net/img18/img/evazion/14901720.png", @site.image_url)
end
should "get the full size image url" do
assert_equal("http://i2.pixiv.net/img-original/img/2014/10/04/03/59/52/46337015_p0.png", @site.image_url)
end
end
should "get the tags" do
pixiv_tags = @site.tags.map(&:first)
pixiv_links = @site.tags.map(&:last)
context "fetching source data for an old illustration" do
setup do
get_source("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=14901720", "source-pixiv-old-illust")
end
should "get the page count" do
assert_equal(1, @site.page_count)
end
should "get the full size image url" do
assert_equal("http://i2.pixiv.net/img18/img/evazion/14901720.png", @site.image_url)
end
should "get the tags" do
pixiv_tags = @site.tags.map(&:first)
pixiv_links = @site.tags.map(&:last)
assert_equal(%w(derp), pixiv_tags)
assert_contains(pixiv_links, /search\.php/)
assert_equal(%w(derp), pixiv_tags)
assert_contains(pixiv_links, /search\.php/)
end
end
end
end

View File

@@ -113,7 +113,7 @@ class UploadTest < ActiveSupport::TestCase
end
should "process successfully" do
VCR.use_cassette("ugoira-converter", :record => :new_episodes) do
VCR.use_cassette("ugoira-converter", :record => :none) do
@upload.download_from_source(@output_file.path)
end
assert_operator(File.size(@output_file.path), :>, 1_000)
@@ -126,7 +126,7 @@ class UploadTest < ActiveSupport::TestCase
@upload = FactoryGirl.create(:source_upload)
path = "#{Rails.root}/tmp/test.download.jpg"
VCR.use_cassette("upload-test-file", :record => :once) do
VCR.use_cassette("upload-test-file", :record => :none) do
assert_nothing_raised {@upload.download_from_source(path)}
assert(File.exists?(path))
assert_equal(8558, File.size(path))
@@ -200,7 +200,7 @@ class UploadTest < ActiveSupport::TestCase
should "increment the uploaders post_upload_count" do
@upload = FactoryGirl.create(:source_upload)
assert_difference("CurrentUser.user.post_upload_count", 1) do
VCR.use_cassette("upload-test-file", :record => :once) do
VCR.use_cassette("upload-test-file", :record => :none) do
@upload.process!
end
@@ -215,7 +215,7 @@ class UploadTest < ActiveSupport::TestCase
:tag_string => "hoge foo"
)
assert_difference("Post.count") do
VCR.use_cassette("upload-test-file", :record => :once) do
VCR.use_cassette("upload-test-file", :record => :none) do
assert_nothing_raised {@upload.process!}
end
end
@@ -242,7 +242,7 @@ class UploadTest < ActiveSupport::TestCase
:uploader_ip_addr => "127.0.0.1",
:tag_string => "hoge foo"
)
VCR.use_cassette("ugoira-converter", :record => :new_episodes) do
VCR.use_cassette("ugoira-converter", :record => :none) do
assert_difference(["Post.count", "PixivUgoiraFrameData.count"]) do
@upload.process!
end