Newgrounds: rewrite tests

This commit is contained in:
nonamethanks
2022-10-08 16:23:14 +02:00
parent 79a9081efa
commit 8008b7a5a2

View File

@@ -2,100 +2,55 @@ require 'test_helper'
module Sources module Sources
class NewgroundsTest < ActiveSupport::TestCase class NewgroundsTest < ActiveSupport::TestCase
context "The source for a newgrounds picture" do context "A newgrounds post url" do
setup do strategy_should_work(
@url = "https://www.newgrounds.com/art/view/hcnone/sephiroth" "https://www.newgrounds.com/art/view/hcnone/sephiroth",
@image_url = "https://art.ngfiles.com/images/1539000/1539538_hcnone_sephiroth.png?f1607668234" image_urls: ["https://art.ngfiles.com/images/1539000/1539538_hcnone_sephiroth.png?f1607668234"],
@image_1 = Source::Extractor.find(@url) page_url: "https://www.newgrounds.com/art/view/hcnone/sephiroth",
@image_2 = Source::Extractor.find(@image_url) download_size: 4_224,
end artist_name: "hcnone",
profile_url: "https://hcnone.newgrounds.com",
should "get the artist name" do artist_commentary_title: "Sephiroth",
assert_equal("hcnone", @image_1.artist_name) tags: [
assert_equal("hcnone", @image_2.artist_name)
end
should "get the artist commentary title" do
assert_equal("Sephiroth", @image_1.artist_commentary_title)
assert_equal("Sephiroth", @image_2.artist_commentary_title)
end
should "get profile url" do
assert_equal("https://hcnone.newgrounds.com", @image_1.profile_url)
assert_equal("https://hcnone.newgrounds.com", @image_2.profile_url)
end
should "get the image urls" do
assert_equal([@image_url], @image_1.image_urls)
assert_equal([@image_url], @image_2.image_urls)
end
should "get the page url" do
assert_equal(@url, @image_1.page_url)
assert_equal(@url, @image_2.page_url)
end
should "download an image" do
assert_downloaded(4224, @image_1.image_urls.sole)
assert_downloaded(4224, @image_2.image_urls.sole)
end
should "get the tags" do
tags = [
%w[sephiroth https://www.newgrounds.com/search/conduct/art?match=tags&tags=sephiroth], %w[sephiroth https://www.newgrounds.com/search/conduct/art?match=tags&tags=sephiroth],
%w[supersmashbros https://www.newgrounds.com/search/conduct/art?match=tags&tags=supersmashbros], %w[supersmashbros https://www.newgrounds.com/search/conduct/art?match=tags&tags=supersmashbros],
] ]
)
assert_equal(tags, @image_1.tags)
assert_equal(tags, @image_2.tags)
end
should "find the right artist" do
artist_1 = create(:artist, name: "hcnone1", url_string: "https://hcnone.newgrounds.com/art")
artist_2 = create(:artist, name: "hcnone2", url_string: "https://www.newgrounds.com/art/view/hcnone/sephiroth")
artist_3 = create(:artist, name: "bad_artist", url_string: "https://www.newgrounds.com/art")
assert_equal([artist_1, artist_2], @image_1.artists)
assert_equal([artist_1, artist_2], @image_2.artists)
assert_not_equal([artist_3], @image_1.artists)
end
end end
context "A multi-image Newgrounds post" do context "A newgrounds image url" do
should "get all the images" do strategy_should_work(
source = Source::Extractor.find("https://www.newgrounds.com/art/view/natthelich/weaver") "https://art.ngfiles.com/images/1539000/1539538_hcnone_sephiroth.png?f1607668234",
image_urls = [ image_urls: ["https://art.ngfiles.com/images/1539000/1539538_hcnone_sephiroth.png?f1607668234"],
page_url: "https://www.newgrounds.com/art/view/hcnone/sephiroth",
download_size: 4_224,
artist_name: "hcnone",
profile_url: "https://hcnone.newgrounds.com",
artist_commentary_title: "Sephiroth",
tags: [
%w[sephiroth https://www.newgrounds.com/search/conduct/art?match=tags&tags=sephiroth],
%w[supersmashbros https://www.newgrounds.com/search/conduct/art?match=tags&tags=supersmashbros],
]
)
end
context "A multi-image post" do
strategy_should_work(
"https://www.newgrounds.com/art/view/natthelich/weaver",
image_urls: [
"https://art.ngfiles.com/images/1520000/1520217_natthelich_weaver.jpg?f1606365031", "https://art.ngfiles.com/images/1520000/1520217_natthelich_weaver.jpg?f1606365031",
"https://art.ngfiles.com/comments/199000/iu_199826_7115981.jpg", "https://art.ngfiles.com/comments/199000/iu_199826_7115981.jpg",
] ]
)
assert_equal(image_urls, source.image_urls)
end
end end
context "A deleted or not existing picture" do context "A deleted or non-existing post" do
setup do strategy_should_work(
@fake_1 = Source::Extractor.find("https://www.newgrounds.com/art/view/ThisUser/DoesNotExist") "https://www.newgrounds.com/art/view/natthelich/nopicture",
@artist_1 = create(:artist, name: "thisuser", url_string: "https://thisuser.newgrounds.com") deleted: true,
profile_url: "https://natthelich.newgrounds.com",
@fake_2 = Source::Extractor.find("https://www.newgrounds.com/art/view/natthelich/nopicture") artist_name: "natthelich"
@artist_2 = create(:artist, name: "natthelich", url_string: "https://natthelich.newgrounds.com") )
@fake_3 = Source::Extractor.find("https://www.newgrounds.com/art/view/theolebrave/sensitive-pochaco")
@artist_3 = create(:artist, name: "taffytoad", url_string: "https://taffytoad.newgrounds.com")
end
should "still find the artist name" do
assert_equal("thisuser", @fake_1.artist_name)
assert_equal([@artist_1], @fake_1.artists)
assert_equal("https://thisuser.newgrounds.com", @fake_1.profile_url)
assert_equal("natthelich", @fake_2.artist_name)
assert_equal([@artist_2], @fake_2.artists)
assert_equal([@artist_3], @fake_3.artists)
end
end end
context "A www.newgrounds.com/dump/item URL" do context "A www.newgrounds.com/dump/item URL" do
@@ -103,23 +58,15 @@ module Sources
"https://www.newgrounds.com/dump/item/a1f417d20f5eaef31e26ac3c4956b3d4", "https://www.newgrounds.com/dump/item/a1f417d20f5eaef31e26ac3c4956b3d4",
image_urls: [], image_urls: [],
artist_name: nil, artist_name: nil,
profile_url: nil, profile_url: nil
) )
end end
context "A post with links to other illustrations in the commentary" do context "A post with links to other illustrations not belonging to the commentary" do
should "not include the links in the commentary" do strategy_should_work(
@source = Source::Extractor.find("https://www.newgrounds.com/art/view/boxofwant/annie-hughes-1") "https://www.newgrounds.com/art/view/boxofwant/annie-hughes-1",
dtext_artist_commentary_desc: 'Commission of Annie Hughes, the mom from The Iron Giant, for "@ManStawberry":[https://twitter.com/ManStawberry].'
assert_equal(<<~EOS.chomp, @source.artist_commentary_desc) )
<div class="padded-top ql-body " id="author_comments"><p>Commission of Annie Hughes, the mom from The Iron Giant, for <a href="https://twitter.com/ManStawberry" target="_blank" rel="noopener noreferrer nofollow">@ManStawberry</a>.</p><p><br></p>
</div>
EOS
assert_equal(<<~EOS.chomp, @source.dtext_artist_commentary_desc)
Commission of Annie Hughes, the mom from The Iron Giant, for "@ManStawberry":[https://twitter.com/ManStawberry].
EOS
end
end end
should "Parse Newgrounds URLs correctly" do should "Parse Newgrounds URLs correctly" do
@@ -133,8 +80,8 @@ module Sources
assert(Source::URL.page_url?("https://www.newgrounds.com/portal/view/830293")) assert(Source::URL.page_url?("https://www.newgrounds.com/portal/view/830293"))
assert(Source::URL.profile_url?("https://natthelich.newgrounds.com")) assert(Source::URL.profile_url?("https://natthelich.newgrounds.com"))
refute(Source::URL.profile_url?("https://www.newgrounds.com")) assert_not(Source::URL.profile_url?("https://www.newgrounds.com"))
refute(Source::URL.profile_url?("https://newgrounds.com")) assert_not(Source::URL.profile_url?("https://newgrounds.com"))
end end
end end
end end