add logic for persisting pixiv sessions in tests
This commit is contained in:
@@ -154,6 +154,9 @@ class PixivApiClient
|
|||||||
else
|
else
|
||||||
raise Error.new("Pixiv API call failed (status=#{resp.code} body=#{body})")
|
raise Error.new("Pixiv API call failed (status=#{resp.code} body=#{body})")
|
||||||
end
|
end
|
||||||
|
rescue Net::OpenTimeout
|
||||||
|
sleep(5)
|
||||||
|
retry
|
||||||
rescue JSON::ParserError
|
rescue JSON::ParserError
|
||||||
raise Error.new("Pixiv API call failed (status=#{resp.code} body=#{body})")
|
raise Error.new("Pixiv API call failed (status=#{resp.code} body=#{body})")
|
||||||
end
|
end
|
||||||
@@ -173,7 +176,7 @@ class PixivApiClient
|
|||||||
}
|
}
|
||||||
url = "https://oauth.secure.pixiv.net/auth/token"
|
url = "https://oauth.secure.pixiv.net/auth/token"
|
||||||
|
|
||||||
resp = HTTParty.post(url, Danbooru.config.httparty_options.deep_merge(timeout: 20, body: params, headers: headers))
|
resp = HTTParty.post(url, Danbooru.config.httparty_options.deep_merge(body: params, headers: headers))
|
||||||
body = resp.body.force_encoding("utf-8")
|
body = resp.body.force_encoding("utf-8")
|
||||||
|
|
||||||
if resp.success?
|
if resp.success?
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ services:
|
|||||||
- DANBOORU_NIJIE_PASSWORD
|
- DANBOORU_NIJIE_PASSWORD
|
||||||
- DANBOORU_NICO_SEIGA_LOGIN
|
- DANBOORU_NICO_SEIGA_LOGIN
|
||||||
- DANBOORU_NICO_SEIGA_PASSWORD
|
- DANBOORU_NICO_SEIGA_PASSWORD
|
||||||
|
- DANBOORU_PERSIST_PIXIV_SESSION
|
||||||
build:
|
build:
|
||||||
context: ../..
|
context: ../..
|
||||||
dockerfile: config/docker/danbooru-ci
|
dockerfile: config/docker/danbooru-ci
|
||||||
|
|||||||
@@ -44,6 +44,22 @@ module TestHelpers
|
|||||||
def as_admin(&block)
|
def as_admin(&block)
|
||||||
CurrentUser.as_admin(&block)
|
CurrentUser.as_admin(&block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def load_pixiv_tokens!
|
||||||
|
if ENV["DANBOORU_PERSIST_PIXIV_SESSION"] && Cache.get("pixiv-papi-access-token")
|
||||||
|
Cache.put("pixiv-papi-access-token", Thread.current[:pixiv_papi_access_token])
|
||||||
|
Cache.put(PixivWebAgent::SESSION_CACHE_KEY, Thread.current[:pixiv_session_cache_key])
|
||||||
|
Cache.put(PixivWebAgent::COMIC_SESSION_CACHE_KEY, Thread.current[:pixiv_comic_session_cache_key])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def save_pixiv_tokens!
|
||||||
|
if ENV["DANBOORU_PERSIST_PIXIV_SESSION"]
|
||||||
|
Thread.current[:pixiv_papi_access_token] = Cache.get("pixiv-papi-access-token")
|
||||||
|
Thread.current[:pixiv_session_cache_key] = Cache.get(PixivWebAgent::SESSION_CACHE_KEY)
|
||||||
|
Thread.current[:pixiv_comic_session_cache_key] = Cache.get(PixivWebAgent::COMIC_SESSION_CACHE_KEY)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,16 @@ require 'test_helper'
|
|||||||
|
|
||||||
module Downloads
|
module Downloads
|
||||||
class PixivTest < ActiveSupport::TestCase
|
class PixivTest < ActiveSupport::TestCase
|
||||||
|
def setup
|
||||||
|
super
|
||||||
|
load_pixiv_tokens!
|
||||||
|
end
|
||||||
|
|
||||||
|
def teardown
|
||||||
|
save_pixiv_tokens!
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
context "An ugoira site for pixiv" do
|
context "An ugoira site for pixiv" do
|
||||||
setup do
|
setup do
|
||||||
@download = Downloads::File.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364")
|
@download = Downloads::File.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364")
|
||||||
|
|||||||
@@ -8,6 +8,16 @@ module Sources
|
|||||||
@site
|
@site
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def setup
|
||||||
|
super
|
||||||
|
load_pixiv_tokens!
|
||||||
|
end
|
||||||
|
|
||||||
|
def teardown
|
||||||
|
save_pixiv_tokens!
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
context "in all cases" do
|
context "in all cases" do
|
||||||
context "A touch page" do
|
context "A touch page" do
|
||||||
setup do
|
setup do
|
||||||
|
|||||||
Reference in New Issue
Block a user