diff --git a/test/app_test.py b/test/app_test.py index 49b92934ca27db633d1b9b2de0e3784eab52ab76..0ea8c6ded5817149a4541215df56b579b242c92f 100644 --- a/test/app_test.py +++ b/test/app_test.py @@ -8,8 +8,9 @@ def test_standard_requests(): """ Tests app controller methods. These tests should be compartmentalized. Also these methods should be made to not retest the behavior of the associated Manager class. """ - from .test_utils import test_app - with test_app(test_conf={"extra_environ": {"REMOTE_ADDR": "127.101.101.98"}}) as app: + from .test_utils import test_lwr_app + + with test_lwr_app(test_conf={"extra_environ": {"REMOTE_ADDR": "127.101.101.98"}}) as app: staging_directory = app.app.staging_directory setup_response = app.get("/setup?job_id=12345") setup_config = json.loads(setup_response.body) diff --git a/test/integration_test.py b/test/integration_test.py index f0eefbc203f45132dd8fd202af027dfb46a75b2e..7ea3fe3c5d63e88367dbc0498797caf4e5e0fa39 100644 --- a/test/integration_test.py +++ b/test/integration_test.py @@ -26,14 +26,14 @@ class BaseIntegrationTest(TempDirectoryTestCase): options["jobs_directory"] = staging_directory if kwds.get("direct_interface", None): - from .test_utils import test_app - with test_app({}, app_conf, {}) as app: + from .test_utils import test_lwr_app + with test_lwr_app({}, app_conf, {}) as app: options = Bunch(job_manager=next(itervalues(app.app.managers)), file_cache=app.app.file_cache, **kwds) update_options_for_app(options, app.app) run(options) else: - from .test_utils import test_server - with test_server(app_conf=app_conf) as server: + from .test_utils import test_lwr_server + with test_lwr_server(app_conf=app_conf) as server: options = Bunch(url=server.application_url, **kwds) update_options_for_app(options, server.test_app.application) run(options) diff --git a/test/lwr_objectstore_test.py b/test/lwr_objectstore_test.py index 6dffcddf466edfc8fc9f4fd9bcb3a672db290611..3fbbe7be37a716a405a52621273ad5c19bd317f7 100644 --- a/test/lwr_objectstore_test.py +++ b/test/lwr_objectstore_test.py @@ -36,8 +36,8 @@ class LwrObjectStoreTest(TempDirectoryTestCase): object_store_config_file=object_store_config_file, private_key="12345", ) - from .test_utils import test_server - with test_server(app_conf=app_conf) as server: + from .test_utils import test_lwr_server + with test_lwr_server(app_conf=app_conf) as server: url = server.application_url # Define a proxy LWR object store. proxy_object_store_config_file = join(self.temp_directory, "proxy_object_store_conf.xml") diff --git a/test/test_utils.py b/test/test_utils.py index ca5a7f89053226d9d404b6217d1435eb0492dfe9..2c872cd7449f28a463c7376fa24fd1376ea1c02c 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -120,24 +120,30 @@ class TestDependencyManager(object): @contextmanager -def test_server(global_conf={}, app_conf={}, test_conf={}): - with test_app(global_conf, app_conf, test_conf) as app: - try: - from paste.exceptions.errormiddleware import ErrorMiddleware - error_app = ErrorMiddleware(app.app, debug=True, error_log="errors") - except ImportError: - # paste.exceptions not available for Python 3. - error_app = app - server = StopableWSGIServer.create(error_app) - try: - server.wait() - yield server - finally: - server.shutdown() +def server_for_test_app(app): + try: + from paste.exceptions.errormiddleware import ErrorMiddleware + error_app = ErrorMiddleware(app.app, debug=True, error_log="errors") + except ImportError: + # paste.exceptions not available for Python 3. + error_app = app + server = StopableWSGIServer.create(error_app) + try: + server.wait() + yield server + finally: + server.shutdown() + + +@contextmanager +def test_lwr_server(global_conf={}, app_conf={}, test_conf={}): + with test_lwr_app(global_conf, app_conf, test_conf) as app: + with server_for_test_app(app) as test_lwr_server: + yield test_lwr_server @contextmanager -def test_app(global_conf={}, app_conf={}, test_conf={}): +def test_lwr_app(global_conf={}, app_conf={}, test_conf={}): staging_directory = mkdtemp() # Make staging directory world executable for run as user tests. mode = stat(staging_directory).st_mode @@ -149,8 +155,7 @@ def test_app(global_conf={}, app_conf={}, test_conf={}): from lwr.app import app_factory app = app_factory(global_conf, **app_conf) - test_app = TestApp(app, **test_conf) - yield test_app + yield TestApp(app, **test_conf) finally: try: app.shutdown()