Пример #1
0
class TestBuildFrame(TestCase):
    def setUp(self):
        self.protocol = StompProtocol()

    def test_build_frame_with_body(self):
        buf = self.protocol.build_frame('HELLO', {
            'from': 'me',
            'to': 'you'
        }, 'I Am The Walrus')

        self.assertEqual(
            buf, b'HELLO\n'
            b'from:me\n'
            b'to:you\n\n'
            b'I Am The Walrus'
            b'\x00')

    def test_build_frame_without_body(self):
        buf = self.protocol.build_frame('HI', {'from': '1', 'to': '2'})

        self.assertEqual(buf, b'HI\n' b'from:1\n' b'to:2\n\n' b'\x00')

    def test_build_frame_with_header_special_chars(self):
        buf = self.protocol.build_frame('MESSAGE', {
            'destination': 'me:123',
            'extra': 'you\nmore\rextra\\here'
        }, 'I Am The Walrus')

        self.assertEqual(
            buf, b'MESSAGE\n'
            b'destination:me\\c123\n'
            b'extra:you\\nmore\\rextra\\\\here\n\n'
            b'I Am The Walrus'
            b'\x00')

        self.protocol.feed_data(buf)
        frames = self.protocol.pop_frames()

        self.assertEqual(len(frames), 1)
        self.assertEqual(frames[0].command, 'MESSAGE')
        self.assertEqual(frames[0].headers, {
            'destination': 'me:123',
            'extra': 'you\nmore\rextra\\here'
        })
Пример #2
0
class TestBuildFrame(TestCase):
    def setUp(self):
        self.protocol = StompProtocol()

    def test_build_frame_with_body(self):
        buf = self.protocol.build_frame(
            "HELLO", {"from": "me", "to": "you"}, "I Am The Walrus"
        )

        self.assertEqual(
            buf, b"HELLO\n" b"from:me\n" b"to:you\n\n" b"I Am The Walrus" b"\x00"
        )

    def test_build_frame_without_body(self):
        buf = self.protocol.build_frame("HI", {"from": "1", "to": "2"})

        self.assertEqual(buf, b"HI\n" b"from:1\n" b"to:2\n\n" b"\x00")

    def test_build_frame_with_header_special_chars(self):
        buf = self.protocol.build_frame(
            "MESSAGE",
            {"destination": "me:123", "extra": "you\nmore\rextra\\here"},
            "I Am The Walrus",
        )

        self.assertEqual(
            buf,
            b"MESSAGE\n"
            b"destination:me\\c123\n"
            b"extra:you\\nmore\\rextra\\\\here\n\n"
            b"I Am The Walrus"
            b"\x00",
        )

        self.protocol.feed_data(buf)
        frames = self.protocol.pop_frames()

        self.assertEqual(len(frames), 1)
        self.assertEqual(frames[0].command, "MESSAGE")
        self.assertEqual(
            frames[0].headers,
            {"destination": "me:123", "extra": "you\nmore\rextra\\here"},
        )
Пример #3
0
class TestBuildFrame(TestCase):
    def setUp(self):
        self.protocol = StompProtocol()

    def test_build_frame_with_body(self):
        buf = self.protocol.build_frame('HELLO', {
            'from': 'me',
            'to': 'you'
        }, 'I Am The Walrus')

        self.assertEqual(
            buf, b'HELLO\n'
            b'from:me\n'
            b'to:you\n\n'
            b'I Am The Walrus'
            b'\x00')

    def test_build_frame_without_body(self):
        buf = self.protocol.build_frame('HI', {'from': '1', 'to': '2'})

        self.assertEqual(buf, b'HI\n' b'from:1\n' b'to:2\n\n' b'\x00')