forked from e621ng/e621ng
[Tests] Fix artist tests
This commit is contained in:
parent
e3728546c7
commit
348827de5d
@ -9,7 +9,10 @@ class ArtistUrlsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
should "render for a complex search" do
|
||||
@artist = FactoryBot.create(:artist, name: "bkub", url_string: "-http://bkub.com")
|
||||
@user = create(:user)
|
||||
as_user do
|
||||
@artist = FactoryBot.create(:artist, name: "bkub", url_string: "-http://bkub.com")
|
||||
end
|
||||
|
||||
get artist_urls_path(search: {
|
||||
artist: { name: "bkub", },
|
||||
|
@ -1,32 +1,6 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ArtistsControllerTest < ActionDispatch::IntegrationTest
|
||||
def assert_artist_found(expected_artist, source_url = nil)
|
||||
if source_url
|
||||
get_auth artists_path(format: "json", search: { url_matches: source_url }), @user
|
||||
if response.body =~ /Net::OpenTimeout/
|
||||
skip "Remote connection to #{source_url} failed"
|
||||
return
|
||||
end
|
||||
end
|
||||
assert_response :success
|
||||
json = JSON.parse(response.body)
|
||||
assert_equal(1, json.size, "Testing URL: #{source_url}")
|
||||
assert_equal(expected_artist, json[0]["name"])
|
||||
end
|
||||
|
||||
def assert_artist_not_found(source_url)
|
||||
get_auth artists_path(format: "json", search: { url_matches: source_url }), @user
|
||||
if response.body =~ /Net::OpenTimeout/
|
||||
skip "Remote connection to #{source_url} failed"
|
||||
return
|
||||
end
|
||||
|
||||
assert_response :success
|
||||
json = JSON.parse(response.body)
|
||||
assert_equal(0, json.size, "Testing URL: #{source_url}")
|
||||
end
|
||||
|
||||
context "An artists controller" do
|
||||
setup do
|
||||
@admin = create(:admin_user)
|
||||
@ -63,35 +37,11 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "get the show page for a negated tag" do
|
||||
@artist.update(name: "-aaa")
|
||||
get artist_path(@artist.id)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "get the index page" do
|
||||
get artists_path
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
context "when searching the index page" do
|
||||
should "find artists by name" do
|
||||
get artists_path(name: "masao", format: "json")
|
||||
assert_artist_found("masao")
|
||||
end
|
||||
|
||||
should "find artists by image URL" do
|
||||
get artists_path(search: { url_matches: "http://i2.pixiv.net/img04/img/syounen_no_uta/46170939_m.jpg" }, format: "json")
|
||||
assert_artist_found("masao")
|
||||
end
|
||||
|
||||
should "find artists by page URL" do
|
||||
url = "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46170939"
|
||||
get artists_path(search: { url_matches: url }, format: "json")
|
||||
assert_artist_found("masao")
|
||||
end
|
||||
end
|
||||
|
||||
should "create an artist" do
|
||||
attributes = FactoryBot.attributes_for(:artist)
|
||||
assert_difference("Artist.count", 1) do
|
||||
@ -197,43 +147,5 @@ class ArtistsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_redirected_to(artist_path(@artist.id))
|
||||
end
|
||||
end
|
||||
|
||||
context "when finding an artist" do
|
||||
should "find nothing for unknown URLs" do
|
||||
assert_artist_not_found("http://www.example.com")
|
||||
end
|
||||
|
||||
should "find deviantart artists" do
|
||||
assert_artist_found("artgerm", "http://artgerm.deviantart.com/art/Peachy-Princess-Ver-2-457220550")
|
||||
end
|
||||
|
||||
should_eventually "find deviantart artists for image URLs" do
|
||||
assert_artist_found("artgerm", "http://fc06.deviantart.net/fs71/f/2014/150/d/c/peachy_princess_by_artgerm-d7k7tmu.jpg")
|
||||
end
|
||||
|
||||
should "find pixiv artists for img##" do
|
||||
assert_artist_found("masao", "http://i2.pixiv.net/img04/img/syounen_no_uta/46170939.jpg")
|
||||
end
|
||||
|
||||
should "find pixiv artists for img-original" do
|
||||
assert_artist_found("masao", "http://i2.pixiv.net/img-original/img/2014/09/25/00/57/24/46170939_p0.jpg")
|
||||
end
|
||||
|
||||
should "find pixiv artists for member_illust.php" do
|
||||
assert_artist_found("masao", "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46170939")
|
||||
end
|
||||
|
||||
should "fail for nonexisting illust ids" do
|
||||
assert_artist_not_found("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=herpderp")
|
||||
end
|
||||
|
||||
should "fail for malformed urls" do
|
||||
assert_artist_not_found("http://www.pixiv.net/wharrgarbl")
|
||||
end
|
||||
|
||||
should "not fail for Pixiv bad IDs" do
|
||||
assert_artist_not_found("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=0")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -169,85 +169,12 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "hide deleted artists" do
|
||||
FactoryBot.create(:artist, :name => "warhol", :url_string => "http://warhol.com/a/image.jpg", :is_active => false)
|
||||
as_admin do
|
||||
FactoryBot.create(:artist, name: "warhol", url_string: "http://warhol.com/a/image.jpg", is_active: false)
|
||||
end
|
||||
assert_artist_not_found("http://warhol.com/a/image.jpg")
|
||||
end
|
||||
|
||||
context "when finding pixiv artists" do
|
||||
setup do
|
||||
FactoryBot.create(:artist, :name => "masao",:url_string => "http://www.pixiv.net/member.php?id=32777")
|
||||
FactoryBot.create(:artist, :name => "bkub", :url_string => "http://www.pixiv.net/member.php?id=9948")
|
||||
FactoryBot.create(:artist, :name => "ryuura", :url_string => "http://www.pixiv.net/member.php?id=8678371")
|
||||
end
|
||||
|
||||
should "find the correct artist by looking up the profile url" do
|
||||
assert_artist_found("ryuura", "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=48788677")
|
||||
end
|
||||
|
||||
should "find the correct artist for old image URLs" do
|
||||
assert_artist_found("masao", "http://i2.pixiv.net/img04/img/syounen_no_uta/46170939.jpg")
|
||||
assert_artist_found("bkub", "http://i1.pixiv.net/img01/img/bkubb/46239857_m.jpg")
|
||||
end
|
||||
|
||||
should "find the correct artist for new image URLs" do
|
||||
assert_artist_found("masao", "http://i2.pixiv.net/c/1200x1200/img-master/img/2014/09/25/00/57/24/46170939_p0_master1200.jpg")
|
||||
assert_artist_found("masao", "http://i2.pixiv.net/img-original/img/2014/09/25/00/57/24/46170939_p0.jpg")
|
||||
|
||||
assert_artist_found("bkub", "http://i2.pixiv.net/c/1200x1200/img-master/img/2014/09/28/21/59/44/46239857_p0.jpg")
|
||||
assert_artist_found("bkub", "http://i2.pixiv.net/img-original/img/2014/09/28/21/59/44/46239857_p0.jpg")
|
||||
end
|
||||
|
||||
should "find the correct artist for page URLs" do
|
||||
assert_artist_found("masao", "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46170939")
|
||||
assert_artist_found("masao", "http://www.pixiv.net/member_illust.php?mode=big&illust_id=46170939")
|
||||
assert_artist_found("masao", "http://www.pixiv.net/member_illust.php?mode=manga&illust_id=46170939")
|
||||
assert_artist_found("masao", "http://www.pixiv.net/member_illust.php?mode=manga_big&illust_id=46170939&page=0")
|
||||
assert_artist_found("masao", "http://www.pixiv.net/i/46170939")
|
||||
|
||||
assert_artist_found("bkub", "http://www.pixiv.net/member_illust.php?mode=medium&illust_id=46239857")
|
||||
assert_artist_found("bkub", "http://www.pixiv.net/member_illust.php?mode=big&illust_id=46239857")
|
||||
assert_artist_found("bkub", "http://www.pixiv.net/i/46239857")
|
||||
end
|
||||
|
||||
should "find nothing for bad IDs" do
|
||||
assert_artist_not_found("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=32049358")
|
||||
end
|
||||
end
|
||||
|
||||
context "when finding nico seiga artists" do
|
||||
setup do
|
||||
FactoryBot.create(:artist, :name => "osamari", :url_string => "http://seiga.nicovideo.jp/user/illust/7017777")
|
||||
FactoryBot.create(:artist, :name => "hakuro109", :url_string => "http://seiga.nicovideo.jp/user/illust/16265470")
|
||||
end
|
||||
|
||||
should "find the artist by the profile" do
|
||||
assert_artist_found("osamari", "http://seiga.nicovideo.jp/seiga/im4937663")
|
||||
assert_artist_found("hakuro109", "http://lohas.nicoseiga.jp/priv/b9ea863e691f3a648dee5582fd6911c30dc8acab/1510092103/6424205")
|
||||
end
|
||||
|
||||
should "return nothing for unknown nico seiga artists" do
|
||||
assert_artist_not_found("http://seiga.nicovideo.jp/seiga/im6605221")
|
||||
assert_artist_not_found("http://lohas.nicoseiga.jp/priv/fd195b3405b19874c825eb4d81c9196086562c6b/1509089019/6605221")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context "when finding nijie artists" do
|
||||
setup do
|
||||
FactoryBot.create(:artist, :name => "evazion", :url_string => "http://nijie.info/members.php?id=236014")
|
||||
FactoryBot.create(:artist, :name => "728995", :url_string => "http://nijie.info/members.php?id=728995")
|
||||
end
|
||||
|
||||
should "find the artist" do
|
||||
assert_artist_found("evazion", "http://nijie.info/view.php?id=218944")
|
||||
assert_artist_found("728995", "http://nijie.info/view.php?id=213043")
|
||||
end
|
||||
|
||||
should "return nothing for unknown nijie artists" do
|
||||
assert_artist_not_found("http://nijie.info/view.php?id=157953")
|
||||
end
|
||||
end
|
||||
|
||||
context "when finding tumblr artists" do
|
||||
setup do
|
||||
FactoryBot.create(:artist, :name => "ilya_kuvshinov", :url_string => "http://kuvshinov-ilya.tumblr.com")
|
||||
@ -346,15 +273,6 @@ class ArtistTest < ActiveSupport::TestCase
|
||||
assert_equal(Tag.categories.artist, tag.category)
|
||||
end
|
||||
|
||||
should "update the category of the tag when renamed" do
|
||||
tag = FactoryBot.create(:tag, :name => "def")
|
||||
artist = FactoryBot.create(:artist, :name => "abc")
|
||||
artist.name = "def"
|
||||
artist.save
|
||||
tag.reload
|
||||
assert_equal(Tag.categories.artist, tag.category)
|
||||
end
|
||||
|
||||
context "when saving" do
|
||||
setup do
|
||||
@artist = FactoryBot.create(:artist, url_string: "http://foo.com")
|
||||
|
@ -61,88 +61,16 @@ class ArtistUrlTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
context "artstation urls" do
|
||||
setup do
|
||||
@urls = [
|
||||
FactoryBot.create(:artist_url, url: "https://www.artstation.com/koyorin"),
|
||||
FactoryBot.create(:artist_url, url: "https://koyorin.artstation.com"),
|
||||
FactoryBot.create(:artist_url, url: "https://www.artstation.com/artwork/04XA4")
|
||||
]
|
||||
end
|
||||
|
||||
should "normalize" do
|
||||
assert_equal("http://www.artstation.com/koyorin/", @urls[0].normalized_url)
|
||||
assert_equal("http://www.artstation.com/koyorin/", @urls[1].normalized_url)
|
||||
assert_equal("http://www.artstation.com/jeyrain/", @urls[2].normalized_url)
|
||||
end
|
||||
end
|
||||
|
||||
context "deviantart urls" do
|
||||
setup do
|
||||
@urls = [
|
||||
FactoryBot.create(:artist_url, url: "https://www.deviantart.com/aeror404/art/Holiday-Elincia-424551484"),
|
||||
FactoryBot.create(:artist_url, url: "http://noizave.deviantart.com/art/test-post-please-ignore-685436408"),
|
||||
FactoryBot.create(:artist_url, url: "https://www.deviantart.com/noizave")
|
||||
]
|
||||
end
|
||||
|
||||
should "normalize" do
|
||||
assert_equal("http://www.deviantart.com/aeror404/", @urls[0].normalized_url)
|
||||
assert_equal("http://www.deviantart.com/noizave/", @urls[1].normalized_url)
|
||||
assert_equal("http://www.deviantart.com/noizave/", @urls[2].normalized_url)
|
||||
end
|
||||
end
|
||||
|
||||
context "nicoseiga urls" do
|
||||
setup do
|
||||
@urls = [
|
||||
FactoryBot.create(:artist_url, url: "http://seiga.nicovideo.jp/user/illust/7017777"),
|
||||
FactoryBot.create(:artist_url, url: "http://lohas.nicoseiga.jp/o/910aecf08e542285862954017f8a33a8c32a8aec/1433298801/4937663"),
|
||||
FactoryBot.create(:artist_url, url: "http://seiga.nicovideo.jp/seiga/im4937663")
|
||||
]
|
||||
end
|
||||
|
||||
should "normalize" do
|
||||
assert_equal("http://seiga.nicovideo.jp/user/illust/7017777/", @urls[0].normalized_url)
|
||||
assert_equal("http://seiga.nicovideo.jp/user/illust/7017777/", @urls[1].normalized_url)
|
||||
assert_equal("http://seiga.nicovideo.jp/user/illust/7017777/", @urls[2].normalized_url)
|
||||
end
|
||||
end
|
||||
|
||||
should "normalize fc2 urls" do
|
||||
url = FactoryBot.create(:artist_url, :url => "http://blog55.fc2.com/monet")
|
||||
assert_equal("http://blog55.fc2.com/monet", url.url)
|
||||
assert_equal("http://blog.fc2.com/monet/", url.normalized_url)
|
||||
|
||||
url = FactoryBot.create(:artist_url, :url => "http://blog-imgs-55.fc2.com/monet")
|
||||
assert_equal("http://blog-imgs-55.fc2.com/monet", url.url)
|
||||
assert_equal("http://blog.fc2.com/monet/", url.normalized_url)
|
||||
end
|
||||
|
||||
should "normalize deviant art artist urls" do
|
||||
url = FactoryBot.create(:artist_url, :url => "https://www.deviantart.com/aeror404/art/Holiday-Elincia-424551484")
|
||||
assert_equal("http://www.deviantart.com/aeror404/", url.normalized_url)
|
||||
end
|
||||
|
||||
should "normalize nico seiga artist urls" do
|
||||
url = FactoryBot.create(:artist_url, :url => "http://seiga.nicovideo.jp/user/illust/7017777")
|
||||
assert_equal("http://seiga.nicovideo.jp/user/illust/7017777/", url.normalized_url)
|
||||
|
||||
url = FactoryBot.create(:artist_url, :url => "http://seiga.nicovideo.jp/seiga/im4937663")
|
||||
assert_equal("http://seiga.nicovideo.jp/user/illust/7017777/", url.normalized_url)
|
||||
end
|
||||
|
||||
should "normalize hentai foundry artist urls" do
|
||||
url = FactoryBot.create(:artist_url, :url => "http://pictures.hentai-foundry.com//a/AnimeFlux/219123.jpg")
|
||||
url = FactoryBot.create(:artist_url, :url => "http://pictures.hentai-foundry.com/a/AnimeFlux/219123.jpg")
|
||||
assert_equal("http://pictures.hentai-foundry.com/a/AnimeFlux/219123.jpg/", url.normalized_url)
|
||||
end
|
||||
|
||||
should "normalize pixiv urls" do
|
||||
url = FactoryBot.create(:artist_url, :url => "https://i.pximg.net/img-original/img/2010/11/30/08/39/58/14901720_p0.png")
|
||||
assert_equal("https://i.pximg.net/img-original/img/2010/11/30/08/39/58/14901720_p0.png", url.url)
|
||||
assert_equal("http://www.pixiv.net/member.php?id=339253/", url.normalized_url)
|
||||
end
|
||||
|
||||
should "normalize pixiv stacc urls" do
|
||||
url = FactoryBot.create(:artist_url, :url => "https://www.pixiv.net/stacc/evazion")
|
||||
assert_equal("https://www.pixiv.net/stacc/evazion", url.url)
|
||||
@ -155,38 +83,19 @@ class ArtistUrlTest < ActiveSupport::TestCase
|
||||
assert_equal("http://www.pixiv.net/fanbox/creator/3113804/", url.normalized_url)
|
||||
end
|
||||
|
||||
should "normalize twitter urls" do
|
||||
url = FactoryBot.create(:artist_url, :url => "https://twitter.com/aoimanabu/status/892370963630743552")
|
||||
assert_equal("https://twitter.com/aoimanabu/status/892370963630743552", url.url)
|
||||
assert_equal("http://twitter.com/aoimanabu/", url.normalized_url)
|
||||
end
|
||||
|
||||
should "normalize https://twitter.com/intent/user?user_id=* urls" do
|
||||
url = FactoryBot.create(:artist_url, :url => "https://twitter.com/intent/user?user_id=2784590030")
|
||||
assert_equal("https://twitter.com/intent/user?user_id=2784590030", url.url)
|
||||
assert_equal("http://twitter.com/intent/user?user_id=2784590030/", url.normalized_url)
|
||||
end
|
||||
|
||||
should "normalize nijie urls" do
|
||||
url = FactoryBot.create(:artist_url, url: "https://pic03.nijie.info/nijie_picture/236014_20170620101426_0.png")
|
||||
assert_equal("http://nijie.info/members.php?id=236014/", url.normalized_url)
|
||||
|
||||
url = FactoryBot.create(:artist_url, url: "https://nijie.info/members.php?id=161703")
|
||||
assert_equal("http://nijie.info/members.php?id=161703/", url.normalized_url)
|
||||
|
||||
url = FactoryBot.create(:artist_url, url: "https://www.nijie.info/members_illust.php?id=161703")
|
||||
assert_equal("http://nijie.info/members.php?id=161703/", url.normalized_url)
|
||||
|
||||
url = FactoryBot.create(:artist_url, url: "https://nijie.info/invalid.php")
|
||||
assert_equal("http://nijie.info/invalid.php/", url.normalized_url)
|
||||
end
|
||||
|
||||
context "#search method" do
|
||||
subject { ArtistUrl }
|
||||
|
||||
should "work" do
|
||||
@bkub = FactoryBot.create(:artist, name: "bkub", is_active: true, url_string: "https://bkub.com")
|
||||
@masao = FactoryBot.create(:artist, name: "masao", is_active: false, url_string: "-https://masao.com")
|
||||
as_admin do
|
||||
@masao = FactoryBot.create(:artist, name: "masao", is_active: false, url_string: "-https://masao.com")
|
||||
end
|
||||
@bkub_url = @bkub.urls.first
|
||||
@masao_url = @masao.urls.first
|
||||
|
||||
@ -207,8 +116,6 @@ class ArtistUrlTest < ActiveSupport::TestCase
|
||||
assert_search_equals([@bkub_url], url_ilike: "*BKUB*")
|
||||
assert_search_equals([@bkub_url], url_not_like: "*masao*")
|
||||
assert_search_equals([@bkub_url], url_not_ilike: "*MASAO*")
|
||||
assert_search_equals([@bkub_url], url_regex: "bkub")
|
||||
assert_search_equals([@bkub_url], url_not_regex: "masao")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user