From 94262546d553959f6c483f76e52633a70ba0be6e Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Wed, 3 May 2017 20:05:07 -0700 Subject: [PATCH] integration tests: add fixture to run all relevant tests in framed and non-framed mode rename test_framed_inverse -> test_memento, remove unneeded test config --- tests/base_config_test.py | 50 ++++- tests/config_test.yaml | 2 + tests/config_test_frames.yaml | 14 -- tests/test_integration.py | 212 +++++++----------- tests/test_live_rewriter.py | 26 +-- ...test_framed_inverse.py => test_memento.py} | 17 +- 6 files changed, 154 insertions(+), 167 deletions(-) delete mode 100644 tests/config_test_frames.yaml rename tests/{test_framed_inverse.py => test_memento.py} (69%) diff --git a/tests/base_config_test.py b/tests/base_config_test.py index 18a66baa..0a4ddb7d 100644 --- a/tests/base_config_test.py +++ b/tests/base_config_test.py @@ -1,5 +1,6 @@ from gevent import monkey; monkey.patch_all(thread=False) +import pytest import webtest from pywb.webagg.test.testutils import BaseTestClass @@ -8,12 +9,55 @@ from pywb.urlrewrite.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 setup_class(cls, config_file): - super(BaseConfigTest, cls).setup_class() + def get_test_app(cls, config_file, override=None): config_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), config_file) - cls.testapp = webtest.TestApp(FrontEndApp(config_file=config_file)) + 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) diff --git a/tests/config_test.yaml b/tests/config_test.yaml index 701ee419..a52fac1d 100644 --- a/tests/config_test.yaml +++ b/tests/config_test.yaml @@ -31,3 +31,5 @@ archive_paths: - ./sample_archive/warcs/ +enable_memento: true + diff --git a/tests/config_test_frames.yaml b/tests/config_test_frames.yaml deleted file mode 100644 index e27dfa92..00000000 --- a/tests/config_test_frames.yaml +++ /dev/null @@ -1,14 +0,0 @@ -collections: - # : - # collection will be accessed via / - # is a string or list of: - # - string or list of one or more local .cdx file - # - string or list of one or more local dirs with .cdx files - # - a string value indicating remote http cdx server - pywb: ./sample_archive/cdx/ - -archive_paths: ./sample_archive/warcs/ - -enable_memento: true - -framed_replay: inverse diff --git a/tests/test_integration.py b/tests/test_integration.py index 9801f426..35988b80 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -1,4 +1,4 @@ -from .base_config_test import BaseConfigTest +from .base_config_test import BaseConfigTest, fmod from pywb.cdx.cdxobject import CDXObject @@ -9,16 +9,6 @@ class TestWbIntegration(BaseConfigTest): def setup_class(cls): super(TestWbIntegration, cls).setup_class('config_test.yaml') - 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 test_home(self): resp = self.testapp.get('/') self._assert_basic_html(resp) @@ -87,82 +77,67 @@ class TestWbIntegration(BaseConfigTest): assert '