update tests

This commit is contained in:
r888888888
2015-05-28 13:32:36 -07:00
parent 2ddc93723c
commit 66dd4f072e
89 changed files with 65157 additions and 58437 deletions

View File

@@ -2,9 +2,7 @@ require 'test_helper'
module Downloads
class PixivTest < ActiveSupport::TestCase
PHPSESSID = "696859_678b7a07e1fff94719fb6560eed5958f"
def assert_downloaded(expected_filesize, source, cassette, record = :none)
def assert_downloaded(expected_filesize, source, cassette, record = :once)
tempfile = Tempfile.new("danbooru-test")
download = Downloads::File.new(source, tempfile.path)
@@ -17,7 +15,7 @@ module Downloads
assert_equal(expected_filesize, tempfile.size, "Tested source URL: #{source}")
end
def assert_rewritten(expected_source, test_source, cassette, record = :none)
def assert_rewritten(expected_source, test_source, cassette, record = :once)
tempfile = Tempfile.new("danbooru-test")
download = Downloads::File.new(test_source, tempfile.path)
@@ -27,16 +25,21 @@ module Downloads
end
end
def assert_not_rewritten(source, cassette, record = :none)
def assert_not_rewritten(source, cassette, record = :once)
assert_rewritten(source, source, cassette, record)
end
def setup
super
setup_vcr
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("download-ugoira-converter", :record => :none) do
VCR.use_cassette("download-ugoira-converter", :record => :once) do
@download.download!
end
end
@@ -45,20 +48,13 @@ module Downloads
@tempfile.unlink
end
should "download the zip file and update the source" do
should "capture the data" do
assert_equal("http://i3.pixiv.net/img-zip-ugoira/img/2014/10/05/23/42/23/46378654_ugoira1920x1080.zip", @download.source)
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}], @download.data[:ugoira_frame_data])
end
end
context "in all cases" do
setup do
PixivWebAgent.stubs(:phpsessid).returns(PHPSESSID)
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.
@@ -182,10 +178,10 @@ module Downloads
assert_rewritten(@p0_full_size_image, @p0_small_thumbnail, "download-pixiv-old-manga-p0-small-thumbnail")
assert_rewritten(@p0_full_size_image_1, @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")
assert_downloaded(@p0_file_size, @p0_tiny_thumbnail, "download-pixiv-old-manga-p0-tiny-thumbnail-2")
assert_downloaded(@p0_file_size, @p0_small_thumbnail, "download-pixiv-old-manga-p0-small-thumbnail-2")
assert_downloaded(@p0_file_size, @p0_large_thumbnail, "download-pixiv-old-manga-p0-large-thumbnail-2")
assert_downloaded(@p1_file_size, @p1_large_thumbnail, "download-pixiv-old-manga-p1-large-thumbnail-2")
end
should "download the full size image instead of the medium thumbnail" do

View File

@@ -2,44 +2,47 @@
module Sources
class NicoSeigaTest < ActiveSupport::TestCase
def setup
super
setup_vcr
end
context "The source site for nico seiga" do
setup do
Cache.put("nico-seiga-session", "user_session_23669858_ea46b9d1b3e64785a14d5a5d9c6606f5b5c24b4a233835d84362b9820f20a758")
VCR.use_cassette("source-nico-seiga-unit-test-1", :record => :none) do
@site_1 = Sources::Site.new("http://lohas.nicoseiga.jp/o/59c833da35d7bc6586a8292103e5e38c9df23b7c/1417762099/4496506")
VCR.use_cassette("source-nico-seiga-unit-test-1", :record => :once) do
@site_1 = Sources::Site.new("http://lohas.nicoseiga.jp/o/910aecf08e542285862954017f8a33a8c32a8aec/1433298801/4937663")
@site_1.get
end
VCR.use_cassette("source-nico-seiga-unit-test-2", :record => :none) do
@site_2 = Sources::Site.new("http://seiga.nicovideo.jp/seiga/im4496506")
VCR.use_cassette("source-nico-seiga-unit-test-2", :record => :once) do
@site_2 = Sources::Site.new("http://seiga.nicovideo.jp/seiga/im4937663")
@site_2.get
end
end
should "get the profile" do
assert_equal("http://seiga.nicovideo.jp/user/illust/18302053", @site_1.profile_url)
assert_equal("http://seiga.nicovideo.jp/user/illust/18302053", @site_2.profile_url)
assert_equal("http://seiga.nicovideo.jp/user/illust/7017777", @site_1.profile_url)
assert_equal("http://seiga.nicovideo.jp/user/illust/7017777", @site_2.profile_url)
end
should "get the artist name" do
assert_equal("ポテち", @site_1.artist_name)
assert_equal("ポテち", @site_2.artist_name)
assert_equal("osamari", @site_1.artist_name)
assert_equal("osamari", @site_2.artist_name)
end
should "get the image url" do
assert_equal("http://lohas.nicoseiga.jp/priv/99d2b59c51e74b93c41cce3ea82137365f88dcff/1417763778/4496506", @site_1.image_url)
assert_equal("http://lohas.nicoseiga.jp/priv/f28fa72d148505b4f4dc2a72cf5f52d2ecba66b7/1417763873/4496506", @site_2.image_url)
assert_equal("http://lohas.nicoseiga.jp/priv/6dadd39237a6b8d3ab0ba85c0651ffab66e57711/1433298875/4937663", @site_1.image_url)
assert_equal("http://lohas.nicoseiga.jp/priv/0295d92ed5e468ab1b440da6697bb030e5061a3f/1433298877/4937663", @site_2.image_url)
end
should "get the tags" do
assert(@site_1.tags.size > 0)
first_tag = @site_1.tags.first
assert_equal(["オリジナル", "http://seiga.nicovideo.jp/tag/%E3%82%AA%E3%83%AA%E3%82%B8%E3%83%8A%E3%83%AB"], first_tag)
assert_equal(["アニメ", "http://seiga.nicovideo.jp/tag/%E3%82%A2%E3%83%8B%E3%83%A1"], first_tag)
assert(@site_2.tags.size > 0)
first_tag = @site_2.tags.first
assert_equal(["オリジナル", "http://seiga.nicovideo.jp/tag/%E3%82%AA%E3%83%AA%E3%82%B8%E3%83%8A%E3%83%AB"], first_tag)
assert_equal(["アニメ", "http://seiga.nicovideo.jp/tag/%E3%82%A2%E3%83%8B%E3%83%A1"], first_tag)
end
should "convert a page into a json representation" do

View File

@@ -4,9 +4,7 @@ require 'test_helper'
module Sources
class PixivTest < ActiveSupport::TestCase
PHPSESSID = "696859_678b7a07e1fff94719fb6560eed5958f"
def get_source(source, cassette, record = :none)
def get_source(source, cassette, record = :once)
VCR.use_cassette(cassette, :record => record) do
@site = Sources::Site.new(source)
@site.get
@@ -14,14 +12,15 @@ module Sources
end
end
context "in all cases" do
setup do
PixivWebAgent.stubs(:phpsessid).returns(PHPSESSID)
end
def setup
super
setup_vcr
end
context "in all cases" do
context "A gallery page" do
setup do
VCR.use_cassette("pixiv-gallery", :record => :none) do
VCR.use_cassette("pixiv-gallery", :record => :once) do
@site = Sources::Site.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=49270482")
@site.get
@image_urls = @site.image_urls
@@ -35,7 +34,7 @@ module Sources
context "An ugoira source site for pixiv" do
setup do
VCR.use_cassette("ugoira-converter", :record => :none) do
VCR.use_cassette("ugoira-converter", :record => :once) do
@site = Sources::Site.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46378654")
@site.get
end

View File

@@ -2,14 +2,14 @@ require 'test_helper'
module Sources
class TwitterTest < ActiveSupport::TestCase
setup do
Danbooru.config.stubs(:twitter_api_key).returns("xxx")
Danbooru.config.stubs(:twitter_api_secret).returns("xxx")
def setup
super
setup_vcr
end
context "The source site for a restricted twitter" do
setup do
VCR.use_cassette("source-twitter-unit-test-2", :record => :none) do
VCR.use_cassette("source-twitter-unit-test-2", :record => :once) do
@site = Sources::Site.new("https://mobile.twitter.com/Strangestone/status/556440271961858051")
@site.get
end
@@ -22,7 +22,7 @@ module Sources
context "The source site for twitter" do
setup do
VCR.use_cassette("source-twitter-unit-test-1", :record => :none) do
VCR.use_cassette("source-twitter-unit-test-1", :record => :once) do
@site = Sources::Site.new("https://mobile.twitter.com/nounproject/status/540944400767922176")
@site.get
end

View File

@@ -1,6 +1,10 @@
require 'test_helper'
class UploadTest < ActiveSupport::TestCase
def setup
super
end
context "In all cases" do
setup do
user = FactoryGirl.create(:contributor_user)
@@ -87,7 +91,7 @@ class UploadTest < ActiveSupport::TestCase
assert_equal("image/gif", @upload.file_header_to_content_type("#{Rails.root}/test/files/test.gif"))
assert_equal("image/png", @upload.file_header_to_content_type("#{Rails.root}/test/files/test.png"))
assert_equal("application/x-shockwave-flash", @upload.file_header_to_content_type("#{Rails.root}/test/files/compressed.swf"))
assert_equal("application/octet-stream", @upload.file_header_to_content_type("#{Rails.root}/README"))
assert_equal("application/octet-stream", @upload.file_header_to_content_type("#{Rails.root}/README.md"))
end
should "know how to parse jpeg, png, gif, and swf content types" do
@@ -122,7 +126,7 @@ class UploadTest < ActiveSupport::TestCase
end
should "process successfully" do
VCR.use_cassette("ugoira-converter", :record => :none) do
VCR.use_cassette("ugoira-converter-1", :record => :once) do
@upload.download_from_source(@output_file.path)
end
assert_operator(File.size(@output_file.path), :>, 1_000)
@@ -135,7 +139,7 @@ class UploadTest < ActiveSupport::TestCase
@upload = FactoryGirl.create(:source_upload)
path = "#{Rails.root}/tmp/test.download.jpg"
VCR.use_cassette("upload-test-file", :record => :none) do
VCR.use_cassette("upload-test-file", :record => :once) do
assert_nothing_raised {@upload.download_from_source(path)}
assert(File.exists?(path))
assert_equal(8558, File.size(path))
@@ -209,7 +213,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 => :none) do
VCR.use_cassette("upload-test-file", :record => :once) do
@upload.process!
end
@@ -230,7 +234,7 @@ class UploadTest < ActiveSupport::TestCase
end
should "create an artist commentary when processed" do
VCR.use_cassette("upload-test-file", :record => :none) do
VCR.use_cassette("upload-test-file", :record => :once) do
assert_difference("ArtistCommentary.count") do
@upload.process!
end
@@ -245,7 +249,7 @@ class UploadTest < ActiveSupport::TestCase
:tag_string => "hoge foo"
)
assert_difference("Post.count") do
VCR.use_cassette("upload-test-file", :record => :none) do
VCR.use_cassette("upload-test-file", :record => :once) do
assert_nothing_raised {@upload.process!}
end
end
@@ -273,7 +277,7 @@ class UploadTest < ActiveSupport::TestCase
:uploader_ip_addr => "127.0.0.1",
:tag_string => "hoge foo"
)
VCR.use_cassette("ugoira-converter", :record => :none) do
VCR.use_cassette("ugoira-converter-2", :record => :once) do
assert_difference(["Post.count", "PixivUgoiraFrameData.count"]) do
@upload.process!
assert_equal([], @upload.errors.full_messages)