Hentai-Foundry: rewrite tests

This commit is contained in:
nonamethanks
2022-10-07 22:22:24 +02:00
parent 1dc60feeb7
commit da46b13a64

View File

@@ -2,99 +2,60 @@ require 'test_helper'
module Sources module Sources
class HentaiFoundryTest < ActiveSupport::TestCase class HentaiFoundryTest < ActiveSupport::TestCase
context "The source for a hentai foundry picture" do context "A hentai-foundry post" do
setup do strategy_should_work(
@image_1 = Source::Extractor.find("https://www.hentai-foundry.com/pictures/user/Afrobull/795025/kuroeda") "https://www.hentai-foundry.com/pictures/user/Afrobull/795025/kuroeda",
@image_2 = Source::Extractor.find("https://pictures.hentai-foundry.com/a/Afrobull/795025/Afrobull-795025-kuroeda.png") image_urls: ["https://pictures.hentai-foundry.com/a/Afrobull/795025/Afrobull-795025-kuroeda.png"],
end artist_name: "Afrobull",
artist_commentary_title: "kuroeda",
should "get the illustration id" do profile_url: "https://www.hentai-foundry.com/user/Afrobull",
assert_equal("795025", @image_1.illust_id) download_size: 1_349_887,
assert_equal("795025", @image_2.illust_id) tags: [["elf", "https://www.hentai-foundry.com/pictures/tagged/elf"]]
end )
should "get the artist name" do
assert_equal("Afrobull", @image_1.artist_name)
assert_equal("Afrobull", @image_2.artist_name)
end
should "get the artist commentary title" do
assert_equal("kuroeda", @image_1.artist_commentary_title)
assert_equal("kuroeda", @image_2.artist_commentary_title)
end
should "get profile url" do
assert_equal("https://www.hentai-foundry.com/user/Afrobull", @image_1.profile_url)
assert_equal("https://www.hentai-foundry.com/user/Afrobull", @image_2.profile_url)
end
should "get the image url" do
assert_equal(["https://pictures.hentai-foundry.com/a/Afrobull/795025/Afrobull-795025-kuroeda.png"], @image_1.image_urls)
assert_equal(["https://pictures.hentai-foundry.com/a/Afrobull/795025/Afrobull-795025-kuroeda.png"], @image_2.image_urls)
end
should "download an image" do
assert_downloaded(1_349_887, @image_1.image_urls.sole)
assert_downloaded(1_349_887, @image_2.image_urls.sole)
end
should "get the tags" do
assert_equal([["elf", "https://www.hentai-foundry.com/pictures/tagged/elf"]], @image_1.tags)
assert_equal([["elf", "https://www.hentai-foundry.com/pictures/tagged/elf"]], @image_2.tags)
end
should "find the correct artist" do
@artist = FactoryBot.create(:artist, name: "Afrobull", url_string: @image_1.url)
assert_equal([@artist], @image_1.artists)
assert_equal([@artist], @image_2.artists)
end
end end
context "An artist profile url" do context "A hentai-foundry picture" do
setup do strategy_should_work(
@site = Source::Extractor.find("https://www.hentai-foundry.com/user/Afrobull/profile") "https://www.hentai-foundry.com/pictures/user/Afrobull/795025/kuroeda",
end image_urls: ["https://pictures.hentai-foundry.com/a/Afrobull/795025/Afrobull-795025-kuroeda.png"],
artist_name: "Afrobull",
should "get the profile url" do artist_commentary_title: "kuroeda",
assert_equal("https://www.hentai-foundry.com/user/Afrobull", @site.profile_url) profile_url: "https://www.hentai-foundry.com/user/Afrobull",
end download_size: 1_349_887,
tags: [["elf", "https://www.hentai-foundry.com/pictures/tagged/elf"]]
should "get the artist name" do )
assert_equal("Afrobull", @site.artist_name)
end
end end
context "A deleted picture" do context "A deleted picture" do
setup do strategy_should_work(
@image = Source::Extractor.find("https://www.hentai-foundry.com/pictures/user/faustsketcher/279498") "https://www.hentai-foundry.com/pictures/user/faustsketcher/279498",
@artist = FactoryBot.create(:artist, name: "faustsketcher", url_string: @image.url) image_urls: [],
end artist_name: "faustsketcher",
profile_url: "https://www.hentai-foundry.com/user/faustsketcher",
should "still find the artist name" do deleted: true
assert_equal("faustsketcher", @image.artist_name) )
assert_equal("https://www.hentai-foundry.com/user/faustsketcher", @image.profile_url)
assert_equal([@artist], @image.artists)
end
end end
context "generating page urls" do context "An old image url" do
should "work" do strategy_should_work(
source1 = "http://pictures.hentai-foundry.com//a/AnimeFlux/219123.jpg" "http://pictures.hentai-foundry.com//a/AnimeFlux/219123.jpg",
source2 = "http://pictures.hentai-foundry.com/a/AnimeFlux/219123/Mobile-Suit-Equestria-rainbow-run.jpg" image_urls: ["https://pictures.hentai-foundry.com/a/AnimeFlux/219123/AnimeFlux-219123-Mobile_Suit_Equestria_rainbow_run.jpg"],
source3 = "http://www.hentai-foundry.com/pictures/user/Ganassa/457176/LOL-Swimsuit---Caitlyn-reworked-nude-ver." page_url: "https://www.hentai-foundry.com/pictures/user/AnimeFlux/219123",
profile_url: "https://www.hentai-foundry.com/user/AnimeFlux"
assert_equal("https://www.hentai-foundry.com/pictures/user/AnimeFlux/219123", Source::URL.page_url(source1)) )
assert_equal("https://www.hentai-foundry.com/pictures/user/AnimeFlux/219123", Source::URL.page_url(source2))
assert_equal("https://www.hentai-foundry.com/pictures/user/Ganassa/457176", Source::URL.page_url(source3))
assert_nil(Source::URL.page_url("https://pictures.hentai-foundry.com/a/AnimeFlux"))
end
end end
context "a post with a deeply nested commentary" do context "An image url without the extension" do
should "work" do strategy_should_work(
@source = Source::Extractor.find("https://hentai-foundry.com/pictures/user/LumiNyu/867562/Mona-patreon-winner") "http://www.hentai-foundry.com/pictures/user/Ganassa/457176/LOL-Swimsuit---Caitlyn-reworked-nude-ver.",
assert_nothing_raised { @source.to_h } image_urls: ["https://pictures.hentai-foundry.com/g/Ganassa/457176/Ganassa-457176-LOL_Swimsuit_-_Caitlyn_reworked_nude_ver..jpg"],
end page_url: "https://www.hentai-foundry.com/pictures/user/Ganassa/457176",
profile_url: "https://www.hentai-foundry.com/user/Ganassa"
)
end
context "A post with deeply nested commentary" do
strategy_should_work("https://hentai-foundry.com/pictures/user/LumiNyu/867562/Mona-patreon-winner")
end end
should "Parse HentaiFoundry URLs correctly" do should "Parse HentaiFoundry URLs correctly" do