1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00
pywb/tests/base_config_test.py
Ilya Kreymer 93921aadb7 Recorder App Support (#241)
recording support: now available for dynamic collections via config
- config.yaml 'recorder: live' entry enables /record/ subpath which records to any dynamic collections (can record from any collection, though usually live)
- autoindex refactor: simplified, standalone AutoIndexer() -- indexes any changed warc files to autoindex.cdxj
- windows autoindex support: also check for changed file size, as last modified time may not be changing
- manager: remove autoindex, now part of main cli
- tests: updated test_auto_colls with autoindex changes
- tests: add record/replay tests for recording and replay
2017-09-21 22:12:57 -07:00

95 lines
3.2 KiB
Python

from gevent import monkey; monkey.patch_all(thread=False)
import pytest
import webtest
from pywb.warcserver.test.testutils import BaseTestClass, TempDirTests
from pywb.manager.manager import main, CollectionsManager
from pywb.apps.frontendapp import FrontEndApp
import os
@pytest.fixture(params=['mp_', ''], ids=['frame', 'non-frame'])
def fmod(request):
return request.param
@pytest.fixture(params=['mp_', ''], ids=['frame', 'non-frame'])
def fmod_sl(request):
return request.param + '/' if request.param else ''
# ============================================================================
class BaseConfigTest(BaseTestClass):
@classmethod
def get_test_app(cls, config_file, override=None):
config_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), config_file)
app = FrontEndApp(config_file=config_file, custom_config=override)
return app, webtest.TestApp(app)
@classmethod
def setup_class(cls, config_file, include_non_frame=True):
super(BaseConfigTest, cls).setup_class()
cls.app, cls.testapp = cls.get_test_app(config_file)
if include_non_frame:
cls.app_non_frame, cls.testapp_non_frame = cls.get_test_app(config_file,
override={'framed_replay': False})
@classmethod
def teardown_class(cls):
if cls.app.recorder:
cls.app.recorder.writer.close()
if cls.app_non_frame.recorder:
cls.app_non_frame.recorder.writer.close()
super(BaseConfigTest, cls).teardown_class()
def _assert_basic_html(self, resp):
assert resp.status_int == 200
assert resp.content_type == 'text/html'
assert resp.content_length > 0
def _assert_basic_text(self, resp):
assert resp.status_int == 200
assert resp.content_type == 'text/plain'
assert resp.content_length > 0
def get(self, url, fmod, *args, **kwargs):
app = self.testapp if fmod else self.testapp_non_frame
return app.get(url.format(fmod), *args, **kwargs)
def post(self, url, fmod, *args, **kwargs):
app = self.testapp if fmod else self.testapp_non_frame
return app.post(url.format(fmod), *args, **kwargs)
def post_json(self, url, fmod, *args, **kwargs):
app = self.testapp if fmod else self.testapp_non_frame
return app.post_json(url.format(fmod), *args, **kwargs)
def head(self, url, fmod, *args, **kwargs):
app = self.testapp if fmod else self.testapp_non_frame
return app.head(url.format(fmod), *args, **kwargs)
#=============================================================================
class CollsDirMixin(TempDirTests):
COLLS_DIR = '_test_colls'
@classmethod
def setup_class(cls, *args, **kwargs):
super(CollsDirMixin, cls).setup_class(*args, **kwargs)
cls.orig_cwd = os.getcwd()
cls.root_dir = os.path.realpath(cls.root_dir)
os.chdir(cls.root_dir)
cls.orig_collections = CollectionsManager.COLLS_DIR
CollectionsManager.COLLS_DIR = cls.COLLS_DIR
@classmethod
def teardown_class(cls):
os.chdir(cls.orig_cwd)
CollectionsManager.COLLS_DIR = cls.orig_collections
super(CollsDirMixin, cls).teardown_class()