Ejemplo n.º 1
0
 def processed_message(
         self,
         target=b'#target',
         sender=b'nick!ident@host',
         body='message body'):
     """Build a PRIVMSG, and process it with parsers.privmsg."""
     message = build_message('PRIVMSG', target, prefix=sender, suffix=body)
     return privmsg(ReceivedMessage(message))
Ejemplo n.º 2
0
 def test_all(self):
     """Command with prefix, params, and suffix."""
     message = build_message(
         b'COMMAND',
         b'param1',
         b'param2',
         prefix=b'something',
         suffix=b'suffix ftw!',
     )
     expected = b':something COMMAND param1 param2 :suffix ftw!\r\n'
     self.assertEqual(message, expected)
Ejemplo n.º 3
0
    def test_unicode(self):
        """
        Make sure build_message works when passed strings.

        No valid commands contain unicode chars, so not bothering with ♬ in it.
        """
        message = build_message(
            'COMMAND',
            'tést',
            'test',
            prefix='mμ',
            suffix='ftẃ!',
        )
        expected = b':m\xce\xbc COMMAND t\xc3\xa9st test :ft\xe1\xba\x83!\r\n'
        self.assertEqual(message, expected)
Ejemplo n.º 4
0
 def test_linefeed_in_suffix(self):
     """Make sure that the suffix cannot contain a linefeed (\r\n)."""
     with self.assertRaises(exceptions.StrayLineEnding):
         build_message('COMMAND', suffix='\r\n')
Ejemplo n.º 5
0
 def test_suffix(self):
     """Command with suffix."""
     message = build_message(b'COMMAND', suffix=b'suffix ftw!')
     self.assertEqual(message, b'COMMAND :suffix ftw!\r\n')
Ejemplo n.º 6
0
 def test_params(self):
     """Command with params."""
     message = build_message(b'COMMAND', b'param1', b'param2')
     self.assertEqual(message, b'COMMAND param1 param2\r\n')
Ejemplo n.º 7
0
 def test_prefix(self):
     """Command with prefix."""
     message = build_message(b'COMMAND', prefix=b'something')
     self.assertEqual(message, b':something COMMAND\r\n')
Ejemplo n.º 8
0
 def test_basic(self):
     """Simple command only."""
     message = build_message(b'COMMAND')
     self.assertEqual(message, b'COMMAND\r\n')
Ejemplo n.º 9
0
 def test_message_too_long(self):
     """Make sure that the the message cannot be longer than 512 bytes."""
     with self.assertRaises(exceptions.MessageTooLong):
         build_message('A' * 511)  # 513 chars when \r\n added.