Add application_name to ConfigurationAdapter
Add a new property to the base ConfigurationAdapter to allow the name of the deployed charm, known as an 'application', to be used within templates. Change-Id: I2e120649440430d9131bf98a85ebd4e5177e95c9
This commit is contained in:
parent
96a0b1e95a
commit
b79e94ba03
|
@ -482,6 +482,11 @@ class ConfigurationAdapter(object):
|
|||
return self._charm_instance_weakref()
|
||||
return None
|
||||
|
||||
@property
|
||||
def application_name(self):
|
||||
"""Return the name of the deployed charm"""
|
||||
return hookenv.service_name()
|
||||
|
||||
|
||||
class APIConfigurationAdapter(ConfigurationAdapter):
|
||||
"""This configuration adapter extends the base class and adds properties
|
||||
|
|
|
@ -392,6 +392,13 @@ class TestConfigurationAdapter(unittest.TestCase):
|
|||
self.assertEqual(c.charm_instance, instance)
|
||||
self.assertTrue(c._charm_instance_weakref is not None)
|
||||
|
||||
def test_application_name(self):
|
||||
with mock.patch.object(adapters.hookenv, 'config', new=lambda: {}):
|
||||
with mock.patch.object(adapters.hookenv, 'service_name',
|
||||
return_value='myapp'):
|
||||
c = adapters.ConfigurationAdapter()
|
||||
self.assertEqual(c.application_name, 'myapp')
|
||||
|
||||
|
||||
class TestAPIConfigurationAdapter(unittest.TestCase):
|
||||
api_ports = {
|
||||
|
|
Loading…
Reference in New Issue