fix source tests

This commit is contained in:
r888888888
2017-11-20 12:29:35 -08:00
parent e21f7c14db
commit 9d5e4f969f
6 changed files with 25 additions and 23 deletions

View File

@@ -17,6 +17,8 @@ module Sources
end
def initialize(url, referer_url: nil)
@url = url
Site.strategies.each do |strategy|
if strategy.url_match?(url) || strategy.url_match?(referer_url)
@strategy = strategy.new(url, referer_url)

View File

@@ -9,11 +9,11 @@ module Sources
end
should "get the image url" do
assert_equal("https://cdna.artstation.com/p/assets/images/images/000/705/368/original/jey-rain-one1.jpg", @site.image_url.sub(/\?\d+/, ""))
assert_equal("https://cdna.artstation.com/p/assets/images/images/000/705/368/large/jey-rain-one1.jpg", @site.image_url.sub(/\?\d+/, ""))
end
should "get the profile" do
assert_equal("https://www.artstation.com/artist/jeyrain", @site.profile_url)
assert_equal("https://www.artstation.com/jeyrain", @site.profile_url)
end
should "get the artist name" do
@@ -37,12 +37,12 @@ module Sources
end
should "get the image url" do
url = "https://cdna.artstation.com/p/assets/images/images/006/066/534/original/yinan-cui-reika.jpg?1495781565"
url = "https://cdna.artstation.com/p/assets/images/images/006/066/534/large/yinan-cui-reika.jpg?1495781565"
assert_equal(url, @site.image_url)
end
should "get the profile" do
assert_equal("https://www.artstation.com/artist/dantewontdie", @site.profile_url)
assert_equal("https://www.artstation.com/dantewontdie", @site.profile_url)
end
should "get the artist name" do
@@ -66,7 +66,7 @@ module Sources
end
should "get the image url" do
url = "https://cdna.artstation.com/p/assets/images/images/000/144/922/original/cassio-yoshiyaki-cody2backup2-yoshiyaki.jpg?1406314198"
url = "https://cdna.artstation.com/p/assets/images/images/000/144/922/large/cassio-yoshiyaki-cody2backup2-yoshiyaki.jpg?1406314198"
assert_equal(url, @site.image_url)
end
end
@@ -91,7 +91,7 @@ module Sources
end
should "get only image urls, not video urls" do
urls = %w[https://cdnb.artstation.com/p/assets/images/images/006/037/253/original/astri-lohne-sjursen-eva.jpg?1495573664]
urls = %w[https://cdnb.artstation.com/p/assets/images/images/006/037/253/large/astri-lohne-sjursen-eva.jpg?1495573664]
assert_equal(urls, @site.image_urls)
end
end

View File

@@ -9,6 +9,7 @@ module Sources
@site = Sources::Site.new("http://nijie.info/view.php?id=213043")
@site.get
sleep(5)
end
should "get the image url" do

View File

@@ -58,30 +58,30 @@ module Sources
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=46304614")
get_source("https://www.pixiv.net/member_illust.php?mode=medium&illust_id=65981735")
end
should "get the profile" do
assert_equal("http://www.pixiv.net/member.php?id=339253", @site.profile_url)
assert_equal("http://www.pixiv.net/member.php?id=696859", @site.profile_url)
end
should "get the artist name" do
assert_equal("evazion", @site.artist_name)
assert_equal("uroobnad", @site.artist_name)
end
should "get the full size image url" do
assert_equal("https://i.pximg.net/img-original/img/2014/10/02/14/21/39/46304614_p0.gif", @site.image_url)
assert_equal("https://i.pximg.net/img-original/img/2017/11/21/05/12/37/65981735_p0.jpg", @site.image_url)
end
should "get the page count" do
assert_equal(3, @site.image_urls.size)
assert_equal(1, @site.image_urls.size)
end
should "get the tags" do
pixiv_tags = @site.tags.map(&:first)
pixiv_links = @site.tags.map(&:last)
assert_equal(%w[漫画 Fate/GrandOrder foo FOO 風景10users入り 伊19/陸奥 鉛筆], pixiv_tags)
assert_equal(%w[漫画 test], pixiv_tags)
assert_contains(pixiv_links, /search\.php/)
end
@@ -129,10 +129,10 @@ module Sources
context "fetching the commentary" do
should "work when the description is blank" do
get_source("https://www.pixiv.net/member_illust.php?mode=medium&illust_id=46337015")
get_source("https://www.pixiv.net/member_illust.php?mode=medium&illust_id=65981746")
assert_equal("Illustration (PNG) - foo & bar", @site.dtext_artist_commentary_title)
assert_equal("", @site.dtext_artist_commentary_desc)
assert_equal("title", @site.dtext_artist_commentary_title)
assert_equal("desc", @site.dtext_artist_commentary_desc)
end
should "convert illust links and member links to dtext" do
@@ -163,18 +163,18 @@ module Sources
FactoryGirl.create(:wiki_page, title: tag, other_names: other_names)
end
@site = get_source("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46304614")
@site = get_source("https://www.pixiv.net/member_illust.php?mode=medium&illust_id=65981746")
@tags = @site.tags.map(&:first)
@translated_tags = @site.translated_tags.map(&:first)
end
should "get the original tags" do
assert_equal(%w[漫画 Fate/GrandOrder foo FOO 風景10users入り 伊19/陸奥 鉛筆], @tags)
assert_equal(["test", "風景", "Fate/GrandOrder", "伊19/陸奥", "鉛筆", "風景10users入り", "foo", "FOO"], @tags)
end
should "translate the tag if it matches a wiki other name" do
assert_includes(@tags, "漫画")
assert_includes(@translated_tags, "comic")
assert_includes(@tags, "風景")
assert_includes(@translated_tags, "scenery")
end
should "return the same tag if it doesn't match a wiki other name but it does match a tag" do

View File

@@ -93,7 +93,7 @@ module Sources
context "The source for a 'http://*.media.tumblr.com/$hash/tumblr_$id_1280.jpg' image with a referer" do
setup do
@url = "https://68.media.tumblr.com/7c4d2c6843466f92c3dd0516e749ec35/tumblr_orwwptNBCE1wsfqepo2_1280.jpg"
@url = "https://78.media.tumblr.com/7c4d2c6843466f92c3dd0516e749ec35/tumblr_orwwptNBCE1wsfqepo2_1280.jpg"
@ref = "https://noizave.tumblr.com/post/162094447052"
@site = Sources::Site.new(@url, referer_url: @ref)
@site.get
@@ -139,7 +139,6 @@ module Sources
should "get the commentary" do
desc = %r!<p>description</p><figure class="tmblr-full" data-orig-height="3000" data-orig-width="3000"><img src="https://\d+.media.tumblr.com/afed9f5b3c33c39dc8c967e262955de2/tumblr_inline_os2zhkfhY01v11u29_540.png" data-orig-height="3000" data-orig-width="3000"/></figure><figure class="tmblr-full" data-orig-height="3000" data-orig-width="3000"><img src="https://\d+.media.tumblr.com/7c4d2c6843466f92c3dd0516e749ec35/tumblr_inline_os2zkg02xH1v11u29_540.jpg" data-orig-height="3000" data-orig-width="3000"/></figure>!
assert_equal("test post", @site.artist_commentary_title)
assert_match(desc, @site.artist_commentary_desc)
end

View File

@@ -26,12 +26,12 @@ module Sources
context "A twitter summary card" do
setup do
@site = Sources::Site.new("https://twitter.com/NatGeo/status/931235536299274241")
@site = Sources::Site.new("https://twitter.com/NatGeo/status/932700115936178177")
@site.get
end
should "get the image url" do
assert_equal("https://pmdvod.nationalgeographic.com/NG_Video/535/155/smpost_1510787765334.jpg", @site.image_url)
assert_equal("https://pmdvod.nationalgeographic.com/NG_Video/205/302/smpost_1510342850295.jpg", @site.image_url)
end
end