def test_to_yaml_without_defaults(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" console: bot: bot default_userid: console prompt: $ license_keys: ./config/license.keys bot_selector: programy.clients.client.DefaultBotSelector renderer: programy.clients.render.text.TextRenderer """, ConsoleConfiguration(), ".") config = ConsoleConfiguration() config.load_configuration(yaml, ".") data = {} config.to_yaml(data, False) self.assertEquals('console', data['default_userid']) self.assertEquals('$', data['prompt']) self.assertEquals(data['bot'], 'bot') self.assertEquals(data['license_keys'], "./config/license.keys") self.assertEquals(data['bot_selector'], "programy.clients.client.DefaultBotSelector") self.assertEquals(data['renderer'], "programy.clients.render.text.TextRenderer")
def test_init(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" twitter: polling_interval: 59 rate_limit_sleep: 900 use_status: true use_direct_message: true auto_follow: true storage: file storage_location: ./storage/twitter.data welcome_message: Thanks for following me """, ConsoleConfiguration(), ".") twitter_config = TwitterConfiguration() twitter_config.load_configuration(yaml, ".") self.assertEqual(59, twitter_config.polling_interval) self.assertEqual(900, twitter_config.rate_limit_sleep) self.assertTrue(twitter_config.use_status) self.assertTrue(twitter_config.use_direct_message) self.assertTrue(twitter_config.auto_follow) self.assertEquals("file", twitter_config.storage) self.assertEquals("./storage/twitter.data", twitter_config.storage_location) self.assertEquals("Thanks for following me", twitter_config.welcome_message)
def test_load_from_configuration_no_data(self): collection = DynamicsCollection() self.assertIsNotNone(collection) yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" brain: dynamic: """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") dynamics_config = BrainDynamicsConfiguration() dynamics_config.load_config_section(yaml, brain_config, ".") collection.load_from_configuration(dynamics_config) self.assertIsNotNone(collection.dynamic_sets) self.assertTrue(collection.is_dynamic_set("NUMBER")) self.assertIsNotNone(collection.dynamic_maps) self.assertTrue(collection.is_dynamic_map("PLURAL")) self.assertTrue(collection.is_dynamic_map("SINGULAR")) self.assertTrue(collection.is_dynamic_map("PREDECESSOR")) self.assertTrue(collection.is_dynamic_map("SUCCESSOR")) self.assertIsNotNone(collection.dynamic_vars)
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 test_load_from_text_single_files(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) configuration = yaml.load_from_text(""" brain: files: aiml: files: $BOT_ROOT/test-aiml extension: .test-aiml directories: true errors: /tmp/y-bot_errors.txt duplicates: /tmp/y-bot_duplicates.txt conversation: /tmp/y-bot_conversation.txt sets: files: $BOT_ROOT/test-sets extension: .test-txt directories: true maps: files: $BOT_ROOT/test-maps extension: .test-txt directories: true """, ConsoleConfiguration(), ".") self.assertIsNotNone(configuration) self.assertTrue(configuration.client_configuration.configurations[0].configurations[0].files.aiml_files.has_multiple_files()) self.assertFalse(configuration.client_configuration.configurations[0].configurations[0].files.aiml_files.has_single_file()) self.assertEqual(configuration.client_configuration.configurations[0].configurations[0].files.aiml_files.files, ["./test-aiml"]) self.assertEqual(configuration.client_configuration.configurations[0].configurations[0].files.set_files.files, ["./test-sets"]) self.assertEqual(configuration.client_configuration.configurations[0].configurations[0].files.map_files.files, ["./test-maps"])
def test_without_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" bot: """, ConsoleConfiguration(), ".") bot_config = BotConfiguration() bot_config.load_configuration(yaml, ".") self.assertIsNone(bot_config.brain_selector) self.assertEqual("Hello", bot_config.initial_question) self.assertEqual("", bot_config.initial_question_srai) self.assertEqual("", bot_config.default_response) self.assertEqual("", bot_config.default_response_srai) self.assertEqual("Bye!", bot_config.exit_response) self.assertEqual("", bot_config.exit_response_srai) self.assertEqual("", bot_config.empty_string) self.assertEqual(bot_config.max_question_recursion, 100) self.assertEqual(bot_config.max_question_timeout, -1) self.assertEqual(bot_config.max_search_depth, 100) self.assertEqual(bot_config.max_search_timeout, -1) self.assertTrue(bot_config.override_properties) self.assertIsNotNone(bot_config.spelling) self.assertIsNotNone(bot_config.conversations)
def test_with_file_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" brain: files: aiml: file: $BOT_ROOT/aiml/test.aiml errors: /tmp/y-bot-errors.txt duplicates: /tmp/y-bot-duplicates.txt conversation: /tmp/y-bot-conversation.txt """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") self.assertIsNotNone(brain_config) files_config = yaml.get_section("files", brain_config) self.assertIsNotNone(files_config) aiml_config = BrainAIMLFileConfiguration() aiml_config.load_config_section(yaml, files_config, ".") self.assertEqual("./aiml/test.aiml", aiml_config.file) self.assertEqual("aiml", aiml_config.extension) self.assertFalse(aiml_config.directories) self.assertEqual("/tmp/y-bot-errors.txt", aiml_config.errors.filename) self.assertEqual("/tmp/y-bot-duplicates.txt", aiml_config.duplicates.filename) self.assertEqual("/tmp/y-bot-conversation.txt", aiml_config.conversation.filename)
def test_with_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" bot: conversations: max_histories: 666 initial_topic: topic1 restore_last_topic: true type: file config_name: file_storage file_storage: dir: $BOT_ROOT/conversations """, ConsoleConfiguration(), ".") bot_config = yaml.get_section("bot") convo_config = BotConversationsConfiguration() convo_config.load_config_section(yaml, bot_config, ".") self.assertEquals(convo_config.section_name, "conversations") self.assertEquals(666, convo_config.max_histories) self.assertEquals("topic1", convo_config.initial_topic) self.assertTrue(convo_config.restore_last_topic) self.assertEquals(convo_config.type, "file") self.assertIsNotNone(convo_config.storage)
def test_with_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" console: bot: bot prompt: ">>>" license_keys: $BOT_ROOT/config/license.keys bot_selector: programy.clients.client.DefaultBotSelector renderer: programy.clients.render.text.TextRenderer scheduler: name: Scheduler1 debug_level: 0 add_listeners: True remove_all_jobs: True """, ConsoleConfiguration(), ".") bot_config = yaml.get_section("console") client_config = ClientConfigurationData("test") client_config.load_configuration(yaml, bot_config, ".") self.assertEquals("./config/license.keys", client_config.license_keys) self.assertEquals("programy.clients.client.DefaultBotSelector", client_config.bot_selector) self.assertIsNotNone(client_config.scheduler) self.assertEquals("Scheduler1", client_config.scheduler.name) self.assertEquals(0, client_config.scheduler.debug_level) self.assertTrue(client_config.scheduler.add_listeners) self.assertTrue(client_config.scheduler.remove_all_jobs) self.assertEquals("programy.clients.render.text.TextRenderer", client_config.renderer)
def test_with_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" console: scheduler: name: Scheduler1 debug_level: 0 add_listeners: True remove_all_jobs: True jobstore: name: mongo mongo: collection: example_jobs redis: jobs_key: example.jobs run_times_key: example.run_times sqlalchemy: url: sqlite:///jobs.sqlite threadpool: max_workers: 20 processpool: max_workers: 5 job_defaults: coalesce: False max_instances: 3 """, ConsoleConfiguration(), ".") bot_config = yaml.get_section("console") scheduler_config = SchedulerConfiguration() scheduler_config.load_config_section(yaml, bot_config, ".") self.assertEquals("Scheduler1", scheduler_config.name) self.assertEquals(0, scheduler_config.debug_level) self.assertTrue(scheduler_config.add_listeners) self.assertTrue(scheduler_config.remove_all_jobs) self.assertIsNotNone(scheduler_config.jobstore) self.assertIsNotNone(scheduler_config.jobstore.jobstore) self.assertEquals("example_jobs", scheduler_config.jobstore.jobstore.collection) self.assertIsNotNone(scheduler_config.threadpool) self.assertEquals(20, scheduler_config.threadpool.max_workers) self.assertIsNotNone(scheduler_config.processpool) self.assertEquals(5, scheduler_config.processpool.max_workers) self.assertIsNotNone(scheduler_config.job_defaults) self.assertEquals(False, scheduler_config.job_defaults.coalesce) self.assertEquals(3, scheduler_config.job_defaults.max_instances)
def test_load_from_text_multis_one_value(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) configuration = yaml.load_from_text(""" bot: brain: bot1 """, ConsoleConfiguration(), ".") self.assertIsNotNone(configuration) self.assertEquals(1, len(configuration.client_configuration.configurations[0].configurations))
def test_with_no_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" brain: """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") tokenizer_config = BrainTokenizerConfiguration() tokenizer_config.load_config_section(yaml, brain_config, ".")
def test_init_no_values(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" console: """, ConsoleConfiguration(), ".") config = ConsoleConfiguration() config.load_configuration(yaml, ".") self.assertIsNotNone(config.configurations) self.assertEquals(1, len(config.configurations))
def test_without_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" brain: dynamic: """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") dynamic_config = BrainDynamicsConfiguration() dynamic_config.load_config_section(yaml, brain_config, ".")
def test_init(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" slack: polling_interval: 1 """, ConsoleConfiguration(), ".") slack_config = SlackConfiguration() slack_config.load_configuration(yaml, ".") self.assertEqual(1, slack_config.polling_interval)
def test_without_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" bot: """, ConsoleConfiguration(), ".") bot_config = yaml.get_section("bot") convo_config = BotConversationsFileStorageConfiguration(config_name="file_storage") convo_config.load_config_section(yaml, bot_config, ".") self.assertIsNone(convo_config.dir)
def test_init_no_values(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" twilio: """, ConsoleConfiguration(), ".") twilio_config = TwilioConfiguration() twilio_config.load_configuration(yaml, ".") self.assertEqual("0.0.0.0", twilio_config.host) self.assertEqual(80, twilio_config.port) self.assertEqual(False, twilio_config.debug)
def test_init_no_values(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" facebook: """, ConsoleConfiguration(), ".") facebook_config = FacebookConfiguration() facebook_config.load_configuration(yaml, ".") self.assertEqual("0.0.0.0", facebook_config.host) self.assertEqual(80, facebook_config.port) self.assertEqual(False, facebook_config.debug)
def test_with_no_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" brain: """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") nodes_config = BrainNodesConfiguration() nodes_config.load_config_section(yaml, brain_config, ".") self.assertIsNone(nodes_config.pattern_nodes) self.assertIsNone(nodes_config.template_nodes)
def test_with_no_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" brain: """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") braintree_config = BrainBraintreeConfiguration() braintree_config.load_config_section(yaml, brain_config, ".") self.assertIsNone(braintree_config.file) self.assertIsNone(braintree_config.content)
def test_init_no_values(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" rest: """, ConsoleConfiguration(), ".") rest_config = RestConfiguration("rest") rest_config.load_configuration(yaml, ".") self.assertEqual("0.0.0.0", rest_config.host) self.assertEqual(80, rest_config.port) self.assertEqual(False, rest_config.debug) self.assertEqual(False, rest_config.use_api_keys)
def test_with_no_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" bot: """, ConsoleConfiguration(), ".") bot_config = yaml.get_section("bot") redis_config = BotConversationsRedisStorageConfiguration("redis") redis_config.load_config_section(yaml, bot_config, ".") self.assertEquals("localhost", redis_config.host) self.assertEquals(6379, redis_config.port)
def test_init(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" telegram: unknown_command: Sorry, that is not a command I have been taught yet! unknown_command_srai: YTELEGRAM_UNKNOWN_COMMAND """, ConsoleConfiguration(), ".") telegram_config = TelegramConfiguration() telegram_config.load_configuration(yaml, ".") self.assertEquals(telegram_config.unknown_command, "Sorry, that is not a command I have been taught yet!") self.assertEquals(telegram_config.unknown_command_srai, "YTELEGRAM_UNKNOWN_COMMAND")
def test_with_no_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" brain: """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") overrides_config = BrainOverridesConfiguration() overrides_config.load_config_section(yaml, brain_config, ".") self.assertFalse(overrides_config.allow_system_aiml) self.assertFalse(overrides_config.allow_learn_aiml) self.assertFalse(overrides_config.allow_learnf_aiml)
def test_with_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" brain: tokenizer: classname: programy.utils.language.chinese.ChineseLanguage """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") tokenizer_config = BrainTokenizerConfiguration() tokenizer_config.load_config_section(yaml, brain_config, ".") self.assertEqual("programy.utils.language.chinese.ChineseLanguage", tokenizer_config.classname)
def test_init(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" facebook: host: 127.0.0.1 port: 5000 debug: false """, ConsoleConfiguration(), ".") facebook_config = FacebookConfiguration() facebook_config.load_configuration(yaml, ".") self.assertEqual("127.0.0.1", facebook_config.host) self.assertEqual(5000, facebook_config.port) self.assertEqual(False, facebook_config.debug)
def test_with_no_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" brain: """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") binaries_config = BrainBinariesConfiguration() binaries_config.load_config_section(yaml, brain_config, ".") self.assertFalse(binaries_config.save_binary) self.assertFalse(binaries_config.load_binary) self.assertIsNone(binaries_config.binary_filename) self.assertFalse(binaries_config.load_aiml_on_binary_fail)
def test_with_no_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" brain: """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") oobs_config = BrainOOBSConfiguration() oobs_config.load_config_section(yaml, brain_config, ".") self.assertFalse(oobs_config.exists("default")) self.assertFalse(oobs_config.exists("dial")) self.assertFalse(oobs_config.exists("email")) self.assertFalse(oobs_config.exists("Other"))
def test_init(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" twilio: host: 127.0.0.1 port: 5000 debug: false """, ConsoleConfiguration(), ".") twilio_config = TwilioConfiguration() twilio_config.load_configuration(yaml, ".") self.assertEqual("127.0.0.1", twilio_config.host) self.assertEqual(5000, twilio_config.port) self.assertEqual(False, twilio_config.debug)
def test_init_no_values(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" viber: """, ConsoleConfiguration(), ".") viber_config = ViberConfiguration() viber_config.load_configuration(yaml, ".") self.assertEqual("0.0.0.0", viber_config.host) self.assertEqual(80, viber_config.port) self.assertEqual(False, viber_config.debug) self.assertIsNone(viber_config.name) self.assertIsNone(viber_config.avatar) self.assertIsNone(viber_config.webhook)
def test_without_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ bot: scheduler: """, ConsoleConfiguration(), ".") bot_config = yaml.get_section("console") scheduler_config = SchedulerConfiguration() scheduler_config.load_config_section(yaml, bot_config, ".") self.assertIsNone(scheduler_config.name) self.assertEqual(0, scheduler_config.debug_level) self.assertFalse(scheduler_config.add_listeners) self.assertFalse(scheduler_config.remove_all_jobs) self.assertIsNone(scheduler_config.jobstore) self.assertIsNone(scheduler_config.threadpool) self.assertIsNone(scheduler_config.processpool) self.assertIsNone(scheduler_config.job_defaults)
def test_init(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ xmpp: server: talk.google.com port: 5222 xep_0030: true xep_0004: true xep_0060: true xep_0199: true """, ConsoleConfiguration(), ".") xmpp_config = XmppConfiguration() xmpp_config.load_configuration(yaml, ".") self.assertEquals('talk.google.com', xmpp_config.server) self.assertEquals(5222, xmpp_config.port) self.assertTrue(xmpp_config.xep_0030) self.assertTrue(xmpp_config.xep_0004) self.assertTrue(xmpp_config.xep_0060) self.assertTrue(xmpp_config.xep_0199)
def test_init(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ rest: host: 127.0.0.1 port: 5000 debug: false workers: 4 use_api_keys: false api_key_file: apikeys.txt """, ConsoleConfiguration(), ".") rest_config = RestConfiguration() rest_config.load_configuration(yaml, ".") self.assertEqual("127.0.0.1", rest_config.host) self.assertEqual(5000, rest_config.port) self.assertEqual(False, rest_config.debug) self.assertEqual(4, rest_config.workers) self.assertEqual(False, rest_config.use_api_keys) self.assertEqual("apikeys.txt", rest_config.api_key_file)
def test_init_no_values(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" google: """, ConsoleConfiguration(), ".") google_config = GoogleConfiguration() google_config.load_configuration(yaml, ".") self.assertEqual(google_config.host, "0.0.0.0") self.assertEqual(google_config.port, 80) self.assertEqual(google_config.debug, False) self.assertEqual(google_config.launch_text, "Hello and welcome") self.assertEqual(google_config.launch_srai, None) self.assertEqual(google_config.quit_text, "Good bye matey") self.assertEqual(google_config.quit_srai, None) self.assertEqual(google_config.error_text, "Oopsie there has been an error") self.assertEqual(google_config.error_srai, None)
def test_with_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" brain: oob: default: classname: programy.utils.oob.default.DefaultOutOfBandProcessor dial: classname: programy.utils.oob.dial.DialOutOfBandProcessor email: classname: programy.utils.oob.email.EmailOutOfBandProcessor """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") oobs_config = BrainOOBSConfiguration() oobs_config.load_config_section(yaml, brain_config, ".") self.assertTrue(oobs_config.exists("default")) self.assertTrue(oobs_config.exists("dial")) self.assertTrue(oobs_config.exists("email")) self.assertFalse(oobs_config.exists("Other"))
def test_init(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ webchat: host: 127.0.0.1 port: 5000 debug: false use_api_keys: false cookie_id: ProgramYSession cookie_expires: 90 """, ConsoleConfiguration(), ".") webchat_config = WebChatConfiguration() webchat_config.load_configuration(yaml, ".") self.assertEqual("127.0.0.1", webchat_config.host) self.assertEqual(5000, webchat_config.port) self.assertEqual(False, webchat_config.debug) self.assertEqual(False, webchat_config.use_api_keys) self.assertEqual("ProgramYSession", webchat_config.cookie_id) self.assertEqual(90, webchat_config.cookie_expires)
def test_oob_loading(self): yaml = YamlConfigurationFile() self.load_os_specific_configuration(yaml, "test_brain.yaml", "test_brain.windows.yaml") brain_config = BrainConfiguration() brain_config.load_configuration(yaml, ".") brain = Brain(None, brain_config) self.assertIsInstance(brain.default_oob, DefaultOutOfBandProcessor) self.assertIsInstance(brain.oobs['dial'], DialOutOfBandProcessor) self.assertIsInstance(brain.oobs['email'], EmailOutOfBandProcessor)
def test_init(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ viber: host: 127.0.0.1 port: 5000 debug: false name: test avatar: avatar.jpg webhook: http://localhost """, ConsoleConfiguration(), ".") viber_config = ViberConfiguration() viber_config.load_configuration(yaml, ".") self.assertEqual("127.0.0.1", viber_config.host) self.assertEqual(5000, viber_config.port) self.assertEqual(False, viber_config.debug) self.assertEqual("test", viber_config.name) self.assertEqual("avatar.jpg", viber_config.avatar) self.assertEqual("http://localhost", viber_config.webhook)
def test_create_scheduler_config_redis(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" console: scheduler: name: Scheduler1 debug_level: 0 add_listeners: True remove_all_jobs: True jobstore: name: redis redis: jobs_key: example.jobs run_times_key: example.run_times threadpool: max_workers: 20 processpool: max_workers: 5 job_defaults: coalesce: False max_instances: 3 """, ConsoleConfiguration(), ".") console_config = yaml.get_section("console") scheduler_config = SchedulerConfiguration() scheduler_config.load_config_section(yaml, console_config, ".") config = scheduler_config.create_scheduler_config() self.assertIsNotNone(config)
def test_init(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ voice: tts: pytts stt: azhang pytts: classname: talky.clients.voice.tts.pyttssay.PyTTSSayTextToSpeach rate_adjust: 50 azhang: classname: talky.clients.voice.stt.azhang.AnthonyZangWebServiceSpeechToText ambient_adjust: 2 """, VoiceConfiguration(), ".") config = VoiceConfiguration() self.assertIsNotNone(config) config.load_config_section(yaml, ".") self.assertIsNotNone(config.stt_engine) self.assertIsInstance(config.stt_engine, AnthonyZhangSpeechToTextConfiguration) self.assertIsNotNone(config.stt_engine.classname) self.assertEqual( "talky.clients.voice.stt.azhang.AnthonyZangWebServiceSpeechToText", config.stt_engine.classname) self.assertEqual(2, config.stt_engine.ambient_adjust) self.assertIsNotNone(config.tts_engine) self.assertIsInstance(config.tts_engine, PyTTSTextToSpeechConfiguration) self.assertIsNotNone(config.tts_engine.classname) self.assertEqual( "talky.clients.voice.tts.pyttssay.PyTTSSayTextToSpeach", config.tts_engine.classname) self.assertEqual(50, config.tts_engine.rate_adjust)
def test_create_scheduler_config_sqlalchemy(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ console: scheduler: name: Scheduler1 debug_level: 0 add_listeners: True remove_all_jobs: True jobstore: name: sqlalchemy sqlalchemy: url: sqlite:///jobs.sqlite threadpool: max_workers: 20 processpool: max_workers: 5 job_defaults: coalesce: False max_instances: 3 """, ConsoleConfiguration(), ".") bot_config = yaml.get_section("console") scheduler_config = SchedulerConfiguration() scheduler_config.load_config_section(yaml, bot_config, ".") config = scheduler_config.create_scheduler_config() self.assertIsNotNone(config)
def test_to_yaml_without_defaults(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ socket: host: 127.0.0.1 port: 9999 queue: 5 max_buffer: 1024 debug: true bot: bot default_userid: console prompt: $ license_keys: ./config/license.keys bot_selector: programy.clients.client.DefaultBotSelector renderer: programy.clients.render.text.TextRenderer """, ConsoleConfiguration(), ".") config = SocketConfiguration() config.load_configuration(yaml, ".") data = {} config.to_yaml(data, False) self.assertEqual("127.0.0.1", data['host']) self.assertEqual(9999, data['port']) self.assertEqual(5, data['queue']) self.assertEqual(1024, data['max_buffer']) self.assertEqual(True, data['debug']) self.assertEquals(data['bot'], 'bot') self.assertEquals(data['license_keys'], "./config/license.keys") self.assertEquals(data['bot_selector'], "programy.clients.client.DefaultBotSelector") self.assertEquals(data['renderer'], "programy.clients.render.text.TextRenderer")
def test_with_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ bot: spelling: classname: programy.spelling.norvig.NorvigSpellingChecker alphabet: abcdefghijklmnopqrstuvwxyz check_before: true check_and_retry: true """, ConsoleConfiguration(), ".") bot_config = yaml.get_section("bot") spelling_config = BotSpellingConfiguration() spelling_config.load_config_section(yaml, bot_config, ".") self.assertEqual("programy.spelling.norvig.NorvigSpellingChecker", spelling_config.classname) self.assertEqual("abcdefghijklmnopqrstuvwxyz", spelling_config.alphabet) self.assertTrue(spelling_config.check_before) self.assertTrue(spelling_config.check_and_retry)
def test_with_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ console: bot: bot prompt: ">>>" license_keys: $BOT_ROOT/config/license.keys bot_selector: programy.clients.client.DefaultBotSelector renderer: programy.clients.render.text.TextRenderer scheduler: name: Scheduler1 debug_level: 0 add_listeners: True remove_all_jobs: True """, ConsoleConfiguration(), ".") bot_config = yaml.get_section("console") client_config = ClientConfigurationData("test") client_config.load_configuration(yaml, bot_config, ".") self.assertEquals("./config/license.keys", client_config.license_keys) self.assertEquals("programy.clients.client.DefaultBotSelector", client_config.bot_selector) self.assertIsNotNone(client_config.scheduler) self.assertEquals("Scheduler1", client_config.scheduler.name) self.assertEquals(0, client_config.scheduler.debug_level) self.assertTrue(client_config.scheduler.add_listeners) self.assertTrue(client_config.scheduler.remove_all_jobs) self.assertEquals("programy.clients.render.text.TextRenderer", client_config.renderer)
def test_init(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" kik: bot_name: testbot webhook: https://localhost:5000 host: 127.0.0.1 port: 5000 debug: false unknown_command: Sorry, that is not a command I have been taught yet! unknown_command_srai: YKIK_UNKNOWN_COMMAND """, ConsoleConfiguration(), ".") kik_config = KikConfiguration() kik_config.load_configuration(yaml, ".") self.assertEqual("testbot", kik_config.bot_name) self.assertEqual("https://localhost:5000", kik_config.webhook) self.assertEqual("127.0.0.1", kik_config.host) self.assertEqual(5000, kik_config.port) self.assertEqual(False, kik_config.debug) self.assertEquals(kik_config.unknown_command, "Sorry, that is not a command I have been taught yet!") self.assertEquals(kik_config.unknown_command_srai, "YKIK_UNKNOWN_COMMAND")
def test_with_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ bot: sentiment: classname: programy.nlp.sentiment.textblob_sentiment.TextBlobSentimentAnalyser scores: programy.nlp.sentiment.scores.SentimentScores """, ConsoleConfiguration(), ".") bot_config = yaml.get_section("bot") sentiment_config = BotSentimentAnalyserConfiguration() sentiment_config.load_config_section(yaml, bot_config, ".") license_keys = LicenseKeys() sentiment_config.check_for_license_keys(license_keys) self.assertEqual( "programy.nlp.sentiment.textblob_sentiment.TextBlobSentimentAnalyser", sentiment_config.classname) self.assertEqual("programy.nlp.sentiment.scores.SentimentScores", sentiment_config.scores)
def test_with_additional_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ console: triggers: manager: programy.triggers.rest.RestTriggerManager url: http://localhost:8989/api/v1.0/trigger method: POST token: 123BC4F3D """, ConsoleConfiguration(), ".") console_config = yaml.get_section("console") triggers_config = TriggerConfiguration() triggers_config.load_config_section(yaml, console_config, ".") self.assertEquals("programy.triggers.rest.RestTriggerManager", triggers_config.manager) self.assertEquals(triggers_config.value("url"), "http://localhost:8989/api/v1.0/trigger") self.assertEquals(triggers_config.value("method"), "POST") self.assertEquals(triggers_config.value("token"), "123BC4F3D")
def test_with_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" bot: conversations: max_histories: 666 initial_topic: topic1 restore_last_topic: true multi_client: true """, ConsoleConfiguration(), ".") bot_config = yaml.get_section("bot") convo_config = BotConversationsConfiguration() convo_config.load_config_section(yaml, bot_config, ".") self.assertEqual(convo_config.section_name, "conversations") self.assertEqual(666, convo_config.max_histories) self.assertEqual("topic1", convo_config.initial_topic) self.assertTrue(convo_config.restore_last_topic) self.assertTrue(convo_config.multi_client)
def test_init(self): client_config = ClientConfiguration() yaml = YamlConfigurationFile(client_config) self.assertIsNotNone(yaml) yaml.load_from_text(""" bot: license_keys: $BOT_ROOT/config/license.keys prompt: ">>>" initial_question: Hi, how can I help you today? default_response: Sorry, I don't have an answer for that! exit_response: So long, and thanks for the fish! override_predicates: true """, ".") bot_config = BotConfiguration() bot_config.load_config_section(yaml, ".") self.assertEqual("./config/license.keys", bot_config.license_keys) self.assertEqual(">>>", bot_config.prompt) self.assertEqual("Hi, how can I help you today?", bot_config.initial_question) self.assertEqual("Sorry, I don't have an answer for that!", bot_config.default_response) self.assertEqual("So long, and thanks for the fish!", bot_config.exit_response) self.assertTrue(bot_config.override_predicates)
def test_without_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" bot: """, ConsoleConfiguration(), ".") bot_config = BotConfiguration() bot_config.load_configuration(yaml, ".") self.assertEqual("Hello", bot_config.initial_question) self.assertEqual("", bot_config.initial_question_srai) self.assertEqual("", bot_config.default_response) self.assertEqual("", bot_config.default_response_srai) self.assertEqual("Bye!", bot_config.exit_response) self.assertEqual("", bot_config.exit_response_srai) self.assertEqual("", bot_config.empty_string) self.assertEqual(bot_config.max_question_recursion, 100) self.assertEqual(bot_config.max_question_timeout, -1) self.assertEqual(bot_config.max_search_depth, 100) self.assertEqual(bot_config.max_search_timeout, -1) self.assertTrue(bot_config.override_properties) self.assertIsNotNone(bot_config.spelling) self.assertIsNotNone(bot_config.conversations)
def test_init(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ line: host: 127.0.0.1 port: 5000 debug: false unknown_command: Sorry, that is not a command I have been taught yet! unknown_command_srai: YLINE_UNKNOWN_COMMAND """, ConsoleConfiguration(), ".") line_config = LineConfiguration() line_config.load_configuration(yaml, ".") self.assertEqual("127.0.0.1", line_config.host) self.assertEqual(5000, line_config.port) self.assertEqual(False, line_config.debug) self.assertEquals( line_config.unknown_command, "Sorry, that is not a command I have been taught yet!") self.assertEquals(line_config.unknown_command_srai, "YLINE_UNKNOWN_COMMAND")
def test_with_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ console: email: host: 127.0.0.1 port: 80 username: emailuser password: emailpassword from_addr: emailfromuser """, ConsoleConfiguration(), ".") client_config = yaml.get_section("console") email_config = EmailConfiguration() email_config.load_config_section(yaml, client_config, ".") self.assertEqual("127.0.0.1", email_config.host) self.assertEqual(80, email_config.port) self.assertEqual("emailuser", email_config.username) self.assertEqual("emailpassword", email_config.password) self.assertEqual("emailfromuser", email_config.from_addr)
def test_init(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text( """ twitter: polling_interval: 59 rate_limit_sleep: 900 use_status: true use_direct_message: true auto_follow: true welcome_message: Thanks for following me """, ConsoleConfiguration(), ".") twitter_config = TwitterConfiguration() twitter_config.load_configuration(yaml, ".") self.assertEqual(59, twitter_config.polling_interval) self.assertEqual(900, twitter_config.rate_limit_sleep) self.assertTrue(twitter_config.use_status) self.assertTrue(twitter_config.use_direct_message) self.assertTrue(twitter_config.auto_follow) self.assertEqual("Thanks for following me", twitter_config.welcome_message)
def test_oob_loading(self): yaml = YamlConfigurationFile() self.load_os_specific_configuration(yaml, "test_brain.yaml", "test_brain.windows.yaml") brain_config = BrainConfiguration() brain_config.load_configuration(yaml, ".") client = TestClient() client_context = client.create_client_context("testid") brain = Brain(client_context.bot, brain_config) self.assertIsInstance(brain._oobhandler.default_oob, DefaultOutOfBandProcessor) self.assertIsInstance(brain._oobhandler.oobs['dial'], DialOutOfBandProcessor) self.assertIsInstance(brain._oobhandler.oobs['email'], EmailOutOfBandProcessor)
def test_load_additionals(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) configuration = yaml.load_from_text( """ brain: services: Authentication: classname: programy.services.authenticate.passthrough.PassThroughAuthenticationService denied_srai: ACCESS_DENIED """, ConsoleConfiguration(), ".") self.assertIsNotNone(configuration) self.assertTrue(configuration.client_configuration.configurations[0]. configurations[0].services.exists("Authentication")) auth_service = configuration.client_configuration.configurations[ 0].configurations[0].services.service("Authentication") self.assertIsNotNone(auth_service) self.assertTrue(auth_service.exists("denied_srai")) self.assertEqual("ACCESS_DENIED", auth_service.value("denied_srai"))
def test_with_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" brain: dynamic: variables: gettime: programy.dynamic.variables.datetime.GetTime sets: number: programy.dynamic.sets.numeric.IsNumeric roman: programy.dynamic.sets.roman.IsRomanNumeral maps: romantodec: programy.dynamic.maps.roman.MapRomanToDecimal dectoroman: programy.dynamic.maps.roman.MapDecimalToRoman """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") dynamic_config = BrainDynamicsConfiguration() dynamic_config.load_config_section(yaml, brain_config, ".") self.assertEquals({'GETTIME': 'programy.dynamic.variables.datetime.GetTime'}, dynamic_config.dynamic_vars) self.assertEquals({'NUMBER': 'programy.dynamic.sets.numeric.IsNumeric', 'ROMAN': 'programy.dynamic.sets.roman.IsRomanNumeral'}, dynamic_config.dynamic_sets) self.assertEquals({'ROMANTODEC': 'programy.dynamic.maps.roman.MapRomanToDecimal', 'DECTOROMAN': 'programy.dynamic.maps.roman.MapDecimalToRoman'}, dynamic_config.dynamic_maps)
def test_reload_unknowns(self): yaml = YamlConfigurationFile() self.load_os_specific_configuration(yaml, "test_brain.yaml", "test_brain.windows.yaml") brain_config = BrainConfiguration() brain_config.load_configuration(yaml, ".") client = TestClient() client_context = client.create_client_context("testid") brain = Brain(client_context.bot, brain_config) brain.reload_map("Unknown") brain.reload_set("Unknown") brain.reload_rdf("Unknown")
def test_brain_init_with_config(self): yaml = YamlConfigurationFile() self.load_os_specific_configuration(yaml, "test_brain.yaml", "test_brain.windows.yaml") brain_config = BrainConfiguration() brain_config.load_configuration(yaml, ".") brain = Brain(None, brain_config) self.assertIsNotNone(brain) self.assertIsNotNone(brain.aiml_parser) self.assertIsNotNone(brain.denormals) self.assertIsNotNone(brain.normals) self.assertIsNotNone(brain.genders) self.assertIsNotNone(brain.persons) self.assertIsNotNone(brain.person2s) self.assertIsNotNone(brain.properties) self.assertIsNotNone(brain.rdf) self.assertIsNotNone(brain.sets) self.assertIsNotNone(brain.maps) self.assertIsNotNone(brain.preprocessors) self.assertIsNotNone(brain.postprocessors) self.assertIsNotNone(brain.authentication) self.assertIsNotNone(brain.authorisation) self.assertIsNotNone(brain.default_oob) self.assertIsNotNone(brain.oobs) if os.path.exists(brain_config.binaries.binary_filename): os.remove(brain_config.binaries.binary_filename) self.assertFalse(os.path.exists(brain_config.binaries.binary_filename)) brain.save_binary(brain_config) self.assertTrue(os.path.exists(brain_config.binaries.binary_filename)) brain.load_binary(brain_config) oob_content = ET.fromstring("<oob><something>other</something></oob>") self.assertEqual( "", brain.default_oob.process_out_of_bounds(self._client_context, oob_content)) oob_content = ET.fromstring("<oob><dial>07777777777</dial></oob>") self.assertEqual( "", brain.oobs['dial'].process_out_of_bounds(self._client_context, oob_content))
def test_with_file_no_config_no_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" brain: files: """, ConsoleConfiguration(), ".") brain_config = yaml.get_section("brain") self.assertIsNotNone(brain_config) files_config = yaml.get_section("files", brain_config) self.assertIsNone(files_config)
def test_brain_init_with_secure_config(self): yaml = YamlConfigurationFile() self.load_os_specific_configuration(yaml, "test_secure_brain.yaml", "test_secure_brain.windows.yaml") brain_config = BrainConfiguration() brain_config.load_config_section(yaml, os.path.dirname(__file__)) brain = Brain(brain_config) self.assertIsNotNone(brain) self.assertTrue(brain.authentication.authenticate("console")) self.assertFalse(brain.authentication.authenticate("someone")) self.assertTrue(brain.authorisation.authorise("console", "root")) self.assertFalse(brain.authorisation.authorise("console", "unknown")) with self.assertRaises(AuthorisationException): brain.authorisation.authorise("someone", "root")