Ejemplo n.º 1
0
    def test_exec(self):
        auth = AuthManager("test/etc/users.auth")
        authkey = AuthKey(None, "my.pass")

        commander = Commander(auth)
        
        print commander.execute(self.command, self.data, authkey)
Ejemplo n.º 2
0
    def test_exec(self):
        auth = AuthManager("test/etc/users.auth")
        authkey = AuthKey(None, "my.pass")

        commander = Commander(auth)

        print commander.execute(self.command, self.data, authkey)
Ejemplo n.º 3
0
 def test_set_max_cal_commander(self):
     cmndr = Commander()
     userstore.register_user_commands(cmndr)
     request_body = {
         'message': {
             'from': {
                 'first_name': 'igor',
                 'id': '777'
             }
         }
     }
     set_reply = cmndr.execute('/set_max_calories', request_body, ['2000'])
     get_reply = cmndr.execute('/show_max_calories', request_body)
     assert set_reply == 'igor, max calories were updated.'
     assert get_reply == 'igor, your max calories is 2000'
Ejemplo n.º 4
0
def main():
    try:
        # Load system configuration
        conf = parse_arguments()

        # Send logging output to a file if specified
        configure_log(conf["log.file"])

        # Look for available commands
        commands = find_commands("cmds/", conf["home.dir"])

        # Core components
        auth = AuthManager(conf["home.dir"] + "/users.auth")
        commander = Commander(auth)
        scanner = MailScanner(Parsers(commands))
        notifier = EmailNotifier(conf["smtp.host"], conf["smtp.port"])

        # Read the email from stdin
        email = UnicodeParser().parse(sys.stdin)

        cmd_id, data, sprops, authkey = scanner.scan(email)
        auth_users = [ key.user for key in auth.keys[cmd_id] if key.user ]

        command = commands[cmd_id]
        output = commander.execute(command, data, authkey)

        if output:
            notifier.send(SuccessNotification(conf["notification.sender"], \
                                              auth_users, command, sprops))
    except AuthException, err:
        notifier.send(AuthNotification(cmd_id, conf["commander.address"], \
                                       auth_users, email, data))
Ejemplo n.º 5
0
 def test_reply_max_cal_comndr(self):
     cmndr = Commander()
     userstore.register_user_commands(cmndr)
     request_body = {
         'message': {
             'from': {
                 'first_name': 'igor',
                 'id': '777'
             }
         }
     }
     show_reply = cmndr.execute('/show_max_calories', request_body)
     assert show_reply == 'igor, sorry but you didn\'t set max calories.'
     cmndr.execute('/set_max_calories', request_body, ['4000'])
     show_reply1 = cmndr.execute('/show_max_calories', request_body)
     assert show_reply1 == 'igor, your max calories is 4000'
Ejemplo n.º 6
0
 def test_update_coffee(self):
     cmndr = Commander()
     coffeestore.registerCoffeeCommands(cmndr)
     cmndr.execute(
         '/coffeeupd', {
             'message': {
                 'date': 1542830400,
                 'from': {
                     'first_name': 'igor',
                     'id': 123
                 }
             }
         }, ['10'])
     key = coffeestore.getCoffeeKey(123, '1542830400')
     coffee_amount = coffeestore.getCoffeeAmount(key)
     assert coffee_amount.timesDrank == 10
Ejemplo n.º 7
0
 def test_update_water(self):
     cmndr = Commander()
     waterstore.registerWaterCommands(cmndr)
     cmndr.execute(
         '/waterupd', {
             'message': {
                 'date': 1542830400,
                 'from': {
                     'first_name': 'igor',
                     'id': '123'
                 }
             }
         }, ['10'])
     key = waterstore.getWaterKey('123', '1542830400')
     water_amount = waterstore.getWaterAmount(key)
     assert water_amount.timesDrank == 10
Ejemplo n.º 8
0
def main():
    try:
        # Load system configuration
        conf = parse_arguments()

        # Send logging output to a file if specified
        configure_log(conf["log.file"])

        # Look for available commands
        commands = find_commands("cmds/", conf["home.dir"])

        # Core components
        auth = AuthManager(conf["home.dir"] + "/users.auth")
        commander = Commander(auth)
        scanner = MailScanner(Parsers(commands))
        notifier = EmailNotifier(conf["smtp.host"], conf["smtp.port"])

        # Read the email from stdin
        email = UnicodeParser().parse(sys.stdin)

        cmd_id, data, sprops, authkey = scanner.scan(email)
        auth_users = [key.user for key in auth.keys[cmd_id] if key.user]

        command = commands[cmd_id]
        output = commander.execute(command, data, authkey)

        if output:
            notifier.send(SuccessNotification(conf["notification.sender"], \
                                              auth_users, command, sprops))
    except AuthException, err:
        notifier.send(AuthNotification(cmd_id, conf["commander.address"], \
                                       auth_users, email, data))
Ejemplo n.º 9
0
 def test_set_max_cal_commander_wrong(self):
     cmndr = Commander()
     userstore.register_user_commands(cmndr)
     request_body = {
         'message': {
             'from': {
                 'first_name': 'igor',
                 'id': '777'
             }
         }
     }
     set_reply = cmndr.execute('/set_max_calories', request_body, [])
     assert set_reply == 'Didn\'t fully understand. Should be like: /set_max_calories 1800'
     set_reply = cmndr.execute('/set_max_calories', request_body, ['fdsd'])
     assert set_reply == 'Didn\'t fully understand. Should be like: /set_max_calories 1800'
     set_reply = cmndr.execute('/set_max_calories', request_body,
                               ['200', '2002'])
     assert set_reply == 'Didn\'t fully understand. Should be like: /set_max_calories 1800'
