tinami/pixa downloads now supported

This commit is contained in:
albert
2011-09-30 14:27:04 -04:00
parent 2287bc8d61
commit aa2b65c48b
13 changed files with 326 additions and 170 deletions

View File

@@ -1,54 +0,0 @@
require 'test_helper'
class DownloadTest < ActiveSupport::TestCase
context "A post download" do
setup do
@source = "http://www.google.com/intl/en_ALL/images/logo.gif"
@tempfile = Tempfile.new("danbooru-test")
@download = Download.new(@source, @tempfile.path)
end
teardown do
@tempfile.close
end
should "stream a file from an HTTP source" do
@download.http_get_streaming do |resp|
assert_equal("200", resp.code)
assert(resp["Content-Length"].to_i > 0, "File should be larger than 0 bytes")
end
end
should "throw an exception when the file is larger than the maximum" do
assert_raise(Download::Error) do
@download.http_get_streaming(:max_size => 1) do |resp|
end
end
end
should "store the file in the tempfile path" do
@download.download!
assert_equal(@source, @download.source)
assert(File.exists?(@tempfile.path), "temp file should exist")
assert(File.size(@tempfile.path) > 0, "should have data")
end
should "initialize the content type" do
@download.download!
assert_match(/image\/gif/, @download.content_type)
end
end
context "a post download for a pixiv manga page" do
setup do
@source = "http://img65.pixiv.net/img/kiyoringo/21755794_p2.png"
@tempfile = Tempfile.new("danbooru-test")
@download = Download.new(@source, @tempfile.path)
end
should "download the big version" do
@download.download!
assert_equal("http://img65.pixiv.net/img/kiyoringo/21755794_big_p2.png", @download.source)
end
end
end

View File

@@ -0,0 +1,43 @@
require 'test_helper'
module Downloads
class FileTest < ActiveSupport::TestCase
context "A post download" do
setup do
@source = "http://www.google.com/intl/en_ALL/images/logo.gif"
@tempfile = Tempfile.new("danbooru-test")
@download = Downloads::File.new(@source, @tempfile.path)
end
teardown do
@tempfile.close
end
should "stream a file from an HTTP source" do
@download.http_get_streaming do |resp|
assert_equal("200", resp.code)
assert(resp["Content-Length"].to_i > 0, "File should be larger than 0 bytes")
end
end
should "throw an exception when the file is larger than the maximum" do
assert_raise(Downloads::File::Error) do
@download.http_get_streaming(:max_size => 1) do |resp|
end
end
end
should "store the file in the tempfile path" do
@download.download!
assert_equal(@source, @download.source)
assert(::File.exists?(@tempfile.path), "temp file should exist")
assert(::File.size(@tempfile.path) > 0, "should have data")
end
should "initialize the content type" do
@download.download!
assert_match(/image\/gif/, @download.content_type)
end
end
end
end

View File

@@ -0,0 +1,18 @@
require 'test_helper'
module Downloads
class NicoSeigaTest < ActiveSupport::TestCase
context "a download for a pixa image" do
setup do
@source = "http://img.tinami.com/illust2/img/330/4e85ecd880a8f.jpg"
@tempfile = Tempfile.new("danbooru-test")
@download = Downloads::File.new(@source, @tempfile.path)
end
should "work" do
@download.download!
assert_equal(201248, ::File.size(@tempfile.path))
end
end
end
end

View File

@@ -0,0 +1,18 @@
require 'test_helper'
module Downloads
class PixaTest < ActiveSupport::TestCase
context "a download for a pixa image" do
setup do
@source = "http://file0.pixa.cc/illustrations/6f/d6/3f/f9/51/61/29/72/23/ac/middle/sse.jpg?1317405928"
@tempfile = Tempfile.new("danbooru-test")
@download = Downloads::File.new(@source, @tempfile.path)
end
should "work" do
@download.download!
assert_equal(104627, ::File.size(@tempfile.path))
end
end
end
end

View File

@@ -0,0 +1,35 @@
require 'test_helper'
module Downloads
class PixivTest < ActiveSupport::TestCase
context "a download for a pixiv manga page" do
setup do
@source = "http://img65.pixiv.net/img/kiyoringo/21755794_p2.png"
@tempfile = Tempfile.new("danbooru-test")
@download = Downloads::File.new(@source, @tempfile.path)
@download.download!
end
should "instead download the big version" do
assert_equal("http://img65.pixiv.net/img/kiyoringo/21755794_big_p2.png", @download.source)
end
end
context "a download for a small image" do
setup do
@source = "http://img02.pixiv.net/img/wanwandoh/4348318_m.jpg"
@tempfile = Tempfile.new("danbooru-test")
@download = Downloads::File.new(@source, @tempfile.path)
@download.download!
end
should "instead download the original version" do
assert_equal("http://img02.pixiv.net/img/wanwandoh/4348318.jpg", @download.source)
end
should "work" do
assert_equal(185778, ::File.size(@tempfile.path))
end
end
end
end

View File

@@ -0,0 +1,18 @@
require 'test_helper'
module Downloads
class TinamiTest < ActiveSupport::TestCase
context "a download for a pixa image" do
setup do
@source = "http://img.tinami.com/illust2/img/330/4e85ecd880a8f.jpg"
@tempfile = Tempfile.new("danbooru-test")
@download = Downloads::File.new(@source, @tempfile.path)
end
should "work" do
@download.download!
assert_equal(201248, ::File.size(@tempfile.path))
end
end
end
end