Foundation: fix some video posts not being extracted

Also adjusts SourceTestHelper to not autogenerate contexts, so that
tests can be launched individually.
This commit is contained in:
nonamethanks
2022-04-21 17:50:10 +02:00
parent edb67b1b81
commit e6cb255a7a
6 changed files with 224 additions and 197 deletions

View File

@@ -2,97 +2,90 @@ require "test_helper"
module Sources
class FoundationTest < ActiveSupport::TestCase
context "The source for a Foundation picture" do
setup do
@post_url = "https://foundation.app/@dadachyo/~/103724"
@post_with_video = "https://foundation.app/@huwari/~/88982"
@image_url = "https://f8n-ipfs-production.imgix.net/QmPhpz6E9TFRpvdVTviM8Hy9o9rxrnPW5Ywj471NnSNkpi/nft.jpg"
@image1 = Source::Extractor.find(@post_url)
@image2 = Source::Extractor.find(@image_url)
@image3 = Source::Extractor.find(@post_with_video)
end
should "get the artist name" do
assert_equal("dadachyo", @image1.artist_name)
assert_equal("huwari", @image3.artist_name)
end
should "get the artist commentary title" do
assert_equal("Rose tea", @image1.artist_commentary_title)
assert_equal("bus", @image3.artist_commentary_title)
end
should "get profile url" do
assert_equal("https://foundation.app/@dadachyo", @image1.profile_url)
assert_equal(["https://foundation.app/@dadachyo", "https://foundation.app/0xb4D9073800c7935351ACDC1e46F0CF670853eA99"], @image1.profile_urls)
assert_equal("https://foundation.app/@huwari", @image3.profile_url)
assert_equal(["https://foundation.app/@huwari", "https://foundation.app/0xaa2f2eDE4D502F59b3706d2E2dA873C8A00A3d4d"], @image3.profile_urls)
end
should "get the image url" do
assert_equal([@image_url], @image1.image_urls)
assert_equal([@image_url], @image2.image_urls)
end
should "download an image" do
assert_downloaded(13_908_349, @image1.image_urls.sole)
assert_downloaded(13_908_349, @image2.image_urls.sole)
assert_downloaded(13_391_766, @image3.image_urls.sole)
end
should "find the correct artist" do
@artist = FactoryBot.create(:artist, name: "dadachyo", url_string: @image1.profile_url)
assert_equal([@artist], @image1.artists)
end
should "not raise errors" do
assert_nothing_raised { @image1.to_h }
assert_nothing_raised { @image2.to_h }
assert_nothing_raised { @image3.to_h }
end
context "A foundation post" do
strategy_should_work(
"https://foundation.app/@dadachyo/~/103724",
download_size: 13_908_349,
image_urls: ["https://f8n-ipfs-production.imgix.net/QmPhpz6E9TFRpvdVTviM8Hy9o9rxrnPW5Ywj471NnSNkpi/nft.jpg"],
artist_commentary_title: "Rose tea",
artist_name: "dadachyo",
profile_url: "https://foundation.app/@dadachyo",
profile_urls: ["https://foundation.app/0xb4D9073800c7935351ACDC1e46F0CF670853eA99", "https://foundation.app/@dadachyo"],
tags: %w[dadachyo rose 2018 matcrewnft]
)
end
context "for a foundation.app/@username/foo-bar-1234 URL" do
should "work" do
page_url = "https://foundation.app/@asuka111art/dinner-with-cats-82426"
image_url = "https://f8n-ipfs-production.imgix.net/Qma7Lz2LfFb4swoqzr1V43oRGh9xikgigM11g3EukdU61R/nft.png"
source = Source::Extractor.find(page_url)
assert_equal("asuka111art", source.artist_name)
assert_equal(["https://foundation.app/@asuka111art", "https://foundation.app/0x9A94f94626352566e0A9105F1e3DA0439E3e3783"], source.profile_urls)
assert_equal([image_url], source.image_urls)
assert_equal(%w[2d anime illustration digital fantasy], source.tags.map(&:first))
end
context "A foundation image url" do
strategy_should_work(
"https://f8n-ipfs-production.imgix.net/QmPhpz6E9TFRpvdVTviM8Hy9o9rxrnPW5Ywj471NnSNkpi/nft.jpg",
image_urls: ["https://f8n-ipfs-production.imgix.net/QmPhpz6E9TFRpvdVTviM8Hy9o9rxrnPW5Ywj471NnSNkpi/nft.jpg"],
download_size: 13_908_349
)
end
context "for a f8n-production-collection-assets.imgix.net URL" do
should "work" do
image_url = "https://f8n-production-collection-assets.imgix.net/0x3B3ee1931Dc30C1957379FAc9aba94D1C48a5405/128711/QmcBfbeCMSxqYB3L1owPAxFencFx3jLzCPFx6xUBxgSCkH/nft.png?q=80&auto=format%2Ccompress&cs=srgb&h=640"
source = Source::Extractor.find(image_url)
assert_equal("mochiiimo", source.artist_name)
assert_equal(["https://foundation.app/@mochiiimo", "https://foundation.app/0x7E2ef75C0C09b2fc6BCd1C68B6D409720CcD58d2"], source.profile_urls)
assert_equal(["https://f8n-ipfs-production.imgix.net/QmcBfbeCMSxqYB3L1owPAxFencFx3jLzCPFx6xUBxgSCkH/nft.png"], source.image_urls)
assert_equal(%w[anime landscape girl cat 2d illustration matcrewnft], source.tags.map(&:first))
end
context "A foundation.app/@username/foo-bar-1234 URL" do
strategy_should_work(
"https://foundation.app/@asuka111art/dinner-with-cats-82426",
image_urls: ["https://f8n-ipfs-production.imgix.net/Qma7Lz2LfFb4swoqzr1V43oRGh9xikgigM11g3EukdU61R/nft.png"],
artist_name: "asuka111art",
profile_url: "https://foundation.app/@asuka111art",
profile_urls: ["https://foundation.app/@asuka111art", "https://foundation.app/0x9A94f94626352566e0A9105F1e3DA0439E3e3783"],
tags: %w[2d anime illustration digital fantasy]
)
end
context "for a collection" do
context "A f8n-production-collection-assets.imgix.net URL" do
strategy_should_work(
"https://f8n-production-collection-assets.imgix.net/0x3B3ee1931Dc30C1957379FAc9aba94D1C48a5405/128711/QmcBfbeCMSxqYB3L1owPAxFencFx3jLzCPFx6xUBxgSCkH/nft.png?q=80&auto=format%2Ccompress&cs=srgb&h=640",
image_urls: ["https://f8n-ipfs-production.imgix.net/QmcBfbeCMSxqYB3L1owPAxFencFx3jLzCPFx6xUBxgSCkH/nft.png"],
artist_name: "mochiiimo",
profile_url: "https://foundation.app/@mochiiimo",
profile_urls: ["https://foundation.app/0x7E2ef75C0C09b2fc6BCd1C68B6D409720CcD58d2", "https://foundation.app/@mochiiimo"],
tags: %w[anime landscape girl cat 2d illustration matcrewnft]
)
end
context "A foundation post with a video hosted on imgix" do
strategy_should_work(
"https://foundation.app/@huwari/~/88982",
image_urls: ["https://f8n-ipfs-production.imgix.net/QmU8bbsjaVQpEKMDWbSZdDD6GsPmRYBhQtYRn8bEGv7igs/nft.mp4"],
download_size: 13_391_766,
artist_name: "huwari",
profile_url: "https://foundation.app/@huwari",
profile_urls: ["https://foundation.app/@huwari", "https://foundation.app/0xaa2f2eDE4D502F59b3706d2E2dA873C8A00A3d4d"],
artist_commentary_title: "bus"
)
end
context "A foundation post with a video hosted on foundation" do
strategy_should_work(
"https://foundation.app/@mcbess/ladies/4",
image_urls: ["https://assets.foundation.app/0x21Afa9aB02B6Fb7cb483ff3667c39eCdd6D9Ea73/4/nft.mp4"]
)
end
context "A foundation post with a video hosted on cloudfront" do
strategy_should_work(
"https://foundation.app/@nixeu/foundation/109126",
image_urls: ["https://f8n-ipfs-production.imgix.net/QmXiCEoBLcpfvpEwAEanLXe3Tjr5ykYJFzCVfpzDDQzdBD/nft.mp4"]
)
end
context "A collection" do
should "get the image urls" do
assert_equal(
["https://f8n-ipfs-production.imgix.net/QmX4MotNAAj9Rcyew43KdgGDxU1QtXemMHoUTNacMLLSjQ/nft.png"],
Source::Extractor.find("https://foundation.app/@mochiiimo/~/97376").image_urls,
Source::Extractor.find("https://foundation.app/@mochiiimo/~/97376").image_urls
)
assert_equal(
["https://f8n-ipfs-production.imgix.net/QmX4MotNAAj9Rcyew43KdgGDxU1QtXemMHoUTNacMLLSjQ/nft.png"],
Source::Extractor.find("https://foundation.app/@mochiiimo/foundation/97376").image_urls,
Source::Extractor.find("https://foundation.app/@mochiiimo/foundation/97376").image_urls
)
assert_equal(
["https://f8n-production-collection-assets.imgix.net/0xFb0a8e1bB97fD7231Cd73c489dA4732Ae87995F0/4/nft.png"],
Source::Extractor.find("https://foundation.app/@KILLERGF/kgfgen/4").image_urls,
Source::Extractor.find("https://foundation.app/@KILLERGF/kgfgen/4").image_urls
)
end
end