Ejemplo n.º 10
0
    def test_register_and_execute(self):
        commander = Commander()

        def command(request_body):
            return True

        commander.register_command('command', command)
        result = commander.execute('command', {})
        assert result == True
Ejemplo n.º 11
0
    def test_execute_params(self):
        commander = Commander()

        def command(text):
            return text

        commander.register_command('com', command)
        result = commander.execute('com', 'shalom')
        assert result == 'shalom'
Ejemplo n.º 12
0
class TestMailCommander(TestCase):
    
    def __init__(self, name):
        TestCase.__init__(self, name)
        
        self.commands = find_commands("test/cmds/")

        self.auth = AuthManager("test/etc/users.auth")
        self.commander = Commander(self.auth)
        
        self.scanner = MailScanner(Parsers(self.commands))
        self.email = UnicodeParser().parse(open("test/data/cmd.email"))

        self.notifier = EmailNotifier("10.2.1.2", 25)

    def test_commander(self):
        cmd_id, data, sprops, authkey = self.scanner.scan(self.email)

        command = self.commands[cmd_id]
        self.commander.execute(command, data, authkey)

        print command.output["text"]

    def test_auth_notification(self):
        cmd_id, data, sprops, authkey = self.scanner.scan(self.email)
        command = self.commands[cmd_id]

        self.commander.execute(command, data, authkey)

        sender = "*****@*****.**"
        recipients = ["*****@*****.**"]

        notification = AuthNotification(cmd_id, sender, recipients,
                                        self.email, data)

        self.notifier.send(notification)

    def test_success_notification(self):
        cmd_id, data, sprops, authkey = self.scanner.scan(self.email)
        command = self.commands[cmd_id]

        self.commander.execute(command, data, authkey)

        sender = "*****@*****.**"
        recipients = []

        notification = SuccessNotification(sender, recipients, command, sprops)
        self.notifier.send(notification)
Ejemplo n.º 13
0
class TestMailCommander(TestCase):
    def __init__(self, name):
        TestCase.__init__(self, name)

        self.commands = find_commands("test/cmds/")

        self.auth = AuthManager("test/etc/users.auth")
        self.commander = Commander(self.auth)

        self.scanner = MailScanner(Parsers(self.commands))
        self.email = UnicodeParser().parse(open("test/data/cmd.email"))

        self.notifier = EmailNotifier("10.2.1.2", 25)

    def test_commander(self):
        cmd_id, data, sprops, authkey = self.scanner.scan(self.email)

        command = self.commands[cmd_id]
        self.commander.execute(command, data, authkey)

        print command.output["text"]

    def test_auth_notification(self):
        cmd_id, data, sprops, authkey = self.scanner.scan(self.email)
        command = self.commands[cmd_id]

        self.commander.execute(command, data, authkey)

        sender = "*****@*****.**"
        recipients = ["*****@*****.**"]

        notification = AuthNotification(cmd_id, sender, recipients, self.email,
                                        data)

        self.notifier.send(notification)

    def test_success_notification(self):
        cmd_id, data, sprops, authkey = self.scanner.scan(self.email)
        command = self.commands[cmd_id]

        self.commander.execute(command, data, authkey)

        sender = "*****@*****.**"
        recipients = []

        notification = SuccessNotification(sender, recipients, command, sprops)
        self.notifier.send(notification)
Ejemplo n.º 14
0
 def test_enable_bot(self):
     cmndr = Commander()
     botenabler.register_user_commands(cmndr)
     request_body = {'message': {'chat': {'id': 123}, 'from': {'first_name': 'Jon'}}}
     result = cmndr.execute('/start', request_body, [])
     assert u'Hi Jon' in result
Ejemplo n.º 15
0
'''Base module for YTScraper'''
from commander import Commander

if __name__ == '__main__':
    INPUT = input('Please input a full YouTube video/playlist link:\n')
    COMMANDER = Commander()

    if 'playlist' in INPUT:
        COMMANDER_SETTINGS = {'set_dataprocessor': 'playlist',
                              'set_scraper': 'requests'}
        COMMANDER.execute(COMMANDER_SETTINGS)

        PLAYLIST_SETTINGS = {'link': INPUT,
                             'parse': True,
                             #'save': True,
                             'display': False}
        COMMANDER.execute(PLAYLIST_SETTINGS)
        DATA = COMMANDER.dataprocessor.current_data

        COMMANDER_SETTINGS = {'set_dataprocessor': 'video',
                              'set_scraper': 'requests',
                              'set_recommender': 'simple'}
        COMMANDER.execute(COMMANDER_SETTINGS)

        VIDEO_SETTINGS = {'link': '',
                          'parse': True,
                          #'save': True,
                          'display': False,
                          'recommend': True}
        for video in DATA:
            VIDEO_SETTINGS['link'] = video
Ejemplo n.º 16
0
 def test_add_default_food(self):
     cmndr = Commander()
     foodstore.registerFoodStoreCommands(cmndr)
     result = cmndr.execute('/add_food_default', {}, ['\ud83c\udf6a','100'])
     assert result == 'Got it ! \ud83c\udf6a=100'