1
0
Fork 0

Add generic handler base class, tests, docs

This commit is contained in:
Lance Edgar 2023-11-25 16:28:37 -06:00
parent 27a90b2a87
commit d73ff274df
2 changed files with 29 additions and 0 deletions

View file

@ -281,3 +281,19 @@ class AppProvider:
self.config = config
self.app = config.get_app()
class GenericHandler:
"""
Generic base class for handlers.
When the :term:`app` defines a new *type* of :term:`handler` it
may subclass this when defining the handler base class.
:param config: Config object for the app. This should be an
instance of :class:`~wuttjamaican.conf.WuttaConfig`.
"""
def __init__(self, config, **kwargs):
self.config = config
self.app = self.config.get_app()

View file

@ -188,3 +188,16 @@ class TestAppProvider(TestCase):
# but provider can supply the attr
self.app.providers['mytest'] = MagicMock(foo_value='bar')
self.assertEqual(self.app.foo_value, 'bar')
class TestGenericHandler(TestCase):
def setUp(self):
self.config = WuttaConfig(appname='wuttatest')
self.app = app.AppHandler(self.config)
self.config.app = self.app
def test_constructor(self):
handler = app.GenericHandler(self.config)
self.assertIs(handler.config, self.config)
self.assertIs(handler.app, self.app)