def test_rest_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 """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") self.assertIsNotNone(brain_config) services_config = yaml.get_section("services", brain_config) self.assertIsNotNone(services_config) service_config = BrainServiceConfiguration("REST") service_config.load_config_section(yaml, services_config, ".") self.assertEqual("programy.services.rest.GenericRESTService", service_config.classname) self.assertEqual("GET", service_config.method) self.assertEqual("0.0.0.0", service_config.host) self.assertIsNone(service_config.port) self.assertIsNone(service_config.url)
def test_pandora_with_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ brain: services: Pandora: classname: programy.services.pandora.PandoraService url: http://www.pandorabots.com/pandora/talk-xml """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") self.assertIsNotNone(brain_config) services_config = yaml.get_section("services", brain_config) self.assertIsNotNone(services_config) service_config = BrainServiceConfiguration("Pandora") service_config.load_config_section(yaml, services_config, ".") self.assertEqual("programy.services.pandora.PandoraService", service_config.classname) self.assertEqual("http://www.pandorabots.com/pandora/talk-xml", service_config.url) self.assertIsNone(service_config.method) self.assertIsNone(service_config.host) self.assertIsNone(service_config.port)
def test_wikipedia_with_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ brain: services: Wikipedia: classname: programy.services.wikipediaservice.WikipediaService """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") self.assertIsNotNone(brain_config) services_config = yaml.get_section("services", brain_config) self.assertIsNotNone(services_config) service_config = BrainServiceConfiguration("Wikipedia") service_config.load_config_section(yaml, services_config, ".") self.assertEqual("programy.services.wikipediaservice.WikipediaService", service_config.classname) self.assertIsNone(service_config.method) self.assertIsNone(service_config.host) self.assertIsNone(service_config.port) self.assertIsNone(service_config.url)
def test_to_yaml_without_defaults(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 """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") services_config = yaml.get_section("services", brain_config) service_config = BrainServiceConfiguration("REST") service_config.load_config_section(yaml, services_config, ".") data = {} service_config.to_yaml(data, defaults=False) self.assertEquals({'classname': 'programy.services.rest.GenericRESTService', 'host': '0.0.0.0', 'method': 'GET', 'port': None, 'url': None}, data)
def load_config_section(self, configuration_file, configuration, bot_root, subs: Substitutions = None): services = configuration_file.get_section(self.section_name, configuration) if services is not None: service_keys = configuration_file.get_keys(services) for name in service_keys: service = BrainServiceConfiguration(name) service.load_config_section(configuration_file, services, bot_root, subs=subs) self._services[name] = service else: YLogger.warning(self, "Config section [services] missing from Brain, no services loaded")
def load_config_section(self, configuration_file, configuration, bot_root): services = configuration_file.get_section("services", configuration) if services is not None: service_keys = configuration_file.get_keys(services) for name in service_keys: service = BrainServiceConfiguration(name) service.load_config_section(configuration_file, services, bot_root) self._services[name] = service else: YLogger.warning(self, "Config section [services] missing from Brain, no services loaded")
def test_rest_without_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" brain: services: REST: """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") self.assertIsNotNone(brain_config) services_config = yaml.get_section("services", brain_config) self.assertIsNotNone(services_config) service_config = BrainServiceConfiguration("REST") service_config.load_config_section(yaml, services_config, ".") self.assertIsNone(service_config.classname) self.assertIsNone(service_config.method) self.assertIsNone(service_config.host) self.assertIsNone(service_config.port) self.assertIsNone(service_config.url)