示例#1
0
    def test_format_userid_log_message_unknown(self, unknown_user_log_message):
        """Should correctly format the user ID portion when the actual user it belongs to is unknown."""
        token = Token("NDcyMjY1OTQzMDYyNDEzMzMy", "XsySD_",
                      "s45jqDV_Iisn-symw0yDRrk_jf4")
        unknown_user_log_message.format.return_value = " Partner"
        msg = MockMessage(id=555, content="hello world")
        msg.guild.get_member.return_value = None

        return_value = TokenRemover.format_userid_log_message(msg, token)

        self.assertEqual(return_value,
                         (unknown_user_log_message.format.return_value, False))
        unknown_user_log_message.format.assert_called_once_with(
            user_id=472265943062413332)
示例#2
0
    def test_format_log_message_user_token_user(self, user_token_message):
        """Should correctly format the user ID portion when the ID belongs to a known user."""
        token = Token("NDY3MjIzMjMwNjUwNzc3NjQx", "XsySD_",
                      "s45jqDV_Iisn-symw0yDRrk_jf4")
        user_token_message.format.return_value = "Partner"

        return_value = TokenRemover.format_userid_log_message(self.msg, token)

        self.assertEqual(return_value,
                         (user_token_message.format.return_value, True))
        user_token_message.format.assert_called_once_with(
            user_id=467223230650777641,
            user_name="Woody",
            kind="USER",
        )
示例#3
0
    def test_format_log_message(self, log_message):
        """Should correctly format the log message with info from the message and token."""
        token = Token("NDY3MjIzMjMwNjUwNzc3NjQx", "XsySD_",
                      "s45jqDV_Iisn-symw0yDRrk_jf4")
        log_message.format.return_value = "Howdy"

        return_value = TokenRemover.format_log_message(self.msg, token)

        self.assertEqual(return_value, log_message.format.return_value)
        log_message.format.assert_called_once_with(
            author=format_user(self.msg.author),
            channel=self.msg.channel.mention,
            user_id=token.user_id,
            timestamp=token.timestamp,
            hmac="x" * len(token.hmac),
        )
示例#4
0
    def test_format_userid_log_message_bot(self, known_user_log_message):
        """Should correctly format the user ID portion when the ID belongs to a known bot."""
        token = Token("NDcyMjY1OTQzMDYyNDEzMzMy", "XsySD_",
                      "s45jqDV_Iisn-symw0yDRrk_jf4")
        known_user_log_message.format.return_value = " Partner"
        msg = MockMessage(id=555, content="hello world")
        msg.guild.get_member.return_value.__str__.return_value = "Sam"
        msg.guild.get_member.return_value.bot = True

        return_value = TokenRemover.format_userid_log_message(msg, token)

        self.assertEqual(return_value,
                         (known_user_log_message.format.return_value, False))

        known_user_log_message.format.assert_called_once_with(
            user_id=472265943062413332,
            user_name="Sam",
            kind="BOT",
        )