Moebooru: rewrite tests

This commit is contained in:
nonamethanks
2022-10-08 16:10:39 +02:00
parent f4b14ba23e
commit 79a9081efa

View File

@@ -2,111 +2,105 @@ require "test_helper"
module Sources module Sources
class MoebooruTest < ActiveSupport::TestCase class MoebooruTest < ActiveSupport::TestCase
def assert_source_data_equals(url, referer = nil, site_name: nil, image_url: nil, page_url: nil, size: nil, tags: [], profile_url: nil, **params) context "For Yande.re," do
site = Source::Extractor.find(url, referer) context "a post" do
strategy_should_work(
assert_equal(site_name, site.site_name) "https://yande.re/post/show/482880",
assert_equal([image_url], site.image_urls) image_urls: ["https://files.yande.re/image/7ecfdead705d7b956b26b1d37b98d089/yande.re%20482880.jpg"],
assert_equal(page_url, site.page_url) if page_url.present? download_size: 362_554,
assert_equal(tags.sort, site.tags.map(&:first).sort) tags: ["bayashiko", "journey_to_the_west", "sun_wukong"],
assert_equal(profile_url.to_s, site.profile_url.to_s) page_url: "https://yande.re/post/show/482880",
assert_nothing_raised { site.to_h } profile_url: "https://twitter.com/apononori"
end )
context "Yande.re:" do
context "A 'https://yande.re/jpeg/:hash/:file.jpg' jpeg sample url" do
should "download the original file" do
@source = "https://yande.re/jpeg/2c6876ac2317fce617e3c5f1a642123b/yande.re%20292092%20hatsune_miku%20tid%20vocaloid.jpg"
@rewrite = "https://files.yande.re/image/2c6876ac2317fce617e3c5f1a642123b/yande.re%20292092.png"
assert_rewritten(@rewrite, @source)
assert_downloaded(1_050_117, @source)
end
end end
context "Fetching data for an active yande.re .jpg post" do context "a https://yande.re/sample/:hash/:file.jpg" do
should "work" do strategy_should_work(
@samp = "https://files.yande.re/sample/7ecfdead705d7b956b26b1d37b98d089/yande.re%20482880%20sample%20bayashiko%20journey_to_the_west%20sun_wukong.jpg" "https://files.yande.re/sample/7ecfdead705d7b956b26b1d37b98d089/yande.re%20482880%20sample%20bayashiko%20journey_to_the_west%20sun_wukong.jpg",
@full = "https://files.yande.re/image/7ecfdead705d7b956b26b1d37b98d089/yande.re%20482880.jpg" image_urls: ["https://files.yande.re/image/7ecfdead705d7b956b26b1d37b98d089/yande.re%20482880.jpg"],
@page = "https://yande.re/post/show/482880" download_size: 362_554,
@tags = ["bayashiko", "journey_to_the_west", "sun_wukong"] tags: ["bayashiko", "journey_to_the_west", "sun_wukong"],
@size = 362_554 page_url: "https://yande.re/post/show/482880",
@profile_url = "https://twitter.com/apononori" profile_url: "https://twitter.com/apononori"
@data = { site_name: "Yande.re", image_url: @full, page_url: @page, size: @size, tags: @tags, profile_url: @profile_url } )
assert_source_data_equals(@samp, **@data)
assert_source_data_equals(@full, **@data)
assert_source_data_equals(@page, **@data)
end
end end
context "Fetching data for a deleted yande.re .png post with the post id" do context "a 'https://yande.re/jpeg/:hash/:file.jpg' jpeg sample url" do
should "work" do strategy_should_work(
@samp = "https://files.yande.re/sample/fb27a7ea6c48b2ef76fe915e378b9098/yande.re%20398018%20detexted%20misaki_kurehito%20saenai_heroine_no_sodatekata%20sawamura_spencer_eriri%20thighhighs.jpg" "https://yande.re/jpeg/2c6876ac2317fce617e3c5f1a642123b/yande.re%20292092%20hatsune_miku%20tid%20vocaloid.jpg",
@jpeg = "https://files.yande.re/sample/fb27a7ea6c48b2ef76fe915e378b9098/yande.re%20398018%20detexted%20misaki_kurehito%20saenai_heroine_no_sodatekata%20sawamura_spencer_eriri%20thighhighs.jpg" image_urls: ["https://files.yande.re/image/2c6876ac2317fce617e3c5f1a642123b/yande.re%20292092.png"],
@full = "https://files.yande.re/image/fb27a7ea6c48b2ef76fe915e378b9098/yande.re%20398018.png" download_size: 1_050_117
@page = "https://yande.re/post/show/398018" )
@tags = ["misaki_kurehito", "saenai_heroine_no_sodatekata", "sawamura_spencer_eriri", "detexted", "thighhighs"]
@size = 9_118_998
@data = { site_name: "Yande.re", image_url: @full, page_url: @page, size: @size, tags: @tags, profile_url: nil }
assert_source_data_equals(@samp, **@data)
assert_source_data_equals(@jpeg, **@data)
assert_source_data_equals(@full, **@data)
assert_source_data_equals(@page, **@data)
end
end end
context "Fetching data for a deleted yande.re .png post without the post id" do context "a deleted yande.re post with the post id" do
should "work" do strategy_should_work(
@samp = "https://files.yande.re/sample/fb27a7ea6c48b2ef76fe915e378b9098.jpg" "https://files.yande.re/sample/fb27a7ea6c48b2ef76fe915e378b9098/yande.re%20398018%20detexted%20misaki_kurehito%20saenai_heroine_no_sodatekata%20sawamura_spencer_eriri%20thighhighs.jpg",
@jpeg = "https://files.yande.re/jpeg/fb27a7ea6c48b2ef76fe915e378b9098.jpg" image_urls: ["https://files.yande.re/image/fb27a7ea6c48b2ef76fe915e378b9098/yande.re%20398018.png"],
@full = "https://files.yande.re/image/fb27a7ea6c48b2ef76fe915e378b9098.png" page_url: "https://yande.re/post/show/398018",
@tags = [] tags: ["misaki_kurehito", "saenai_heroine_no_sodatekata", "sawamura_spencer_eriri", "detexted", "thighhighs"],
@size = 9_118_998 download_size: 9_118_998
@data = { site_name: "Yande.re", image_url: @full, page_url: @page, size: @size, tags: @tags, profile_url: nil } )
assert_source_data_equals(@samp, **@data)
assert_source_data_equals(@jpeg, **@data)
assert_source_data_equals(@full, **@data)
end
end end
context "When the referer URL is SauceNao" do context "a deleted yande.re post without the post id" do
should "ignore the referer" do strategy_should_work(
@url = "https://yande.re/post/show/469929" "https://files.yande.re/jpeg/fb27a7ea6c48b2ef76fe915e378b9098.jpg",
@ref = "https://saucenao.com/" image_urls: ["https://files.yande.re/image/fb27a7ea6c48b2ef76fe915e378b9098.png"],
download_size: 9_118_998
)
end
assert_source_data_equals(@url, @ref, context "a yande.re post with a saucenao referer" do
site_name: "Yande.re", strategy_should_work(
image_url: "https://files.yande.re/image/36b031b266605d89aed2b62d479e64b1/yande.re%20469929.jpg", "https://yande.re/post/show/469929",
page_url: "https://yande.re/post/show/469929", referer: "https://saucenao.com",
tags: %w[anchovy bandages darjeeling girls_und_panzer katyusha kay_(girls_und_panzer) mika_(girls_und_panzer) nishi_kinuyo nishizumi_maho nishizumi_miho shimada_arisu uniform], image_urls: ["https://files.yande.re/image/36b031b266605d89aed2b62d479e64b1/yande.re%20469929.jpg"],
) page_url: "https://yande.re/post/show/469929",
end tags: %w[anchovy bandages darjeeling girls_und_panzer katyusha kay_(girls_und_panzer) mika_(girls_und_panzer) nishi_kinuyo nishizumi_maho nishizumi_miho shimada_arisu uniform]
)
end end
end end
context "Konachan.com:" do context "For konachan.com," do
context "Fetching data for an active konachan.com .png post" do context "a sample url" do
should "work" do strategy_should_work(
@samp = "https://konachan.com/sample/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916%20sample.jpg" "https://konachan.com/sample/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916%20sample.jpg",
@jpeg = "https://konachan.com/jpeg/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916%20anthropomorphism%20bed%20blonde_hair%20bow%20brown_eyes%20doll%20girls_frontline%20hara_shoutarou%20hoodie%20long_hair%20pantyhose%20scar%20skirt%20twintails.jpg" image_urls: ["https://konachan.com/image/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916.png"],
@full = "https://konachan.com/image/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916.png" download_size: 8_167_593,
@page = "https://konachan.com/post/show/270916" tags: %w[anthropomorphism bed blonde_hair bow brown_eyes doll girls_frontline hara_shoutarou hoodie long_hair pantyhose scar skirt twintails ump-45_(girls_frontline) ump-9_(girls_frontline)],
@size = 8_167_593 profile_url: "https://www.pixiv.net/users/22528152"
@tags = %w[ )
anthropomorphism bed blonde_hair bow brown_eyes doll end
girls_frontline hara_shoutarou hoodie long_hair pantyhose scar skirt
twintails ump-45_(girls_frontline) ump-9_(girls_frontline)
]
@profile_url = "https://www.pixiv.net/users/22528152"
@data = { site_name: "Konachan", image_url: @full, page_url: @page, size: @size, tags: @tags, profile_url: @profile_url } context "a jpeg url" do
assert_source_data_equals(@samp, **@data) strategy_should_work(
assert_source_data_equals(@jpeg, **@data) "https://konachan.com/jpeg/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916%20anthropomorphism%20bed%20blonde_hair%20bow%20brown_eyes%20doll%20girls_frontline%20hara_shoutarou%20hoodie%20long_hair%20pantyhose%20scar%20skirt%20twintails.jpg",
assert_source_data_equals(@full, **@data) image_urls: ["https://konachan.com/image/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916.png"],
assert_source_data_equals(@page, **@data) download_size: 8_167_593,
end tags: %w[anthropomorphism bed blonde_hair bow brown_eyes doll girls_frontline hara_shoutarou hoodie long_hair pantyhose scar skirt twintails ump-45_(girls_frontline) ump-9_(girls_frontline)],
profile_url: "https://www.pixiv.net/users/22528152"
)
end
context "a full-size image url" do
strategy_should_work(
"https://konachan.com/image/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916.png",
image_urls: ["https://konachan.com/image/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916.png"],
download_size: 8_167_593,
tags: %w[anthropomorphism bed blonde_hair bow brown_eyes doll girls_frontline hara_shoutarou hoodie long_hair pantyhose scar skirt twintails ump-45_(girls_frontline) ump-9_(girls_frontline)],
profile_url: "https://www.pixiv.net/users/22528152"
)
end
context "a post url" do
strategy_should_work(
"https://konachan.com/post/show/270916",
image_urls: ["https://konachan.com/image/ca12cdb79a66d242e95a6f958341bf05/Konachan.com%20-%20270916.png"],
download_size: 8_167_593,
tags: %w[anthropomorphism bed blonde_hair bow brown_eyes doll girls_frontline hara_shoutarou hoodie long_hair pantyhose scar skirt twintails ump-45_(girls_frontline) ump-9_(girls_frontline)],
profile_url: "https://www.pixiv.net/users/22528152"
)
end end
end end