Pixiv Sketch: rewrite tests

This commit is contained in:
nonamethanks
2022-10-21 11:09:10 +02:00
parent 8008b7a5a2
commit 1b11321161

View File

@@ -2,83 +2,62 @@ require 'test_helper'
module Sources module Sources
class PixivSketchTest < ActiveSupport::TestCase class PixivSketchTest < ActiveSupport::TestCase
context "A Pixiv Sketch source" do context "A Pixiv Sketch post" do
should "work for a post with a single image" do strategy_should_work(
source = Source::Extractor.find("https://sketch.pixiv.net/items/5835314698645024323") "https://sketch.pixiv.net/items/5835314698645024323",
image_urls: ["https://img-sketch.pixiv.net/uploads/medium/file/9986983/8431631593768139653.jpg"],
assert_equal("Pixiv Sketch", source.site_name) page_url: "https://sketch.pixiv.net/items/5835314698645024323",
assert_equal(["https://img-sketch.pixiv.net/uploads/medium/file/9986983/8431631593768139653.jpg"], source.image_urls) profile_urls: ["https://sketch.pixiv.net/@user_ejkv8372", "https://www.pixiv.net/users/44772126"],
assert_equal("https://sketch.pixiv.net/items/5835314698645024323", source.page_url) profile_url: "https://sketch.pixiv.net/@user_ejkv8372",
assert_equal("https://sketch.pixiv.net/@user_ejkv8372", source.profile_url) artist_name: "user_ejkv8372",
assert_equal(["https://sketch.pixiv.net/@user_ejkv8372", "https://www.pixiv.net/users/44772126"], source.profile_urls) other_names: ["user_ejkv8372", "サコ"],
assert_equal("user_ejkv8372", source.artist_name) artist_commentary_desc: "🍻シャンクスとミホーク誕生日おめでとう🍻(過去絵) ",
assert_equal(["user_ejkv8372", "サコ"], source.other_names) tags: []
assert_equal("🍻シャンクスとミホーク誕生日おめでとう🍻(過去絵) ", source.artist_commentary_desc) )
assert_equal([], source.tags.map(&:first))
assert_nothing_raised { source.to_h }
end end
should "work for an image url without a referer" do context "A Pixiv Sketch image with referer" do
strategy_should_work(
"https://img-sketch.pixiv.net/uploads/medium/file/9986983/8431631593768139653.jpg",
referer: "https://sketch.pixiv.net/items/5835314698645024323",
image_urls: ["https://img-sketch.pixiv.net/uploads/medium/file/9986983/8431631593768139653.jpg"],
page_url: "https://sketch.pixiv.net/items/5835314698645024323",
profile_urls: ["https://sketch.pixiv.net/@user_ejkv8372", "https://www.pixiv.net/users/44772126"],
profile_url: "https://sketch.pixiv.net/@user_ejkv8372",
artist_name: "user_ejkv8372",
other_names: ["user_ejkv8372", "サコ"],
artist_commentary_desc: "🍻シャンクスとミホーク誕生日おめでとう🍻(過去絵) ",
tags: []
)
end
context "A Pixiv Sketch image without the referer" do
# page: https://sketch.pixiv.net/items/8052785510155853613 # page: https://sketch.pixiv.net/items/8052785510155853613
source = Source::Extractor.find("https://img-sketch.pixiv.net/uploads/medium/file/9988973/7216948861306830496.jpg") strategy_should_work(
"https://img-sketch.pixiv.net/uploads/medium/file/9988973/7216948861306830496.jpg",
assert_equal(["https://img-sketch.pixiv.net/uploads/medium/file/9988973/7216948861306830496.jpg"], source.image_urls) page_url: nil,
assert_nil(source.page_url) profile_url: nil,
assert_nil(source.profile_url) artist_name: nil,
assert_equal([], source.profile_urls) tags: [],
assert_nil(source.artist_name) artist_commentary_desc: nil
assert_equal([], source.other_names) )
assert_nil(source.artist_commentary_desc)
assert_equal([], source.tags.map(&:first))
assert_nothing_raised { source.to_h }
end end
should "work for an image url with a referer" do context "A NSFW post" do
source = Source::Extractor.find("https://img-sketch.pixiv.net/uploads/medium/file/9988973/7216948861306830496.jpg", "https://sketch.pixiv.net/items/8052785510155853613") strategy_should_work(
"https://sketch.pixiv.net/items/193462611994864256",
assert_equal("https://sketch.pixiv.net/items/8052785510155853613", source.page_url) image_urls: ["https://img-sketch.pixiv.net/uploads/medium/file/884876/4909517173982299587.jpg"],
assert_equal("https://sketch.pixiv.net/@op-one", source.profile_url) page_url: "https://sketch.pixiv.net/items/193462611994864256",
assert_equal(["https://sketch.pixiv.net/@op-one", "https://www.pixiv.net/users/5903369"], source.profile_urls) profile_url: "https://sketch.pixiv.net/@lithla",
assert_equal("op-one", source.artist_name) artist_name: "lithla",
assert_equal(["op-one", "俺P"], source.other_names) other_names: ["lithla", "リリスラウダ"],
assert_match(/\A3月3日は「うさぎの日」らしいので/, source.artist_commentary_desc) artist_commentary_desc: "チビッコ露出プレイ ピース",
assert_equal(%w[制作過程 このすば この素晴らしい世界に祝福を セナ バニー 3月3日 巨乳 黒髪巨乳 タイツ], source.tags.map(&:first)) tags: []
assert_nothing_raised { source.to_h } )
end end
should "work for a NSFW post" do context "A post with multiple images" do
source = Source::Extractor.find("https://sketch.pixiv.net/items/193462611994864256") desc = <<~EOS.normalize_whitespace
assert_equal(["https://img-sketch.pixiv.net/uploads/medium/file/884876/4909517173982299587.jpg"], source.image_urls)
assert_equal("https://sketch.pixiv.net/items/193462611994864256", source.page_url)
assert_equal("https://sketch.pixiv.net/@lithla", source.profile_url)
assert_equal(["https://sketch.pixiv.net/@lithla", "https://www.pixiv.net/users/4957"], source.profile_urls)
assert_equal("lithla", source.artist_name)
assert_equal(["lithla", "リリスラウダ"], source.other_names)
assert_equal("チビッコ露出プレイ ピース", source.artist_commentary_desc)
assert_equal([], source.tags.map(&:first))
assert_nothing_raised { source.to_h }
end
should "work for a post with a multiple images" do
source = Source::Extractor.find("https://sketch.pixiv.net/items/8052785510155853613")
assert_equal(%w[
https://img-sketch.pixiv.net/uploads/medium/file/9988964/1564052114639195387.png
https://img-sketch.pixiv.net/uploads/medium/file/9988965/3187185972065199018.png
https://img-sketch.pixiv.net/uploads/medium/file/9988966/5281789458380074490.png
https://img-sketch.pixiv.net/uploads/medium/file/9988967/8187710652175488805.png
https://img-sketch.pixiv.net/uploads/medium/file/9988968/3497441770651131427.png
https://img-sketch.pixiv.net/uploads/medium/file/9988969/1770110164450415039.png
https://img-sketch.pixiv.net/uploads/medium/file/9988970/1340350233137289970.png
https://img-sketch.pixiv.net/uploads/medium/file/9988971/9105451079763734305.jpg
https://img-sketch.pixiv.net/uploads/medium/file/9988972/2641925439408057307.jpg
https://img-sketch.pixiv.net/uploads/medium/file/9988973/7216948861306830496.jpg
], source.image_urls)
assert_equal("https://sketch.pixiv.net/items/8052785510155853613", source.page_url)
assert_equal("https://sketch.pixiv.net/@op-one", source.profile_url)
assert_equal("op-one", source.artist_name)
assert_equal(<<~EOS.normalize_whitespace, source.artist_commentary_desc)
33 33
@@ -127,8 +106,26 @@ module Sources
#タイツ #タイツ
EOS EOS
assert_equal(%w[制作過程 このすば この素晴らしい世界に祝福を セナ バニー 3月3日 巨乳 黒髪巨乳 タイツ], source.tags.map(&:first)) strategy_should_work(
assert_nothing_raised { source.to_h } "https://sketch.pixiv.net/items/8052785510155853613",
image_urls: %w[
https://img-sketch.pixiv.net/uploads/medium/file/9988964/1564052114639195387.png
https://img-sketch.pixiv.net/uploads/medium/file/9988965/3187185972065199018.png
https://img-sketch.pixiv.net/uploads/medium/file/9988966/5281789458380074490.png
https://img-sketch.pixiv.net/uploads/medium/file/9988967/8187710652175488805.png
https://img-sketch.pixiv.net/uploads/medium/file/9988968/3497441770651131427.png
https://img-sketch.pixiv.net/uploads/medium/file/9988969/1770110164450415039.png
https://img-sketch.pixiv.net/uploads/medium/file/9988970/1340350233137289970.png
https://img-sketch.pixiv.net/uploads/medium/file/9988971/9105451079763734305.jpg
https://img-sketch.pixiv.net/uploads/medium/file/9988972/2641925439408057307.jpg
https://img-sketch.pixiv.net/uploads/medium/file/9988973/7216948861306830496.jpg
],
artist_commentary_desc: desc,
artist_name: "op-one",
page_url: "https://sketch.pixiv.net/items/8052785510155853613",
profile_url: "https://sketch.pixiv.net/@op-one",
tags: %w[制作過程 このすば この素晴らしい世界に祝福を セナ バニー 3月3日 巨乳 黒髪巨乳 タイツ]
)
end end
should "Parse Pixiv Sketch URLs correctly" do should "Parse Pixiv Sketch URLs correctly" do
@@ -140,4 +137,3 @@ module Sources
end end
end end
end end
end