fix: add get_batch_handler()
method for app handler
also `get_batch_handler_specs()`
This commit is contained in:
parent
174a17dd5e
commit
a302f323af
2 changed files with 157 additions and 6 deletions
|
@ -19,7 +19,15 @@ from wuttjamaican import app as mod
|
|||
from wuttjamaican.progress import ProgressBase
|
||||
from wuttjamaican.conf import WuttaConfig
|
||||
from wuttjamaican.util import UNSPECIFIED
|
||||
from wuttjamaican.testing import FileTestCase
|
||||
from wuttjamaican.testing import FileTestCase, ConfigTestCase
|
||||
from wuttjamaican.batch import BatchHandler
|
||||
|
||||
|
||||
class MockBatchHandler(BatchHandler):
|
||||
pass
|
||||
|
||||
class AnotherBatchHandler(BatchHandler):
|
||||
pass
|
||||
|
||||
|
||||
class TestAppHandler(FileTestCase):
|
||||
|
@ -546,6 +554,59 @@ app_title = WuttaTest
|
|||
auth = self.app.get_auth_handler()
|
||||
self.assertIsInstance(auth, AuthHandler)
|
||||
|
||||
def test_get_batch_handler(self):
|
||||
|
||||
# error if handler not found
|
||||
self.assertRaises(KeyError, self.app.get_batch_handler, 'CannotFindMe!')
|
||||
|
||||
# caller can specify default
|
||||
handler = self.app.get_batch_handler('foo', default='wuttjamaican.batch:BatchHandler')
|
||||
self.assertIsInstance(handler, BatchHandler)
|
||||
|
||||
# default can be configured
|
||||
self.config.setdefault('wuttatest.batch.foo.handler.default_spec',
|
||||
'wuttjamaican.batch:BatchHandler')
|
||||
handler = self.app.get_batch_handler('foo')
|
||||
self.assertIsInstance(handler, BatchHandler)
|
||||
|
||||
# preference can be configured
|
||||
self.config.setdefault('wuttatest.batch.foo.handler.spec',
|
||||
'tests.test_app:MockBatchHandler')
|
||||
handler = self.app.get_batch_handler('foo')
|
||||
self.assertIsInstance(handler, MockBatchHandler)
|
||||
|
||||
def test_get_batch_handler_specs(self):
|
||||
|
||||
# empty by default
|
||||
specs = self.app.get_batch_handler_specs('foo')
|
||||
self.assertEqual(specs, [])
|
||||
|
||||
# caller can specify default as string
|
||||
specs = self.app.get_batch_handler_specs('foo', default='wuttjamaican.batch:BatchHandler')
|
||||
self.assertEqual(specs, ['wuttjamaican.batch:BatchHandler'])
|
||||
|
||||
# caller can specify default as list
|
||||
specs = self.app.get_batch_handler_specs('foo', default=['wuttjamaican.batch:BatchHandler',
|
||||
'tests.test_app:MockBatchHandler'])
|
||||
self.assertEqual(specs, ['wuttjamaican.batch:BatchHandler',
|
||||
'tests.test_app:MockBatchHandler'])
|
||||
|
||||
# default can be configured
|
||||
self.config.setdefault('wuttatest.batch.foo.handler.default_spec',
|
||||
'wuttjamaican.batch:BatchHandler')
|
||||
specs = self.app.get_batch_handler_specs('foo')
|
||||
self.assertEqual(specs, ['wuttjamaican.batch:BatchHandler'])
|
||||
|
||||
# the rest come from entry points
|
||||
with patch.object(mod, 'load_entry_points', return_value={
|
||||
'mock': MockBatchHandler,
|
||||
'another': AnotherBatchHandler,
|
||||
}):
|
||||
specs = self.app.get_batch_handler_specs('foo')
|
||||
self.assertEqual(specs, ['wuttjamaican.batch:BatchHandler',
|
||||
'tests.test_app:AnotherBatchHandler',
|
||||
'tests.test_app:MockBatchHandler'])
|
||||
|
||||
def test_get_db_handler(self):
|
||||
try:
|
||||
from wuttjamaican.db.handler import DatabaseHandler
|
||||
|
@ -684,15 +745,17 @@ class TestAppProvider(TestCase):
|
|||
self.assertEqual(self.app.foo_value, 'bar')
|
||||
|
||||
|
||||
class TestGenericHandler(TestCase):
|
||||
class TestGenericHandler(ConfigTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.config = WuttaConfig(appname='wuttatest')
|
||||
self.app = mod.AppHandler(self.config)
|
||||
self.config._app = self.app
|
||||
def make_config(self, **kw):
|
||||
kw.setdefault('appname', 'wuttatest')
|
||||
return super().make_config(**kw)
|
||||
|
||||
def test_constructor(self):
|
||||
handler = mod.GenericHandler(self.config)
|
||||
self.assertIs(handler.config, self.config)
|
||||
self.assertIs(handler.app, self.app)
|
||||
self.assertEqual(handler.appname, 'wuttatest')
|
||||
|
||||
def test_get_spec(self):
|
||||
self.assertEqual(mod.GenericHandler.get_spec(), 'wuttjamaican.app:GenericHandler')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue