fix: add app handler methods: get_node_title()
, get_node_type()
This commit is contained in:
parent
bb7a83a73c
commit
1744e8706c
|
@ -152,6 +152,45 @@ class AppHandler:
|
||||||
return self.config.get(f'{self.appname}.app_title',
|
return self.config.get(f'{self.appname}.app_title',
|
||||||
default=default or self.default_app_title)
|
default=default or self.default_app_title)
|
||||||
|
|
||||||
|
def get_node_title(self, default=None):
|
||||||
|
"""
|
||||||
|
Returns the configured title for the local app node.
|
||||||
|
|
||||||
|
If none is configured, and no default provided, will return
|
||||||
|
the value from :meth:`get_title()`.
|
||||||
|
|
||||||
|
:param default: Value to use if the node title is not
|
||||||
|
configured.
|
||||||
|
|
||||||
|
:returns: Title for the local app node.
|
||||||
|
"""
|
||||||
|
title = self.config.get(f'{self.appname}.node_title')
|
||||||
|
if title:
|
||||||
|
return title
|
||||||
|
return self.get_title(default=default)
|
||||||
|
|
||||||
|
def get_node_type(self, default=None):
|
||||||
|
"""
|
||||||
|
Returns the "type" of current app node.
|
||||||
|
|
||||||
|
The framework itself does not (yet?) have any notion of what a
|
||||||
|
node type means. This abstraction is here for convenience, in
|
||||||
|
case it is needed by a particular app ecosystem.
|
||||||
|
|
||||||
|
:returns: String name for the node type, or ``None``.
|
||||||
|
|
||||||
|
The node type must be configured via file; this cannot be done
|
||||||
|
with a DB setting. Depending on :attr:`appname` that is like
|
||||||
|
so:
|
||||||
|
|
||||||
|
.. code-block:: ini
|
||||||
|
|
||||||
|
[wutta]
|
||||||
|
node_type = warehouse
|
||||||
|
"""
|
||||||
|
return self.config.get(f'{self.appname}.node_type', default=default,
|
||||||
|
usedb=False)
|
||||||
|
|
||||||
def get_distribution(self, obj=None):
|
def get_distribution(self, obj=None):
|
||||||
"""
|
"""
|
||||||
Returns the appropriate Python distribution name.
|
Returns the appropriate Python distribution name.
|
||||||
|
|
|
@ -179,6 +179,28 @@ class TestAppHandler(TestCase):
|
||||||
def test_get_title(self):
|
def test_get_title(self):
|
||||||
self.assertEqual(self.app.get_title(), 'WuttJamaican')
|
self.assertEqual(self.app.get_title(), 'WuttJamaican')
|
||||||
|
|
||||||
|
def test_get_node_title(self):
|
||||||
|
|
||||||
|
# default
|
||||||
|
self.assertEqual(self.app.get_node_title(), 'WuttJamaican')
|
||||||
|
|
||||||
|
# will fallback to app title
|
||||||
|
self.config.setdefault('wuttatest.app_title', "WuttaTest")
|
||||||
|
self.assertEqual(self.app.get_node_title(), 'WuttaTest')
|
||||||
|
|
||||||
|
# will read from config
|
||||||
|
self.config.setdefault('wuttatest.node_title', "WuttaNode")
|
||||||
|
self.assertEqual(self.app.get_node_title(), 'WuttaNode')
|
||||||
|
|
||||||
|
def test_get_node_type(self):
|
||||||
|
|
||||||
|
# default
|
||||||
|
self.assertIsNone(self.app.get_node_type())
|
||||||
|
|
||||||
|
# will read from config
|
||||||
|
self.config.setdefault('wuttatest.node_type', 'warehouse')
|
||||||
|
self.assertEqual(self.app.get_node_type(), 'warehouse')
|
||||||
|
|
||||||
def test_get_distribution(self):
|
def test_get_distribution(self):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue