def test_should_create_new_command_with_passed_arguments(self):
     factory = CommandFactory
     factory.commandMapping = {"status": CommandMock}
     command = CommandFactory.create_command("status2")
     self.assertIsNotNone(command)
     self.assertIsInstance(command, UnknownCommand)
     self.assertEqual({"message_text": "Unknown command"}, command.process("reer"))
Ejemplo n.º 2
0
    def check_updates(self, data):

        # Message gets accepted if
        # (1) Sender is authorized
        # (2) Correct recipient
        for update in data:
            self.offset = update['update_id']
            from_id = update['message']['chat']['id']
            name = update['message']['chat']['first_name']
            if from_id not in self.configuration.allowed_access:
                LoggingService.info("Unauthorized access")
                return self.send_text(from_id, UnauthorizedCommand(None).process(from_id))
                continue
            message = update['message']['text']
            parameters = (self.offset, name, from_id, message)
            LoggingService.info('Message (id%s) from %s (id%s): "%s"' % parameters)
            body = self.check_recipient_params(message)
            if body is None:
                LoggingService.info("Different recipient")
                continue
            command = CommandFactory.create_command(body)
            try:
                return_message = command.process(from_id)
                self.send_message(from_id, return_message)
            except Exception as inst:
                LoggingService.exception(inst)
                return self.send_text(from_id, str(inst))
Ejemplo n.º 3
0
    def check_updates(self, data):

        # Message gets accepted if
        # (1) Sender is authorized
        # (2) Correct recipient
        for update in data:
            self.offset = update['update_id']
            from_id = update['message']['chat']['id']
            name = update['message']['chat']['first_name']
            if from_id not in self.configuration.allowed_access:
                LoggingService.info("Unauthorized access")
                return self.send_text(
                    from_id,
                    UnauthorizedCommand(None).process(from_id))
                continue
            message = update['message']['text']
            parameters = (self.offset, name, from_id, message)
            LoggingService.info('Message (id%s) from %s (id%s): "%s"' %
                                parameters)
            body = self.check_recipient_params(message)
            if body is None:
                LoggingService.info("Different recipient")
                continue
            command = CommandFactory.create_command(body)
            try:
                return_message = command.process(from_id)
                self.send_message(from_id, return_message)
            except Exception as inst:
                LoggingService.exception(inst)
                return self.send_text(from_id, str(inst))
 def test_should_create_new_command_with_passed_arguments(self):
     factory = CommandFactory
     factory.commandMapping = {"status": CommandMock}
     command = CommandFactory.create_command("status2")
     self.assertIsNotNone(command)
     self.assertIsInstance(command, UnknownCommand)
     self.assertEqual({"message_text": "Unknown command"},
                      command.process("reer"))
 def test_should_create_new_command(self):
     factory = CommandFactory
     factory.commandMapping = {"status": CommandMock, "status2": None}
     command = CommandFactory.create_command("status")
     self.assertIsNotNone(command)
     self.assertEqual(None, command.params)
 def test_should_create_new_command_with_passed_arguments(self):
     factory = CommandFactory
     factory.commandMapping = {"status": CommandMock}
     command = CommandFactory.create_command("status param1 param2")
     self.assertIsNotNone(command)
     self.assertEqual("param1 param2", command.params)
 def test_should_create_new_command(self):
     factory = CommandFactory
     factory.commandMapping = {"status": CommandMock, "status2": None}
     command = CommandFactory.create_command("status")
     self.assertIsNotNone(command)
     self.assertEqual(None, command.params)
 def test_should_create_new_command_with_passed_arguments(self):
     factory = CommandFactory
     factory.commandMapping = {"status": CommandMock}
     command = CommandFactory.create_command("status param1 param2")
     self.assertIsNotNone(command)
     self.assertEqual("param1 param2", command.params)