From c9300cc54e7e558977181d5b8ce67985c612c53e Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 10 Sep 2018 18:55:38 -0500 Subject: [PATCH] sta.sh: add tests + docs. --- app/logical/sources/strategies/stash.rb | 12 +++++ test/unit/sources/stash_test.rb | 58 +++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 test/unit/sources/stash_test.rb diff --git a/app/logical/sources/strategies/stash.rb b/app/logical/sources/strategies/stash.rb index 8394add28..dbaf2e930 100644 --- a/app/logical/sources/strategies/stash.rb +++ b/app/logical/sources/strategies/stash.rb @@ -1,3 +1,15 @@ +# Page URLs: +# * https://sta.sh/0wxs31o7nn2 (single image) +# * https://sta.sh/21leo8mz87ue (folder) +# +# Image URLs: +# * https://orig00.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png +# +# Ref: +# * https://github.com/r888888888/danbooru/issues/3877 +# * https://www.deviantartsupport.com/en/article/what-is-stash-3391708 +# * https://www.deviantart.com/developers/http/v1/20160316/stash_item/4662dd8b10e336486ea9a0b14da62b74 +# module Sources module Strategies class Stash < DeviantArt diff --git a/test/unit/sources/stash_test.rb b/test/unit/sources/stash_test.rb new file mode 100644 index 000000000..b005bb9c8 --- /dev/null +++ b/test/unit/sources/stash_test.rb @@ -0,0 +1,58 @@ +require 'test_helper' + +module Sources + class StashTest < ActiveSupport::TestCase + def setup + super + 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 = Sources::Strategies.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_equal("https://sta.sh/0wxs31o7nn2", @site.canonical_url) + assert_equal("http://origin-orig.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png", @site.image_url) + assert_equal(["http://origin-orig.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png"], @site.image_urls) + end + end + + context "A https://orig00.deviantart.net/* image url" do + context "with a https://sta.sh/:id referer" do + should "work" do + @site = Sources::Strategies.find("https://orig00.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png", "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_equal("https://sta.sh/0wxs31o7nn2", @site.canonical_url) + assert_equal("http://origin-orig.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png", @site.image_url) + assert_equal(["http://origin-orig.deviantart.net/0fd2/f/2018/252/9/c/a_pepe_by_noizave-dcmga0s.png"], @site.image_urls) + end + end + + context "without a referer" do + should "use the base deviantart strategy" do + @site = Sources::Strategies.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/deviation/763305148", @site.page_url) + end + end + end + end +end