1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-10 04:02:17 +00:00

Tests: removed context/module unload dance

Was a workaround for issues fixed by blueprints
This commit is contained in:
spl0k 2018-01-29 22:09:28 +01:00
parent 7455711b60
commit 66b6eb341e
3 changed files with 9 additions and 37 deletions

View File

@ -61,7 +61,6 @@ def create_application(config = None):
makedirs(cache_path) makedirs(cache_path)
# Import app sections # Import app sections
with app.app_context():
if app.config['WEBAPP']['mount_webui']: if app.config['WEBAPP']['mount_webui']:
from .frontend import frontend from .frontend import frontend
app.register_blueprint(frontend) app.register_blueprint(frontend)

View File

@ -23,19 +23,13 @@ class ResponseHelperBaseCase(TestBase):
super(ResponseHelperBaseCase, self).setUp() super(ResponseHelperBaseCase, self).setUp()
from supysonic.api.formatters import make_json_response, make_jsonp_response, make_xml_response 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.jsonp = self.__response_unwrapper(make_jsonp_response)
self.xml = self.__response_unwrapper(make_xml_response) self.xml = self.__response_unwrapper(make_xml_response)
def __json_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 __response_unwrapper(self, func):
def execute(*args, **kwargs): def execute(*args, **kwargs):
with self.request_context():
rv = func(*args, **kwargs) rv = func(*args, **kwargs)
return rv.get_data(as_text = True) return rv.get_data(as_text = True)
return execute return execute

View File

@ -12,12 +12,9 @@ import inspect
import io import io
import os import os
import shutil import shutil
import sys
import unittest import unittest
import tempfile import tempfile
from contextlib import contextmanager
from supysonic.db import init_database, release_database from supysonic.db import init_database, release_database
from supysonic.config import DefaultConfig from supysonic.config import DefaultConfig
from supysonic.managers.user import UserManager from supysonic.managers.user import UserManager
@ -96,9 +93,6 @@ class TestBase(unittest.TestCase):
release_database() release_database()
self.__app = create_application(config) self.__app = create_application(config)
self.__ctx = self.__app.app_context()
self.__ctx.push()
self.client = self.__app.test_client() self.client = self.__app.test_client()
UserManager.add('alice', 'Alic3', 'test@example.com', True) 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.get = patch_method(self.client.get)
self.client.post = patch_method(self.client.post) self.client.post = patch_method(self.client.post)
@contextmanager
def request_context(self, *args, **kwargs): def request_context(self, *args, **kwargs):
ctx = self.__app.test_request_context(*args, **kwargs) return 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
def tearDown(self): def tearDown(self):
self.__ctx.pop()
release_database() release_database()
shutil.rmtree(self.__dir) shutil.rmtree(self.__dir)
os.remove(self.__dbfile) 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]