Change how artist URLs are normalized in artist entries. Don't try to secretly convert image URLs to profile URLs in artist entries. For example, if someone puts a Pixiv image URL in an artist entry, don't secretly try to fetch the source and convert it into a profile URL in the `normalized_url` field. We did this because years ago, it was standard practice to put image URLs in artist entries. Pixiv image URLs used to contain the artist's username, so we used to put image URLs in artist entries for artist finding purposes. But Pixiv changed it so that image URLs no longer contained the username, so we dealt with it by adding a `normalized_url` column to artist_urls and secretly converting image URLs to profile URLs in this field. But this is no longer necessary because now we don't normally put image URLs in artist entries in the first place. Now the `profile_url` method in `Source::URL` is used to normalize URLs in artist entries. This lets us parse various profile URL formats and normalize them into a single canonical form. This also removes the `normalize_for_artist_finder` method from source strategies. Instead the `profile_url` method is used for artist finding purposes. So the profile URL returned by the source strategy needs to be the same as the URL in the artist entry in order for artist finding to work.
110 lines
4.6 KiB
Ruby
110 lines
4.6 KiB
Ruby
require 'test_helper'
|
|
|
|
module Sources
|
|
class HentaiFoundryTest < ActiveSupport::TestCase
|
|
context "The source for a hentai foundry picture" do
|
|
setup do
|
|
@image_1 = Sources::Strategies.find("https://www.hentai-foundry.com/pictures/user/Afrobull/795025/kuroeda")
|
|
@image_2 = Sources::Strategies.find("https://pictures.hentai-foundry.com/a/Afrobull/795025/Afrobull-795025-kuroeda.png")
|
|
end
|
|
|
|
should "get the illustration id" do
|
|
assert_equal("795025", @image_1.illust_id)
|
|
assert_equal("795025", @image_2.illust_id)
|
|
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 "get the canonical url" do
|
|
assert_equal("https://pictures.hentai-foundry.com/a/Afrobull/795025/Afrobull-795025-kuroeda.png", @image_1.canonical_url)
|
|
assert_equal("https://pictures.hentai-foundry.com/a/Afrobull/795025/Afrobull-795025-kuroeda.png", @image_2.canonical_url)
|
|
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/search/index?query=elf&search_in=keywords"]], @image_1.tags)
|
|
assert_equal([["elf", "https://www.hentai-foundry.com/search/index?query=elf&search_in=keywords"]], @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
|
|
|
|
context "An artist profile url" do
|
|
setup do
|
|
@site = Sources::Strategies.find("https://www.hentai-foundry.com/user/Afrobull/profile")
|
|
end
|
|
|
|
should "get the profile url" do
|
|
assert_equal("https://www.hentai-foundry.com/user/Afrobull", @site.profile_url)
|
|
end
|
|
|
|
should "get the artist name" do
|
|
assert_equal("Afrobull", @site.artist_name)
|
|
end
|
|
end
|
|
|
|
context "A deleted picture" do
|
|
setup do
|
|
@image = Sources::Strategies.find("https://www.hentai-foundry.com/pictures/user/faustsketcher/279498")
|
|
@artist = FactoryBot.create(:artist, name: "faustsketcher", url_string: @image.url)
|
|
end
|
|
|
|
should "still find the artist name" do
|
|
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
|
|
|
|
context "normalizing for source" do
|
|
should "normalize correctly" do
|
|
source1 = "http://pictures.hentai-foundry.com//a/AnimeFlux/219123.jpg"
|
|
source2 = "http://pictures.hentai-foundry.com/a/AnimeFlux/219123/Mobile-Suit-Equestria-rainbow-run.jpg"
|
|
source3 = "http://www.hentai-foundry.com/pictures/user/Ganassa/457176/LOL-Swimsuit---Caitlyn-reworked-nude-ver."
|
|
|
|
assert_equal("https://www.hentai-foundry.com/pictures/user/AnimeFlux/219123", Sources::Strategies.normalize_source(source1))
|
|
assert_equal("https://www.hentai-foundry.com/pictures/user/AnimeFlux/219123", Sources::Strategies.normalize_source(source2))
|
|
assert_equal("https://www.hentai-foundry.com/pictures/user/Ganassa/457176", Sources::Strategies.normalize_source(source3))
|
|
end
|
|
|
|
should "avoid normalizing unnormalizable urls" do
|
|
bad_source = "https://pictures.hentai-foundry.com/a/AnimeFlux"
|
|
assert_equal(bad_source, Sources::Strategies.normalize_source(bad_source))
|
|
end
|
|
end
|
|
|
|
context "a post with a deeply nested commentary" do
|
|
should "work" do
|
|
@source = Sources::Strategies.find("https://hentai-foundry.com/pictures/user/LumiNyu/867562/Mona-patreon-winner")
|
|
assert_nothing_raised { @source.to_h }
|
|
end
|
|
end
|
|
end
|
|
end
|