Exemple #1
0
    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)
Exemple #2
0
    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)
Exemple #3
0
    def test_to_yaml_with_defaults(self):
        config = TwitterConfiguration()

        data = {}
        config.to_yaml(data, True)

        self.assertEqual(data['polling_interval'], 60)
        self.assertEqual(data['rate_limit_sleep'], 900)

        self.assertEqual(data['follow_followers'], True)
        self.assertEqual(data['respond_to_mentions'], True)
        self.assertEqual(data['respond_to_directs'], False)

        self.assertEqual(data['welcome_message'], "Thanks for following me.")

        self.assertEqual(data['bot_selector'],
                         "programy.clients.botfactory.DefaultBotSelector")
        self.assertEqual(data['renderer'],
                         "programy.clients.render.text.TextRenderer")

        self.assertTrue('bots' in data)
        self.assertTrue('bot' in data['bots'])
        self.assertEqual(data['bot_selector'],
                         "programy.clients.botfactory.DefaultBotSelector")

        self.assertTrue('brains' in data['bots']['bot'])
        self.assertTrue('brain' in data['bots']['bot']['brains'])
Exemple #4
0
    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 = TwitterConfiguration()

        data = {}
        config.to_yaml(data, True)

        self.assertEqual(data['polling_interval'], 0)
        self.assertEqual(data['rate_limit_sleep'], -1)
        self.assertEqual(data['use_status'], False)
        self.assertEqual(data['use_direct_message'], False)
        self.assertEqual(data['auto_follow'], False)
        self.assertEqual(data['welcome_message'], "Thanks for following me.")

        self.assertEqual(data['bot'], 'bot')
        self.assertEqual(data['bot_selector'],
                         "programy.clients.client.DefaultBotSelector")
        self.assertEqual(data['renderer'],
                         "programy.clients.render.text.TextRenderer")
Exemple #6
0
    def test_to_yaml_with_defaults(self):
        config = TwitterConfiguration()

        data = {}
        config.to_yaml(data, True)

        self.assertEquals(data['polling_interval'], 0)
        self.assertEquals(data['rate_limit_sleep'], -1)
        self.assertEquals(data['use_status'], False)
        self.assertEquals(data['use_direct_message'], False)
        self.assertEquals(data['auto_follow'], False)
        self.assertEquals(data['storage'], 'file')
        self.assertEquals(data['storage_location'], './storage/twitter.data')
        self.assertEquals(data['welcome_message'], "Thanks for following me.")

        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")
Exemple #7
0
    def test_init(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text(
            """
            twitter:
              description: Program-Y Twitter Client
              polling_interval: 60
              rate_limit_sleep: 900
            
              follow_followers: True
              respond_to_mentions: True
              respond_to_directs: False
            
              mentions: |
                #askprogramy
                #programy
            
              welcome_message: "Thanks for following me."
        """, ConsoleConfiguration(), ".")

        twitter_config = TwitterConfiguration()
        twitter_config.load_configuration(yaml, ".")

        self.assertEqual("Program-Y Twitter Client",
                         twitter_config.description)

        self.assertEqual(60, twitter_config.polling_interval)
        self.assertEqual(900, twitter_config.rate_limit_sleep)

        self.assertTrue(twitter_config.follow_followers)
        self.assertTrue(twitter_config.respond_to_mentions)
        self.assertFalse(twitter_config.respond_to_directs)

        self.assertEqual(twitter_config.mentions,
                         ['#askprogramy', '#programy'])

        self.assertEqual("Thanks for following me.",
                         twitter_config.welcome_message)
Exemple #8
0
    def test_to_yaml_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
            other:
        """, ConsoleConfiguration(), ".")

        twitter_config = TwitterConfiguration()
        twitter_config.load_configuration(yaml, ".")

        twitter_config = TwitterConfiguration()
        twitter_config.load_configuration(yaml, ".")

        self.assertEqual(0, twitter_config.polling_interval)
        self.assertEqual(-1, twitter_config.rate_limit_sleep)
        self.assertFalse(twitter_config.use_status)
        self.assertFalse(twitter_config.use_direct_message)
        self.assertFalse(twitter_config.auto_follow)
        self.assertEqual("Thanks for following me.", twitter_config.welcome_message)
Exemple #9
0
    def test_to_yaml_no_data(self):
        yaml = YamlConfigurationFile()
        self.assertIsNotNone(yaml)
        yaml.load_from_text("""
            other:
        """, ConsoleConfiguration(), ".")

        twitter_config = TwitterConfiguration()
        twitter_config.load_configuration(yaml, ".")

        twitter_config = TwitterConfiguration()
        twitter_config.load_configuration(yaml, ".")

        self.assertEqual(60, twitter_config.polling_interval)
        self.assertEqual(900, twitter_config.rate_limit_sleep)

        self.assertTrue(twitter_config.follow_followers)
        self.assertTrue(twitter_config.respond_to_mentions)
        self.assertFalse(twitter_config.respond_to_directs)

        self.assertEqual("Thanks for following me.",
                         twitter_config.welcome_message)
Exemple #10
0
 def get_client_configuration(self):
     return TwitterConfiguration()