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.assertEqual( kik_config.unknown_command, "Sorry, that is not a command I have been taught yet!") self.assertEqual(kik_config.unknown_command_srai, "YKIK_UNKNOWN_COMMAND")
def test_init_no_data(self): yaml = YamlConfigurationFile() self.assertIsNotNone(yaml) yaml.load_from_text(""" client: """, ConsoleConfiguration(), ".") kik_config = KikConfiguration() kik_config.load_configuration(yaml, ".") self.assertEqual("program-y", kik_config.bot_name) self.assertEqual("https://localhost:5000", kik_config.webhook) self.assertEqual("0.0.0.0", kik_config.host) self.assertEqual(80, kik_config.port) self.assertEqual(False, kik_config.debug)
def execute(self, args): config_data = {} if args is None: raise Exception("Args empty") if args.clients is None: raise Exception("No clients defined") if 'all' in args.clients or 'console' in args.clients: self.add_to_config(config_data, ConsoleConfiguration(), args.defaults) if 'all' in args.clients or 'socket' in args.clients: self.add_to_config(config_data, SocketConfiguration(), args.defaults) if 'all' in args.clients or 'slack' in args.clients: self.add_to_config(config_data, SlackConfiguration(), args.defaults) if 'all' in args.clients or 'telegram' in args.clients: self.add_to_config(config_data, TelegramConfiguration(), args.defaults) if 'all' in args.clients or 'twitter' in args.clients: self.add_to_config(config_data, TwitterConfiguration(), args.defaults) if 'all' in args.clients or 'xmpp' in args.clients: self.add_to_config(config_data, XmppConfiguration(), args.defaults) if 'all' in args.clients or 'rest' in args.clients: self.add_to_config(config_data, RestConfiguration(name="rest")) if 'all' in args.clients or 'facebook' in args.clients: self.add_to_config(config_data, FacebookConfiguration(), args.defaults) if 'all' in args.clients or 'kik' in args.clients: self.add_to_config(config_data, KikConfiguration(), args.defaults) if 'all' in args.clients or 'line' in args.clients: self.add_to_config(config_data, LineConfiguration(), args.defaults) if 'all' in args.clients or 'twilio' in args.clients: self.add_to_config(config_data, TwilioConfiguration(), args.defaults) if 'all' in args.clients or 'viber' in args.clients: self.add_to_config(config_data, ViberConfiguration(), args.defaults) if 'all' in args.clients or 'sanic' in args.clients: self.add_to_config(config_data, SanicRestConfiguration(name="sanic")) client_config = ConsoleConfiguration() bot_config = client_config.configurations[0] self.add_to_config(config_data, bot_config, args.defaults) brain_config = bot_config.configurations[0] self.add_to_config(config_data, brain_config, args.defaults) self.write_yaml(args.file, config_data)
def test_to_yaml_with_defaults(self): config = KikConfiguration() data = {} config.to_yaml(data, True) self.assertEqual(data['bot_name'], "program-y") self.assertEqual(data['webhook'], "https://666666666.ngrok.io") self.assertEqual(data['unknown_command'], "Unknown command") self.assertEqual(data['unknown_command_srai'], 'KIKUNKNONWCOMMAND') self.assertEqual(data['bot'], 'bot') self.assertEqual(data['bot_selector'], "programy.clients.client.DefaultBotSelector") self.assertEqual(data['renderer'], "programy.clients.render.text.TextRenderer")
def get_client_configuration(self): return KikConfiguration()