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:
parent
7455711b60
commit
66b6eb341e
@ -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
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user