mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 17:06: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,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)
|
||||||
|
@ -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
|
||||||
|
@ -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]
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user