Example #1
0
class StubBotHandler:
    def __init__(self) -> None:
        self.storage = SimpleStorage()
        self.full_name = 'test-bot'
        self.email = '*****@*****.**'
        self.message_server = SimpleMessageServer()
        self.reset_transcript()

    def reset_transcript(self) -> None:
        self.transcript = []  # type: List[Tuple[str, Dict[str, Any]]]

    def identity(self) -> BotIdentity:
        return BotIdentity(self.full_name, self.email)

    def send_message(self, message: Dict[str, Any]) -> Dict[str, Any]:
        self.transcript.append(('send_message', message))
        return self.message_server.send(message)

    def send_reply(self,
                   message: Dict[str, Any],
                   response: str,
                   widget_content: Optional[str] = None) -> Dict[str, Any]:
        response_message = dict(content=response,
                                widget_content=widget_content)
        self.transcript.append(('send_reply', response_message))
        return self.message_server.send(response_message)

    def update_message(self, message: Dict[str, Any]) -> None:
        self.message_server.update(message)

    class BotQuitException(Exception):
        pass

    def quit(self, message: str = "") -> None:
        raise self.BotQuitException()

    def get_config_info(self,
                        bot_name: str,
                        optional: bool = False) -> Dict[str, Any]:
        return {}

    def unique_reply(self) -> Dict[str, Any]:
        responses = [
            message for (method, message) in self.transcript
            if method == 'send_reply'
        ]
        self.ensure_unique_response(responses)
        return responses[0]

    def unique_response(self) -> Dict[str, Any]:
        responses = [message for (method, message) in self.transcript]
        self.ensure_unique_response(responses)
        return responses[0]

    def ensure_unique_response(self, responses: List[Dict[str, Any]]) -> None:
        if not responses:
            raise Exception('The bot is not responding for some reason.')
        if len(responses) > 1:
            raise Exception(
                'The bot is giving too many responses for some reason.')
Example #2
0
 def __init__(self):
     # type: () -> None
     self.storage = SimpleStorage()
     self.full_name = 'test-bot'
     self.email = '*****@*****.**'
     self.message_server = SimpleMessageServer()
     self.reset_transcript()
Example #3
0
class StubBotHandler:
    def __init__(self):
        # type: () -> None
        self.storage = SimpleStorage()
        self.message_server = SimpleMessageServer()
        self.reset_transcript()

    def reset_transcript(self):
        # type: () -> None
        self.transcript = []  # type: List[Tuple[str, Dict[str, Any]]]

    def send_message(self, message):
        # type: (Dict[str, Any]) -> Dict[str, Any]
        self.transcript.append(('send_message', message))
        return self.message_server.send(message)

    def send_reply(self, message, response):
        # type: (Dict[str, Any], str) -> Dict[str, Any]
        response_message = dict(content=response)
        self.transcript.append(('send_reply', response_message))
        return self.message_server.send(response_message)

    def update_message(self, message):
        # type: (Dict[str, Any]) -> None
        self.message_server.update(message)

    class BotQuitException(Exception):
        pass

    def quit(self, message=""):
        # type: (str) -> None
        raise self.BotQuitException()

    def get_config_info(self, bot_name, optional=False):
        # type: (str, bool) -> Dict[str, Any]
        return {}

    def unique_reply(self):
        # type: () -> Dict[str, Any]
        responses = [
            message for (method, message) in self.transcript
            if method == 'send_reply'
        ]
        self.ensure_unique_response(responses)
        return responses[0]

    def unique_response(self):
        # type: () -> Dict[str, Any]
        responses = [message for (method, message) in self.transcript]
        self.ensure_unique_response(responses)
        return responses[0]

    def ensure_unique_response(self, responses):
        # type: (List[Dict[str, Any]]) -> None
        if not responses:
            raise Exception('The bot is not responding for some reason.')
        if len(responses) > 1:
            raise Exception(
                'The bot is giving too many responses for some reason.')
 def __init__(self):
     # type: () -> None
     self.storage = SimpleStorage()
     self.message_server = SimpleMessageServer()
     self.reset_transcript()
Example #5
0
 def __init__(self) -> None:
     self.storage = SimpleStorage()
     self.full_name = 'test-bot'
     self.email = '*****@*****.**'
     self.message_server = SimpleMessageServer()
     self.reset_transcript()
Example #6
0
class StubBotHandler:
    def __init__(self) -> None:
        self.storage = SimpleStorage()
        self.full_name = 'test-bot'
        self.email = '*****@*****.**'
        self.message_server = SimpleMessageServer()
        self.reset_transcript()

    def reset_transcript(self) -> None:
        self.transcript = []  # type: List[Tuple[str, Dict[str, Any]]]

    def identity(self) -> BotIdentity:
        return BotIdentity(self.full_name, self.email)

    def send_message(self, message: Dict[str, Any]) -> Dict[str, Any]:
        self.transcript.append(('send_message', message))
        return self.message_server.send(message)

    def send_reply(self, message: Dict[str, Any], response: str,
                   widget_content: Optional[str]=None) -> Dict[str, Any]:
        response_message = dict(
            content=response,
            widget_content=widget_content
        )
        self.transcript.append(('send_reply', response_message))
        return self.message_server.send(response_message)

    def update_message(self, message: Dict[str, Any]) -> None:
        self.message_server.update(message)

    class BotQuitException(Exception):
        pass

    def quit(self, message: str="") -> None:
        raise self.BotQuitException()

    def get_config_info(self, bot_name: str, optional: bool=False) -> Dict[str, Any]:
        return {}

    def unique_reply(self) -> Dict[str, Any]:
        responses = [
            message
            for (method, message)
            in self.transcript
            if method == 'send_reply'
        ]
        self.ensure_unique_response(responses)
        return responses[0]

    def unique_response(self) -> Dict[str, Any]:
        responses = [
            message
            for (method, message)
            in self.transcript
        ]
        self.ensure_unique_response(responses)
        return responses[0]

    def ensure_unique_response(self, responses: List[Dict[str, Any]]) -> None:
        if not responses:
            raise Exception('The bot is not responding for some reason.')
        if len(responses) > 1:
            raise Exception('The bot is giving too many responses for some reason.')