Rewrite tests for downloading new Pixiv URLs.

* Test that downloading the HTML page downloads the full size image
  instead.
* Test that downloading a small or medium size image downloads the
  full size instead.
* Test the above for both single illustrations and for manga galleries,
  for new and old posts (i.e. uploaded before the Pixiv URL changes versus
  after), and for different file extensions.
* Test trying to download ugoira zip files. These tests are expected to
  fail because we don't support ugoira yet.
* Also add some more tests for fetching source data.
This commit is contained in:
evazion
2014-09-27 00:48:07 -05:00
parent 268f79c3d9
commit 339e88584d
2 changed files with 310 additions and 53 deletions

View File

@@ -4,32 +4,41 @@ require 'test_helper'
module Sources
class PixivTest < ActiveSupport::TestCase
context "The source site for pixiv" do
def get_source(source, cassette)
VCR.use_cassette(cassette, :record => :once) do
@site = Sources::Site.new(source)
@site.get
@site
end
end
context "fetching source data for a new manga image" do
setup do
VCR.use_cassette("source-pixiv-unit-test", :record => :new_episodes) do
@site = Sources::Site.new("http://www.pixiv.net/member_illust.php?mode=big&illust_id=9646484")
@site.get
end
get_source("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46324488", "source-pixiv-new-manga")
end
should "get the profile" do
assert_equal("http://www.pixiv.net/member.php?id=4015", @site.profile_url)
assert_equal("http://www.pixiv.net/member.php?id=339253", @site.profile_url)
end
should "get the artist name" do
assert_equal("シビレ罠", @site.artist_name)
assert_equal("evazion", @site.artist_name)
end
should "get the image url" do
assert_equal("http://i1.pixiv.net/img01/img/nisieda/9646484.jpg", @site.image_url)
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 page count" do
assert_equal(3, @site.page_count)
end
should "get the tags" do
assert(@site.tags.size > 0)
first_tag = @site.tags.first
assert_equal(2, first_tag.size)
assert(first_tag[0] =~ /./)
assert(first_tag[1] =~ /search\.php/)
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
@@ -38,5 +47,55 @@ module Sources
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")
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
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
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/)
end
end
end
end