From 66b6eb341e4a82924cd2d856ee690b7a0f146a7b Mon Sep 17 00:00:00 2001 From: spl0k Date: Mon, 29 Jan 2018 22:09:28 +0100 Subject: [PATCH] Tests: removed context/module unload dance Was a workaround for issues fixed by blueprints --- supysonic/web.py | 13 ++++++------- tests/api/test_response_helper.py | 10 ++-------- tests/testbase.py | 23 +---------------------- 3 files changed, 9 insertions(+), 37 deletions(-) diff --git a/supysonic/web.py b/supysonic/web.py index 4c58b34..d161a8c 100644 --- a/supysonic/web.py +++ b/supysonic/web.py @@ -61,13 +61,12 @@ def create_application(config = None): makedirs(cache_path) # Import app sections - with app.app_context(): - if app.config['WEBAPP']['mount_webui']: - from .frontend import frontend - app.register_blueprint(frontend) - if app.config['WEBAPP']['mount_api']: - from .api import api - app.register_blueprint(api, url_prefix = '/rest') + if app.config['WEBAPP']['mount_webui']: + from .frontend import frontend + app.register_blueprint(frontend) + if app.config['WEBAPP']['mount_api']: + from .api import api + app.register_blueprint(api, url_prefix = '/rest') return app diff --git a/tests/api/test_response_helper.py b/tests/api/test_response_helper.py index e29f581..a632179 100644 --- a/tests/api/test_response_helper.py +++ b/tests/api/test_response_helper.py @@ -23,23 +23,17 @@ class ResponseHelperBaseCase(TestBase): super(ResponseHelperBaseCase, self).setUp() from supysonic.api.formatters import make_json_response, make_jsonp_response, make_xml_response - self.json = self.__json_unwrapper(make_json_response) + self.json = self.__response_unwrapper(make_json_response) self.jsonp = self.__response_unwrapper(make_jsonp_response) self.xml = self.__response_unwrapper(make_xml_response) - def __json_unwrapper(self, func): + def __response_unwrapper(self, func): def execute(*args, **kwargs): with self.request_context(): rv = func(*args, **kwargs) return rv.get_data(as_text = True) return execute - def __response_unwrapper(self, func): - def execute(*args, **kwargs): - rv = func(*args, **kwargs) - return rv.get_data(as_text = True) - return execute - class ResponseHelperJsonTestCase(ResponseHelperBaseCase): def serialize_and_deserialize(self, d, error = False): if not isinstance(d, dict): diff --git a/tests/testbase.py b/tests/testbase.py index e907a7f..300d78f 100644 --- a/tests/testbase.py +++ b/tests/testbase.py @@ -12,12 +12,9 @@ import inspect import io import os import shutil -import sys import unittest import tempfile -from contextlib import contextmanager - from supysonic.db import init_database, release_database from supysonic.config import DefaultConfig from supysonic.managers.user import UserManager @@ -96,9 +93,6 @@ class TestBase(unittest.TestCase): release_database() self.__app = create_application(config) - self.__ctx = self.__app.app_context() - self.__ctx.push() - self.client = self.__app.test_client() UserManager.add('alice', 'Alic3', 'test@example.com', True) @@ -108,26 +102,11 @@ class TestBase(unittest.TestCase): self.client.get = patch_method(self.client.get) self.client.post = patch_method(self.client.post) - @contextmanager def request_context(self, *args, **kwargs): - ctx = self.__app.test_request_context(*args, **kwargs) - ctx.push() - yield - ctx.pop() - - @staticmethod - def __should_unload_module(module): - if module.startswith('supysonic'): - return not module.startswith('supysonic.db') - return False + return self.__app.test_request_context(*args, **kwargs) def tearDown(self): - self.__ctx.pop() release_database() shutil.rmtree(self.__dir) os.remove(self.__dbfile) - to_unload = [ m for m in sorted(sys.modules) if self.__should_unload_module(m) ] - for m in to_unload: - del sys.modules[m] -