Artstation: rewrite tests

This commit is contained in:
nonamethanks
2022-10-07 21:36:53 +02:00
parent b51c1e1d41
commit 3c8e8ad8d9
2 changed files with 83 additions and 136 deletions

View File

@@ -48,7 +48,7 @@ class Source::Extractor
def tags def tags
api_response[:tags].to_a.map do |tag| api_response[:tags].to_a.map do |tag|
[tag, "https://www.artstation.com/search?q=" + CGI.escape(tag)] [tag, "https://www.artstation.com/search?q=#{CGI.escape(tag)}"]
end end
end end
@@ -94,7 +94,7 @@ class Source::Extractor
image_sizes = %w[original 4k large medium small] image_sizes = %w[original 4k large medium small]
urls = image_sizes.map { |size| parsed_url.full_image_url(size) } urls = image_sizes.map { |size| parsed_url.full_image_url(size) }
chosen_url = urls.find { |url| http_exists?(url) } chosen_url = urls.find { |u| http_exists?(u) }
chosen_url || url chosen_url || url
end end
end end

View File

@@ -2,35 +2,17 @@ require 'test_helper'
module Sources module Sources
class ArtStationTest < ActiveSupport::TestCase class ArtStationTest < ActiveSupport::TestCase
context "The source site for an art station artwork page" do context "An ArtStation /artwork/:id URL" do
setup do strategy_should_work(
@site = Source::Extractor.find("https://www.artstation.com/artwork/04XA4") "https://www.artstation.com/artwork/04XA4",
end image_urls: ["https://cdn.artstation.com/p/assets/images/images/000/705/368/4k/jey-rain-one1.jpg?1443931773"],
page_url: "https://jeyrain.artstation.com/projects/04XA4",
should "get the image url" do profile_url: "https://www.artstation.com/jeyrain",
assert_equal(["https://cdn.artstation.com/p/assets/images/images/000/705/368/4k/jey-rain-one1.jpg?1443931773"], @site.image_urls) artist_name: "jeyrain",
end tags: [],
artist_commentary_title: "pink",
should "get the page url" do dtext_artist_commentary_desc: ""
assert_equal("https://jeyrain.artstation.com/projects/04XA4", @site.page_url) )
end
should "get the profile" do
assert_equal("https://www.artstation.com/jeyrain", @site.profile_url)
end
should "get the artist name" do
assert_equal("jeyrain", @site.artist_name)
end
should "get the tags" do
assert_equal([], @site.tags)
end
should "get the artist commentary" do
assert_equal("pink", @site.artist_commentary_title)
assert_equal("", @site.dtext_artist_commentary_desc)
end
end end
context "An ArtStation /projects/ URL" do context "An ArtStation /projects/ URL" do
@@ -43,94 +25,56 @@ module Sources
tags: %w[gantz Reika], tags: %w[gantz Reika],
artist_commentary_title: "Reika ", artist_commentary_title: "Reika ",
dtext_artist_commentary_desc: "From Gantz.", dtext_artist_commentary_desc: "From Gantz.",
download_size: 210_899, download_size: 210_899
) )
end end
context "The source site for a www.artstation.com/artwork/$slug page" do context "An ArtStation /artwork/$slug page" do
setup do strategy_should_work(
@site = Source::Extractor.find("https://www.artstation.com/artwork/cody-from-sf") "https://www.artstation.com/artwork/cody-from-sf",
end image_urls: ["https://cdn.artstation.com/p/assets/images/images/000/144/922/4k/cassio-yoshiyaki-cody2backup2-yoshiyaki.jpg?1406314198"],
tags: ["Street Fighter", "Cody", "SF"]
should "get the image url" do )
url = "https://cdn.artstation.com/p/assets/images/images/000/144/922/4k/cassio-yoshiyaki-cody2backup2-yoshiyaki.jpg?1406314198"
assert_equal([url], @site.image_urls)
end
should "get the tags" do
assert_equal(["Street Fighter", "Cody", "SF"].sort, @site.tags.map(&:first).sort)
assert_equal(["street_fighter", "cody", "sf"].sort, @site.normalized_tags.sort)
end
end end
context "The source site for a http://cdn.artstation.com/p/assets/... url" do context "A http://cdn.artstation.com/p/assets/... url" do
setup do strategy_should_work(
@url = "https://cdna.artstation.com/p/assets/images/images/006/029/978/large/amama-l-z.jpg" "https://cdna.artstation.com/p/assets/images/images/006/029/978/large/amama-l-z.jpg",
@ref = "https://www.artstation.com/artwork/4BWW2" image_urls: ["https://cdn.artstation.com/p/assets/images/images/006/029/978/4k/amama-l-z.jpg"],
end page_url: nil,
profile_url: nil
context "with a referer" do )
should "work" do
site = Source::Extractor.find(@url, @ref)
assert_equal(["https://cdn.artstation.com/p/assets/images/images/006/029/978/4k/amama-l-z.jpg"], site.image_urls)
assert_equal("https://amama.artstation.com/projects/4BWW2", site.page_url)
assert_equal("https://www.artstation.com/amama", site.profile_url)
assert_equal("amama", site.artist_name)
assert_nothing_raised { site.to_h }
end
end
context "without a referer" do
should "work" do
site = Source::Extractor.find(@url)
assert_equal(["https://cdn.artstation.com/p/assets/images/images/006/029/978/4k/amama-l-z.jpg"], site.image_urls)
assert_nil(site.page_url)
assert_nil(site.profile_url)
assert_nil(site.artist_name)
assert_equal([], site.tags)
assert_nothing_raised { site.to_h }
end
end
end end
context "A 4k asset url" do context "A http://cdn.artstation.com/p/assets/... url with referrer" do
context "without a referer" do strategy_should_work(
should "work" do "https://cdna.artstation.com/p/assets/images/images/006/029/978/large/amama-l-z.jpg",
site = Source::Extractor.find("https://cdna.artstation.com/p/assets/images/images/007/253/680/4k/ina-wong-demon-girl-done-ttd-comp.jpg?1504793833") image_urls: ["https://cdn.artstation.com/p/assets/images/images/006/029/978/4k/amama-l-z.jpg"],
referer: "https://www.artstation.com/artwork/4BWW2",
assert_equal(["https://cdn.artstation.com/p/assets/images/images/007/253/680/4k/ina-wong-demon-girl-done-ttd-comp.jpg?1504793833"], site.image_urls) page_url: "https://amama.artstation.com/projects/4BWW2",
assert_nothing_raised { site.to_h } profile_url: "https://www.artstation.com/amama",
end artist_name: "amama"
end )
end end
context "A cover url" do context "An ArtStation cover url" do
should "work" do strategy_should_work(
url = "https://cdna.artstation.com/p/assets/covers/images/007/262/828/large/monica-kyrie-1.jpg?1504865060" "https://cdna.artstation.com/p/assets/covers/images/007/262/828/large/monica-kyrie-1.jpg?1504865060",
site = Source::Extractor.find(url) image_urls: ["https://cdn.artstation.com/p/assets/covers/images/007/262/828/original/monica-kyrie-1.jpg?1504865060"]
)
assert_equal(["https://cdn.artstation.com/p/assets/covers/images/007/262/828/original/monica-kyrie-1.jpg?1504865060"], site.image_urls)
end
end end
context "The source site for an ArtStation gallery" do context "An ArtStation post with images and youtube links" do
setup do strategy_should_work(
@site = Source::Extractor.find("https://www.artstation.com/artwork/BDxrA") "https://www.artstation.com/artwork/BDxrA",
end image_urls: ["https://cdn.artstation.com/p/assets/images/images/006/037/253/4k/astri-lohne-sjursen-eva.jpg?1495573664"]
)
should "get only image urls, not video urls" do
urls = %w[https://cdn.artstation.com/p/assets/images/images/006/037/253/4k/astri-lohne-sjursen-eva.jpg?1495573664]
assert_equal(urls, @site.image_urls)
end
end end
context "A work that includes video clips" do context "An ArtStation post with images and videos" do
should_eventually "include the video clips in the image urls" do strategy_should_work( # XXX Broken by Cloudflare captcha
@source = Source::Extractor.find("https://www.artstation.com/artwork/0nP1e8") "https://www.artstation.com/artwork/0nP1e8",
image_urls: %w[
assert_equal(%w[
https://cdn.artstation.com/p/assets/images/images/040/979/418/original/yusuf-umar-workout-10mb.gif?1630425406 https://cdn.artstation.com/p/assets/images/images/040/979/418/original/yusuf-umar-workout-10mb.gif?1630425406
https://cdn.artstation.com/p/assets/images/images/040/979/435/4k/yusuf-umar-1.jpg?1630425420 https://cdn.artstation.com/p/assets/images/images/040/979/435/4k/yusuf-umar-1.jpg?1630425420
https://cdn.artstation.com/p/assets/images/images/040/979/470/4k/yusuf-umar-2.jpg?1630425483 https://cdn.artstation.com/p/assets/images/images/040/979/470/4k/yusuf-umar-2.jpg?1630425483
@@ -140,34 +84,33 @@ module Sources
https://cdn.artstation.com/p/assets/images/images/040/980/932/4k/yusuf-umar-tpose.jpg?1630427748 https://cdn.artstation.com/p/assets/images/images/040/980/932/4k/yusuf-umar-tpose.jpg?1630427748
https://cdn-animation.artstation.com/p/video_sources/000/466/622/workout.mp4 https://cdn-animation.artstation.com/p/video_sources/000/466/622/workout.mp4
https://cdn-animation.artstation.com/p/video_sources/000/466/623/workout-clay.mp4 https://cdn-animation.artstation.com/p/video_sources/000/466/623/workout-clay.mp4
], @source.image_urls) ]
end )
should "work for the video itself" do
@source = Source::Extractor.find("https://cdn-animation.artstation.com/p/video_sources/000/466/622/workout.mp4")
assert_equal(["https://cdn-animation.artstation.com/p/video_sources/000/466/622/workout.mp4"], @source.image_urls)
end
end end
context "A work that has been deleted" do context "An ArtStation video url" do
should "work" do strategy_should_work(
url = "https://fiship.artstation.com/projects/x8n8XT" "https://cdn-animation.artstation.com/p/video_sources/000/466/622/workout.mp4",
site = Source::Extractor.find(url) image_urls: ["https://cdn-animation.artstation.com/p/video_sources/000/466/622/workout.mp4"]
)
end
assert_equal("fiship", site.artist_name) context "A deleted ArtStation url" do
assert_equal("https://www.artstation.com/fiship", site.profile_url) strategy_should_work(
assert_equal(url, site.page_url) "https://fiship.artstation.com/projects/x8n8XT",
assert_equal([], site.image_urls) deleted: true,
assert_nothing_raised { site.to_h } image_urls: [],
end artist_name: "fiship",
profile_url: "https://www.artstation.com/fiship",
page_url: "https://fiship.artstation.com/projects/x8n8XT"
)
end end
context "A /small/ ArtStation image URL" do context "A /small/ ArtStation image URL" do
strategy_should_work( strategy_should_work(
"https://cdnb3.artstation.com/p/assets/images/images/003/716/071/small/aoi-ogata-hate-city.jpg?1476754974", "https://cdnb3.artstation.com/p/assets/images/images/003/716/071/small/aoi-ogata-hate-city.jpg?1476754974",
image_urls: ["https://cdn.artstation.com/p/assets/images/images/003/716/071/4k/aoi-ogata-hate-city.jpg?1476754974"], image_urls: ["https://cdn.artstation.com/p/assets/images/images/003/716/071/4k/aoi-ogata-hate-city.jpg?1476754974"],
download_size: 1_816_628, download_size: 1_816_628
) )
end end
@@ -175,7 +118,7 @@ module Sources
strategy_should_work( strategy_should_work(
"https://cdnb.artstation.com/p/assets/images/images/003/716/071/large/aoi-ogata-hate-city.jpg?1476754974", "https://cdnb.artstation.com/p/assets/images/images/003/716/071/large/aoi-ogata-hate-city.jpg?1476754974",
image_urls: ["https://cdn.artstation.com/p/assets/images/images/003/716/071/4k/aoi-ogata-hate-city.jpg?1476754974"], image_urls: ["https://cdn.artstation.com/p/assets/images/images/003/716/071/4k/aoi-ogata-hate-city.jpg?1476754974"],
download_size: 1_816_628, download_size: 1_816_628
) )
end end
@@ -183,18 +126,22 @@ module Sources
strategy_should_work( strategy_should_work(
"https://cdna.artstation.com/p/assets/images/images/004/730/278/large/mendel-oh-dragonll.jpg", "https://cdna.artstation.com/p/assets/images/images/004/730/278/large/mendel-oh-dragonll.jpg",
image_urls: ["https://cdn.artstation.com/p/assets/images/images/004/730/278/4k/mendel-oh-dragonll.jpg"], image_urls: ["https://cdn.artstation.com/p/assets/images/images/004/730/278/4k/mendel-oh-dragonll.jpg"],
download_size: 452_985, download_size: 452_985
) )
end end
should "work for artists with underscores in their name" do context "An ArtStation url with underscores in the artist name" do
site = Source::Extractor.find("https://hosi_na.artstation.com/projects/3oEk3B") strategy_should_work(
assert_equal("hosi_na", site.artist_name) "https://hosi_na.artstation.com/projects/3oEk3B",
artist_name: "hosi_na"
)
end end
should "work for artists with dashes in their name" do context "An ArtStation url with dashes in the artist name" do
site = Source::Extractor.find("https://sa-dui.artstation.com/projects/DVERn") strategy_should_work(
assert_equal("sa-dui", site.artist_name) "https://sa-dui.artstation.com/projects/DVERn",
artist_name: "sa-dui"
)
end end
should "Parse ArtStation URLs correctly" do should "Parse ArtStation URLs correctly" do
@@ -212,9 +159,9 @@ module Sources
assert(Source::URL.profile_url?("https://artstation.com/artist/sa-dui")) assert(Source::URL.profile_url?("https://artstation.com/artist/sa-dui"))
assert(Source::URL.profile_url?("https://anubis1982918.artstation.com")) assert(Source::URL.profile_url?("https://anubis1982918.artstation.com"))
refute(Source::URL.profile_url?("https://anubis1982918.artstation.com/projects/qPVGP")) assert_not(Source::URL.profile_url?("https://anubis1982918.artstation.com/projects/qPVGP"))
refute(Source::URL.profile_url?("https://www.artstation.com")) assert_not(Source::URL.profile_url?("https://www.artstation.com"))
refute(Source::URL.profile_url?("https://artstation.com")) assert_not(Source::URL.profile_url?("https://artstation.com"))
end end
end end
end end