add logic for persisting pixiv sessions in tests

This commit is contained in:
Albert Yi
2018-05-10 13:58:42 -07:00
parent 76eeafca2c
commit 6839249e9d
5 changed files with 41 additions and 1 deletions

View File

@@ -154,6 +154,9 @@ class PixivApiClient
else
raise Error.new("Pixiv API call failed (status=#{resp.code} body=#{body})")
end
rescue Net::OpenTimeout
sleep(5)
retry
rescue JSON::ParserError
raise Error.new("Pixiv API call failed (status=#{resp.code} body=#{body})")
end
@@ -173,7 +176,7 @@ class PixivApiClient
}
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")
if resp.success?

View File

@@ -48,6 +48,7 @@ services:
- DANBOORU_NIJIE_PASSWORD
- DANBOORU_NICO_SEIGA_LOGIN
- DANBOORU_NICO_SEIGA_PASSWORD
- DANBOORU_PERSIST_PIXIV_SESSION
build:
context: ../..
dockerfile: config/docker/danbooru-ci

View File

@@ -44,6 +44,22 @@ module TestHelpers
def as_admin(&block)
CurrentUser.as_admin(&block)
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

View File

@@ -2,6 +2,16 @@ require 'test_helper'
module Downloads
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
setup do
@download = Downloads::File.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=62247364")

View File

@@ -8,6 +8,16 @@ module Sources
@site
end
def setup
super
load_pixiv_tokens!
end
def teardown
save_pixiv_tokens!
super
end
context "in all cases" do
context "A touch page" do
setup do