def test_with_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ brain: services: REST: classname: programy.services.rest.GenericRESTService method: GET host: 0.0.0.0 Pannous: classname: programy.services.pannous.PannousService url: http://weannie.pannous.com/api Pandora: classname: programy.services.pandora.PandoraService url: http://www.pandorabots.com/pandora/talk-xml Wikipedia: classname: programy.services.wikipediaservice.WikipediaService """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") services_config = BrainServicesConfiguration() services_config.load_config_section(yaml, brain_config, ".") self.assertTrue(services_config.exists("REST")) self.assertTrue(services_config.exists("Pannous")) self.assertTrue(services_config.exists("Pandora")) self.assertTrue(services_config.exists("Wikipedia")) self.assertFalse(services_config.exists("Other")) self.assertIsNotNone(services_config.service("REST")) self.assertIsNone(services_config.service("REST2"))
def set_service_config(self): service1 = BrainServiceConfiguration("ask") service1._classname = "programy.services.rest.GenericRESTService" service1._host = "localhost" service2 = BrainServiceConfiguration("test") service2._classname = "programy.services.rest.GenericRESTService" service2._host = "localhost" services_config = BrainServicesConfiguration() services_config._services = {"ask": service1, "test": service2} ServiceFactory.preload_services(services_config)
def __init__(self, section_name="brain"): self._overrides = BrainOverridesConfiguration() self._defaults = BrainDefaultsConfiguration() self._binaries = BrainBinariesConfiguration() self._braintree = BrainBraintreeConfiguration() self._services = BrainServicesConfiguration() self._openchatbots = BrainOpenChatBotsConfiguration() self._security = BrainSecuritiesConfiguration() self._dynamics = BrainDynamicsConfiguration() self._tokenizer = BrainTokenizerConfiguration() self._debugfiles = BrainDebugFilesConfiguration() BaseContainerConfigurationData.__init__(self, section_name)
def __init__(self, section_name="brain"): self._overrides = BrainOverridesConfiguration() self._defaults = BrainDefaultsConfiguration() self._nodes = BrainNodesConfiguration() self._binaries = BrainBinariesConfiguration() self._braintree = BrainBraintreeConfiguration() self._files = BrainFilesConfiguration() self._services = BrainServicesConfiguration() self._security = BrainSecuritiesConfiguration() self._oob = BrainOOBSConfiguration() self._dynamics = BrainDynamicsConfiguration() self._tokenizer = BrainTokenizerConfiguration() BaseContainerConfigurationData.__init__(self, section_name)
def test_with_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" brain: services: REST: classname: programy.services.rest.GenericRESTService method: GET host: 0.0.0.0 Pannous: classname: programy.services.pannous.PannousService url: http://weannie.pannous.com/api Pandora: classname: programy.services.pandora.PandoraService url: http://www.pandorabots.com/pandora/talk-xml Wikipedia: classname: programy.services.wikipediaservice.WikipediaService """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") services_config = BrainServicesConfiguration() services_config.load_config_section(yaml, brain_config, ".") self.assertTrue(services_config.exists("REST")) self.assertTrue(services_config.exists("Pannous")) self.assertTrue(services_config.exists("Pandora")) self.assertTrue(services_config.exists("Wikipedia")) self.assertFalse(services_config.exists("Other"))
def to_yaml(self, data, defaults=True): self.config_to_yaml(data, BrainOverridesConfiguration(), defaults) self.config_to_yaml(data, BrainDefaultsConfiguration(), defaults) self.config_to_yaml(data, BrainBinariesConfiguration(), defaults) self.config_to_yaml(data, BrainBraintreeConfiguration(), defaults) self.config_to_yaml(data, BrainServicesConfiguration(), defaults) self.config_to_yaml(data, BrainOpenChatBotsConfiguration(), defaults) self.config_to_yaml(data, BrainSecuritiesConfiguration(), defaults) self.config_to_yaml(data, BrainDynamicsConfiguration(), defaults) self.config_to_yaml(data, BrainTokenizerConfiguration(), defaults) self.config_to_yaml(data, BrainDebugFilesConfiguration(), defaults)
def test_with_no_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" brain: """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") services_config = BrainServicesConfiguration() services_config.load_config_section(yaml, brain_config, ".") self.assertFalse(services_config.exists("REST")) self.assertFalse(services_config.exists("Pannous")) self.assertFalse(services_config.exists("Pandora")) self.assertFalse(services_config.exists("Wikipedia")) self.assertFalse(services_config.exists("Other"))
class BrainConfiguration(BaseContainerConfigurationData): def __init__(self, section_name="brain"): self._overrides = BrainOverridesConfiguration() self._defaults = BrainDefaultsConfiguration() self._binaries = BrainBinariesConfiguration() self._braintree = BrainBraintreeConfiguration() self._services = BrainServicesConfiguration() self._openchatbots = BrainOpenChatBotsConfiguration() self._security = BrainSecuritiesConfiguration() self._dynamics = BrainDynamicsConfiguration() self._tokenizer = BrainTokenizerConfiguration() self._debugfiles = BrainDebugFilesConfiguration() BaseContainerConfigurationData.__init__(self, section_name) @property def overrides(self): return self._overrides @property def defaults(self): return self._defaults @property def binaries(self): return self._binaries @property def braintree(self): return self._braintree @property def services(self): return self._services @property def openchatbots(self): return self._openchatbots @property def security(self): return self._security @property def dynamics(self): return self._dynamics @property def tokenizer(self): return self._tokenizer @property def debugfiles(self): return self._debugfiles def check_for_license_keys(self, license_keys): self._overrides.check_for_license_keys(license_keys) self._defaults.check_for_license_keys(license_keys) self._binaries.check_for_license_keys(license_keys) self._braintree.check_for_license_keys(license_keys) self._services.check_for_license_keys(license_keys) self._openchatbots.check_for_license_keys(license_keys) self._security.check_for_license_keys(license_keys) self._dynamics.check_for_license_keys(license_keys) self._tokenizer.check_for_license_keys(license_keys) self._debugfiles.check_for_license_keys(license_keys) BaseContainerConfigurationData.check_for_license_keys( self, license_keys) def load_configuration(self, configuration_file, brain_config, bot_root, subs: Substitutions = None): if brain_config is not None: self._overrides.load_config_section(configuration_file, brain_config, bot_root, subs=subs) self._defaults.load_config_section(configuration_file, brain_config, bot_root, subs=subs) self._binaries.load_config_section(configuration_file, brain_config, bot_root, subs=subs) self._braintree.load_config_section(configuration_file, brain_config, bot_root, subs=subs) self._services.load_config_section(configuration_file, brain_config, bot_root, subs=subs) self._openchatbots.load_config_section(configuration_file, brain_config, bot_root, subs=subs) self._security.load_config_section(configuration_file, brain_config, bot_root, subs=subs) self._dynamics.load_config_section(configuration_file, brain_config, bot_root, subs=subs) self._tokenizer.load_config_section(configuration_file, brain_config, bot_root, subs=subs) self._debugfiles.load_config_section(configuration_file, brain_config, bot_root, subs=subs) def to_yaml(self, data, defaults=True): self.config_to_yaml(data, BrainOverridesConfiguration(), defaults) self.config_to_yaml(data, BrainDefaultsConfiguration(), defaults) self.config_to_yaml(data, BrainBinariesConfiguration(), defaults) self.config_to_yaml(data, BrainBraintreeConfiguration(), defaults) self.config_to_yaml(data, BrainServicesConfiguration(), defaults) self.config_to_yaml(data, BrainOpenChatBotsConfiguration(), defaults) self.config_to_yaml(data, BrainSecuritiesConfiguration(), defaults) self.config_to_yaml(data, BrainDynamicsConfiguration(), defaults) self.config_to_yaml(data, BrainTokenizerConfiguration(), defaults) self.config_to_yaml(data, BrainDebugFilesConfiguration(), defaults)
class BrainConfiguration(BaseContainerConfigurationData): def __init__(self, section_name="brain"): self._overrides = BrainOverridesConfiguration() self._defaults = BrainDefaultsConfiguration() self._nodes = BrainNodesConfiguration() self._binaries = BrainBinariesConfiguration() self._braintree = BrainBraintreeConfiguration() self._files = BrainFilesConfiguration() self._services = BrainServicesConfiguration() self._security = BrainSecuritiesConfiguration() self._oob = BrainOOBSConfiguration() self._dynamics = BrainDynamicsConfiguration() self._tokenizer = BrainTokenizerConfiguration() BaseContainerConfigurationData.__init__(self, section_name) @property def overrides(self): return self._overrides @property def defaults(self): return self._defaults @property def nodes(self): return self._nodes @property def binaries(self): return self._binaries @property def braintree(self): return self._braintree @property def files(self): return self._files @property def services(self): return self._services @property def security(self): return self._security @property def oob(self): return self._oob @property def dynamics(self): return self._dynamics @property def tokenizer(self): return self._tokenizer def load_configuration(self, configuration_file, bot_root): brain_config = configuration_file.get_section(self.section_name) if brain_config is not None: self._overrides.load_config_section(configuration_file, brain_config, bot_root) self._defaults.load_config_section(configuration_file, brain_config, bot_root) self._nodes.load_config_section(configuration_file, brain_config, bot_root) self._binaries.load_config_section(configuration_file, brain_config, bot_root) self._braintree.load_config_section(configuration_file, brain_config, bot_root) self._files.load_config_section(configuration_file, brain_config, bot_root) self._services.load_config_section(configuration_file, brain_config, bot_root) self._security.load_config_section(configuration_file, brain_config, bot_root) self._oob.load_config_section(configuration_file, brain_config, bot_root) self._dynamics.load_config_section(configuration_file, brain_config, bot_root) self._tokenizer.load_config_section(configuration_file, brain_config, bot_root) def to_yaml(self, data, defaults=True): self.config_to_yaml(data, BrainOverridesConfiguration(), defaults) self.config_to_yaml(data, BrainDefaultsConfiguration(), defaults) self.config_to_yaml(data, BrainNodesConfiguration(), defaults) self.config_to_yaml(data, BrainBinariesConfiguration(), defaults) self.config_to_yaml(data, BrainBraintreeConfiguration(), defaults) self.config_to_yaml(data, BrainFilesConfiguration(), defaults) self.config_to_yaml(data, BrainServicesConfiguration(), defaults) self.config_to_yaml(data, BrainSecuritiesConfiguration(), defaults) self.config_to_yaml(data, BrainOOBSConfiguration(), defaults) self.config_to_yaml(data, BrainDynamicsConfiguration(), defaults) self.config_to_yaml(data, BrainTokenizerConfiguration(), defaults)
class BrainConfiguration(BaseContainerConfigurationData): def __init__(self, section_name="brain"): self._bot_name = None self._manager_name = None self._overrides = BrainOverridesConfiguration() self._defaults = BrainDefaultsConfiguration() self._binaries = BrainBinariesConfiguration() self._braintree = BrainBraintreeConfiguration() self._services = BrainServicesConfiguration() self._security = BrainSecuritiesConfiguration() self._oob = BrainOOBSConfiguration() self._dynamics = BrainDynamicsConfiguration() self._tokenizer = BrainTokenizerConfiguration() self._debugfiles = BrainDebugFilesConfiguration() self._nlu = BrainNluConfiguration() BaseContainerConfigurationData.__init__(self, section_name) @property def bot_name(self): return self._bot_name @property def manager_name(self): return self._manager_name @property def overrides(self): return self._overrides @property def defaults(self): return self._defaults @property def binaries(self): return self._binaries @property def braintree(self): return self._braintree @property def services(self): return self._services @property def security(self): return self._security @property def oob(self): return self._oob @property def dynamics(self): return self._dynamics @property def tokenizer(self): return self._tokenizer @property def debugfiles(self): return self._debugfiles @property def nlu(self): return self._nlu def check_for_license_keys(self, license_keys): self._overrides.check_for_license_keys(license_keys) self._defaults.check_for_license_keys(license_keys) self._binaries.check_for_license_keys(license_keys) self._braintree.check_for_license_keys(license_keys) self._services.check_for_license_keys(license_keys) self._security.check_for_license_keys(license_keys) self._oob.check_for_license_keys(license_keys) self._dynamics.check_for_license_keys(license_keys) self._tokenizer.check_for_license_keys(license_keys) self._debugfiles.check_for_license_keys(license_keys) self._nlu.check_for_license_keys(license_keys) BaseContainerConfigurationData.check_for_license_keys( self, license_keys) def load_configuration(self, configuration_file, bot_root, subs: Substitutions = None): brain_config = configuration_file.get_section(self.section_name) if brain_config is not None: self._bot_name = configuration_file.get_option( brain_config, "bot_name") self._manager_name = configuration_file.get_option( brain_config, "manager_name") self._overrides.load_config_section(configuration_file, brain_config, bot_root, subs=subs) self._defaults.load_config_section(configuration_file, brain_config, bot_root, subs=subs) self._binaries.load_config_section(configuration_file, brain_config, bot_root, subs=subs) self._braintree.load_config_section(configuration_file, brain_config, bot_root, subs=subs) self._services.load_config_section(configuration_file, brain_config, bot_root, subs=subs) self._security.load_config_section(configuration_file, brain_config, bot_root, subs=subs) self._oob.load_config_section(configuration_file, brain_config, bot_root, subs=subs) self._dynamics.load_config_section(configuration_file, brain_config, bot_root, subs=subs) self._tokenizer.load_config_section(configuration_file, brain_config, bot_root, subs=subs) self._debugfiles.load_config_section(configuration_file, brain_config, bot_root, subs=subs) self._nlu.load_config_section(configuration_file, brain_config, bot_root, subs=subs) def to_yaml(self, data, defaults=True): self.config_to_yaml(data, BrainOverridesConfiguration(), defaults) self.config_to_yaml(data, BrainDefaultsConfiguration(), defaults) self.config_to_yaml(data, BrainBinariesConfiguration(), defaults) self.config_to_yaml(data, BrainBraintreeConfiguration(), defaults) self.config_to_yaml(data, BrainServicesConfiguration(), defaults) self.config_to_yaml(data, BrainSecuritiesConfiguration(), defaults) self.config_to_yaml(data, BrainOOBSConfiguration(), defaults) self.config_to_yaml(data, BrainDynamicsConfiguration(), defaults) self.config_to_yaml(data, BrainTokenizerConfiguration(), defaults) self.config_to_yaml(data, BrainDebugFilesConfiguration(), defaults) self.config_to_yaml(data, BrainNluConfiguration(), defaults)
def test_defaults(self): services_config = BrainServicesConfiguration() data = {} services_config.to_yaml(data, True) BrainServicesConfigurationTests.assert_defaults(self, data)