fix: let config class specify default app handler, engine maker
this avoids the need for a config subclass to use `setdefault()` hacks to specify default app handler for instance, since that approach must compete with config extensions who also may wish to do that. similar concept for the engine maker; notably the rattail project needs to override this function somewhat and we need a way to allow for that without (re-)introducing the app handler here.
This commit is contained in:
parent
c3efbfbf7b
commit
a25712ef54
3 changed files with 68 additions and 4 deletions
|
@ -10,6 +10,7 @@ import sqlalchemy as sa
|
|||
from wuttjamaican import conf
|
||||
from wuttjamaican.exc import ConfigurationError
|
||||
from wuttjamaican.db import Session
|
||||
from wuttjamaican.db.conf import make_engine_from_config
|
||||
from wuttjamaican.app import AppHandler
|
||||
from wuttjamaican.testing import FileConfigTestCase
|
||||
|
||||
|
@ -386,12 +387,43 @@ configure_logging = true
|
|||
self.assertEqual(config.get_list('foo.bar'), ['hello', 'world'])
|
||||
|
||||
def test_get_app(self):
|
||||
|
||||
# default handler
|
||||
config = conf.WuttaConfig()
|
||||
self.assertEqual(config.default_app_handler_spec, 'wuttjamaican.app:AppHandler')
|
||||
app = config.get_app()
|
||||
# make sure we get the true default handler class
|
||||
self.assertIsInstance(app, AppHandler)
|
||||
# nb. make extra sure we didn't get a subclass
|
||||
self.assertIs(type(app), AppHandler)
|
||||
|
||||
# custom default handler
|
||||
config = conf.WuttaConfig()
|
||||
config.default_app_handler_spec = 'tests.test_conf:CustomAppHandler'
|
||||
app = config.get_app()
|
||||
self.assertIsInstance(app, CustomAppHandler)
|
||||
|
||||
def test_get_engine_maker(self):
|
||||
|
||||
# default func
|
||||
config = conf.WuttaConfig()
|
||||
self.assertEqual(config.default_engine_maker_spec, 'wuttjamaican.db.conf:make_engine_from_config')
|
||||
make_engine = config.get_engine_maker()
|
||||
self.assertIs(make_engine, make_engine_from_config)
|
||||
|
||||
# custom default func
|
||||
config = conf.WuttaConfig()
|
||||
config.default_engine_maker_spec = 'tests.test_conf:custom_make_engine_from_config'
|
||||
make_engine = config.get_engine_maker()
|
||||
self.assertIs(make_engine, custom_make_engine_from_config)
|
||||
|
||||
|
||||
class CustomAppHandler(AppHandler):
|
||||
pass
|
||||
|
||||
|
||||
def custom_make_engine_from_config(*args, **kwargs):
|
||||
pass
|
||||
|
||||
|
||||
class TestWuttaConfigExtension(TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue