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

@@ -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