2017-02-27 19:07:51 -08:00
|
|
|
from gevent import monkey; monkey.patch_all(thread=False)
|
|
|
|
|
2017-05-03 20:05:07 -07:00
|
|
|
import pytest
|
2017-04-29 13:47:54 -07:00
|
|
|
import webtest
|
2017-02-27 19:07:51 -08:00
|
|
|
|
2017-05-23 19:08:29 -07:00
|
|
|
from pywb.warcserver.test.testutils import BaseTestClass
|
2017-02-27 19:07:51 -08:00
|
|
|
|
2017-05-23 19:08:29 -07:00
|
|
|
from pywb.apps.frontendapp import FrontEndApp
|
2017-02-27 19:07:51 -08:00
|
|
|
import os
|
|
|
|
|
|
|
|
|
2017-05-03 20:05:07 -07:00
|
|
|
@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 ''
|
|
|
|
|
|
|
|
|
2017-02-27 19:07:51 -08:00
|
|
|
# ============================================================================
|
|
|
|
class BaseConfigTest(BaseTestClass):
|
|
|
|
@classmethod
|
2017-05-03 20:05:07 -07:00
|
|
|
def get_test_app(cls, config_file, override=None):
|
2017-02-27 19:07:51 -08:00
|
|
|
config_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), config_file)
|
2017-05-03 20:05:07 -07:00
|
|
|
return webtest.TestApp(FrontEndApp(config_file=config_file, custom_config=override))
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setup_class(cls, config_file, include_non_frame=True):
|
|
|
|
super(BaseConfigTest, cls).setup_class()
|
|
|
|
cls.testapp = cls.get_test_app(config_file)
|
|
|
|
|
|
|
|
if include_non_frame:
|
|
|
|
cls.testapp_non_frame = cls.get_test_app(config_file,
|
|
|
|
override={'framed_replay': False})
|
|
|
|
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)
|
2017-02-27 19:07:51 -08:00
|
|
|
|
|
|
|
|