add logic for persisting pixiv sessions in tests
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user