Stash: rewrite tests

This commit is contained in:
nonamethanks
2022-10-22 20:09:23 +02:00
parent ec293eec2d
commit f5a3a7da9f

View File

@@ -7,48 +7,39 @@ module Sources
skip "DeviantArt API keys not set" unless Danbooru.config.deviantart_client_id.present?
end
context "A https://sta.sh/:id page url" do
should "work" do
@site = Source::Extractor.find("https://sta.sh/0wxs31o7nn2")
assert_equal("noizave", @site.artist_name)
assert_equal("https://www.deviantart.com/noizave", @site.profile_url)
assert_equal("A pepe", @site.artist_commentary_title)
assert_equal("This is a test.", @site.artist_commentary_desc)
assert_equal("https://sta.sh/0wxs31o7nn2", @site.page_url)
assert_match("https://wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/83d3eb4d-13e5-4aea-a08f-8d4331d033c4/dcmga0s-a345a815-2436-4ab5-8941-492011e1bff6.png", @site.image_urls.sole)
end
context "A https://sta.sh/:id url" do
strategy_should_work(
"https://sta.sh/0wxs31o7nn2",
image_urls: ["https://wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/83d3eb4d-13e5-4aea-a08f-8d4331d033c4/dcmga0s-a345a815-2436-4ab5-8941-492011e1bff6.png"],
page_url: "https://sta.sh/0wxs31o7nn2",
artist_name: "noizave",
profile_url: "https://www.deviantart.com/noizave",
artist_commentary_title: "A pepe",
artist_commentary_desc: "This is a test."
)
end
context "A https://orig00.deviantart.net/* image url" do
context "with a https://sta.sh/:id referer" do
should "work" do
@site = Source::Extractor.find("https://orig00.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png", "https://sta.sh/0wxs31o7nn2")
context "A https://orig00.deviantart.net/* image url with a https://sta.sh/:id referer" do
strategy_should_work(
"https://orig00.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png",
image_urls: [" https://wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/83d3eb4d-13e5-4aea-a08f-8d4331d033c4/dcmga0s-a345a815-2436-4ab5-8941-492011e1bff6.png"],
referer: "https://sta.sh/0wxs31o7nn2",
page_url: "https://sta.sh/0wxs31o7nn2",
artist_name: "noizave",
profile_url: "https://www.deviantart.com/noizave",
artist_commentary_title: "A pepe",
artist_commentary_desc: "This is a test."
)
end
assert_equal("noizave", @site.artist_name)
assert_equal("https://www.deviantart.com/noizave", @site.profile_url)
assert_equal("A pepe", @site.artist_commentary_title)
assert_equal("This is a test.", @site.artist_commentary_desc)
assert_equal("https://sta.sh/0wxs31o7nn2", @site.page_url)
assert_match("https://wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/83d3eb4d-13e5-4aea-a08f-8d4331d033c4/dcmga0s-a345a815-2436-4ab5-8941-492011e1bff6.png", @site.image_urls.sole)
end
end
context "without a referer" do
should "use the base deviantart strategy" do
@site = Source::Extractor.find("https://orig00.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png")
# if all we have is the image url, then we can't tell that this is really a sta.sh image.
assert_equal("Deviant Art", @site.site_name)
# this is the wrong page, but there's no way to know the correct sta.sh page without the referer.
assert_equal("https://www.deviantart.com/noizave/art/A-Pepe-763305148", @site.page_url)
end
end
context "A https://orig00.deviantart.net/* image url without the referer" do
strategy_should_work(
"https://orig00.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png",
# if all we have is the image url, then we can't tell that this is really a sta.sh image.
site_name: "Deviant Art",
# this is the wrong page, but there's no way to know the correct sta.sh page without the referer.
page_url: "https://www.deviantart.com/noizave/art/A-Pepe-763305148"
)
end
end
end