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
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
@@ -94,7 +94,7 @@ class Source::Extractor
image_sizes = %w[original 4k large medium small]
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
end
end

View File

@@ -2,35 +2,17 @@ require 'test_helper'
module Sources
class ArtStationTest < ActiveSupport::TestCase
context "The source site for an art station artwork page" do
setup do
@site = Source::Extractor.find("https://www.artstation.com/artwork/04XA4")
end
should "get the image url" do
assert_equal(["https://cdn.artstation.com/p/assets/images/images/000/705/368/4k/jey-rain-one1.jpg?1443931773"], @site.image_urls)
end
should "get the page url" do
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
context "An ArtStation /artwork/:id URL" do
strategy_should_work(
"https://www.artstation.com/artwork/04XA4",
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",
profile_url: "https://www.artstation.com/jeyrain",
artist_name: "jeyrain",
tags: [],
artist_commentary_title: "pink",
dtext_artist_commentary_desc: ""
)
end
context "An ArtStation /projects/ URL" do
@@ -43,94 +25,56 @@ module Sources
tags: %w[gantz Reika],
artist_commentary_title: "Reika ",
dtext_artist_commentary_desc: "From Gantz.",
download_size: 210_899,
download_size: 210_899
)
end
context "The source site for a www.artstation.com/artwork/$slug page" do
setup do
@site = Source::Extractor.find("https://www.artstation.com/artwork/cody-from-sf")
end
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
context "An ArtStation /artwork/$slug page" do
strategy_should_work(
"https://www.artstation.com/artwork/cody-from-sf",
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"]
)
end
context "The source site for a http://cdn.artstation.com/p/assets/... url" do
setup do
@url = "https://cdna.artstation.com/p/assets/images/images/006/029/978/large/amama-l-z.jpg"
@ref = "https://www.artstation.com/artwork/4BWW2"
end
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
context "A http://cdn.artstation.com/p/assets/... url" do
strategy_should_work(
"https://cdna.artstation.com/p/assets/images/images/006/029/978/large/amama-l-z.jpg",
image_urls: ["https://cdn.artstation.com/p/assets/images/images/006/029/978/4k/amama-l-z.jpg"],
page_url: nil,
profile_url: nil
)
end
context "A 4k asset url" do
context "without a referer" do
should "work" do
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")
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)
assert_nothing_raised { site.to_h }
end
end
context "A http://cdn.artstation.com/p/assets/... url with referrer" do
strategy_should_work(
"https://cdna.artstation.com/p/assets/images/images/006/029/978/large/amama-l-z.jpg",
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",
page_url: "https://amama.artstation.com/projects/4BWW2",
profile_url: "https://www.artstation.com/amama",
artist_name: "amama"
)
end
context "A cover url" do
should "work" do
url = "https://cdna.artstation.com/p/assets/covers/images/007/262/828/large/monica-kyrie-1.jpg?1504865060"
site = Source::Extractor.find(url)
assert_equal(["https://cdn.artstation.com/p/assets/covers/images/007/262/828/original/monica-kyrie-1.jpg?1504865060"], site.image_urls)
end
context "An ArtStation cover url" do
strategy_should_work(
"https://cdna.artstation.com/p/assets/covers/images/007/262/828/large/monica-kyrie-1.jpg?1504865060",
image_urls: ["https://cdn.artstation.com/p/assets/covers/images/007/262/828/original/monica-kyrie-1.jpg?1504865060"]
)
end
context "The source site for an ArtStation gallery" do
setup do
@site = Source::Extractor.find("https://www.artstation.com/artwork/BDxrA")
end
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
context "An ArtStation post with images and youtube links" do
strategy_should_work(
"https://www.artstation.com/artwork/BDxrA",
image_urls: ["https://cdn.artstation.com/p/assets/images/images/006/037/253/4k/astri-lohne-sjursen-eva.jpg?1495573664"]
)
end
context "A work that includes video clips" do
should_eventually "include the video clips in the image urls" do
@source = Source::Extractor.find("https://www.artstation.com/artwork/0nP1e8")
assert_equal(%w[
context "An ArtStation post with images and videos" do
strategy_should_work( # XXX Broken by Cloudflare captcha
"https://www.artstation.com/artwork/0nP1e8",
image_urls: %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/435/4k/yusuf-umar-1.jpg?1630425420
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-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
], @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
context "A work that has been deleted" do
should "work" do
url = "https://fiship.artstation.com/projects/x8n8XT"
site = Source::Extractor.find(url)
context "An ArtStation video url" do
strategy_should_work(
"https://cdn-animation.artstation.com/p/video_sources/000/466/622/workout.mp4",
image_urls: ["https://cdn-animation.artstation.com/p/video_sources/000/466/622/workout.mp4"]
)
end
assert_equal("fiship", site.artist_name)
assert_equal("https://www.artstation.com/fiship", site.profile_url)
assert_equal(url, site.page_url)
assert_equal([], site.image_urls)
assert_nothing_raised { site.to_h }
end
context "A deleted ArtStation url" do
strategy_should_work(
"https://fiship.artstation.com/projects/x8n8XT",
deleted: true,
image_urls: [],
artist_name: "fiship",
profile_url: "https://www.artstation.com/fiship",
page_url: "https://fiship.artstation.com/projects/x8n8XT"
)
end
context "A /small/ ArtStation image URL" do
strategy_should_work(
"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"],
download_size: 1_816_628,
download_size: 1_816_628
)
end
@@ -175,7 +118,7 @@ module Sources
strategy_should_work(
"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"],
download_size: 1_816_628,
download_size: 1_816_628
)
end
@@ -183,18 +126,22 @@ module Sources
strategy_should_work(
"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"],
download_size: 452_985,
download_size: 452_985
)
end
should "work for artists with underscores in their name" do
site = Source::Extractor.find("https://hosi_na.artstation.com/projects/3oEk3B")
assert_equal("hosi_na", site.artist_name)
context "An ArtStation url with underscores in the artist name" do
strategy_should_work(
"https://hosi_na.artstation.com/projects/3oEk3B",
artist_name: "hosi_na"
)
end
should "work for artists with dashes in their name" do
site = Source::Extractor.find("https://sa-dui.artstation.com/projects/DVERn")
assert_equal("sa-dui", site.artist_name)
context "An ArtStation url with dashes in the artist name" do
strategy_should_work(
"https://sa-dui.artstation.com/projects/DVERn",
artist_name: "sa-dui"
)
end
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://anubis1982918.artstation.com"))
refute(Source::URL.profile_url?("https://anubis1982918.artstation.com/projects/qPVGP"))
refute(Source::URL.profile_url?("https://www.artstation.com"))
refute(Source::URL.profile_url?("https://artstation.com"))
assert_not(Source::URL.profile_url?("https://anubis1982918.artstation.com/projects/qPVGP"))
assert_not(Source::URL.profile_url?("https://www.artstation.com"))
assert_not(Source::URL.profile_url?("https://artstation.com"))
end
end
end