本文整理匯總了Python中redash.utils.configuration.ConfigurationContainer.to_dict方法的典型用法代碼示例。如果您正苦於以下問題:Python ConfigurationContainer.to_dict方法的具體用法?Python ConfigurationContainer.to_dict怎麽用?Python ConfigurationContainer.to_dict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類redash.utils.configuration.ConfigurationContainer
的用法示例。
在下文中一共展示了ConfigurationContainer.to_dict方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestConfigurationUpdate
# 需要導入模塊: from redash.utils.configuration import ConfigurationContainer [as 別名]
# 或者: from redash.utils.configuration.ConfigurationContainer import to_dict [as 別名]
class TestConfigurationUpdate(TestCase):
def setUp(self):
self.config = {'a': 1, 'b': 'test'}
self.container = ConfigurationContainer(self.config, configuration_schema)
def test_rejects_invalid_new_config(self):
self.assertRaises(ValidationError, lambda: self.container.update({'c': 3}))
def test_fails_if_no_schema_set(self):
self.container.set_schema(None)
self.assertRaises(RuntimeError, lambda: self.container.update({'c': 3}))
def test_ignores_secret_placehodler(self):
self.container.update(self.container.to_dict(mask_secrets=True))
self.assertEqual(self.container['b'], self.config['b'])
def test_updates_secret(self):
new_config = {'a': 2, 'b': 'new'}
self.container.update(new_config)
self.assertDictEqual(self.container._config, new_config)
def test_doesnt_leave_leftovers(self):
container = ConfigurationContainer({'a': 1, 'b': 'test', 'e': 3}, configuration_schema)
new_config = container.to_dict(mask_secrets=True)
new_config.pop('e')
container.update(new_config)
self.assertEqual(container['a'], 1)
self.assertEqual('test', container['b'])
self.assertNotIn('e', container)
示例2: test_doesnt_leave_leftovers
# 需要導入模塊: from redash.utils.configuration import ConfigurationContainer [as 別名]
# 或者: from redash.utils.configuration.ConfigurationContainer import to_dict [as 別名]
def test_doesnt_leave_leftovers(self):
container = ConfigurationContainer({'a': 1, 'b': 'test', 'e': 3}, configuration_schema)
new_config = container.to_dict(mask_secrets=True)
new_config.pop('e')
container.update(new_config)
self.assertEqual(container['a'], 1)
self.assertEqual('test', container['b'])
self.assertNotIn('e', container)
示例3: TestConfigurationToJson
# 需要導入模塊: from redash.utils.configuration import ConfigurationContainer [as 別名]
# 或者: from redash.utils.configuration.ConfigurationContainer import to_dict [as 別名]
class TestConfigurationToJson(TestCase):
def setUp(self):
self.config = {'a': 1, 'b': 'test'}
self.container = ConfigurationContainer(self.config, configuration_schema)
def test_returns_plain_dict(self):
self.assertDictEqual(self.config, self.container.to_dict())
def test_raises_exception_when_no_schema_set(self):
self.container.set_schema(None)
self.assertRaises(RuntimeError, lambda: self.container.to_dict(mask_secrets=True))
def test_returns_dict_with_masked_secrets(self):
d = self.container.to_dict(mask_secrets=True)
self.assertEqual(d['a'], self.config['a'])
self.assertNotEqual(d['b'], self.config['b'])
self.assertEqual(self.config['b'], self.container['b'])