def test_connect(self):
        self.assertEquals(commands.connect(), StompFrame(StompSpec.CONNECT))
        self.assertEquals(commands.connect(login='******'), StompFrame(StompSpec.CONNECT, headers={StompSpec.LOGIN_HEADER: 'hi'}))
        self.assertEquals(commands.connect(passcode='there'), StompFrame(StompSpec.CONNECT, headers={StompSpec.PASSCODE_HEADER: 'there'}))
        self.assertEquals(commands.connect('hi', 'there'), StompFrame(StompSpec.CONNECT, headers={StompSpec.LOGIN_HEADER: 'hi', StompSpec.PASSCODE_HEADER: 'there'}))
        self.assertEquals(commands.connect('hi', 'there', {'4711': '0815'}), StompFrame(StompSpec.CONNECT, headers={StompSpec.LOGIN_HEADER: 'hi', StompSpec.PASSCODE_HEADER: 'there', '4711': '0815'}))

        self.assertEquals(commands.connect('hi', 'there', versions=[StompSpec.VERSION_1_0]), StompFrame(StompSpec.CONNECT, headers={StompSpec.LOGIN_HEADER: 'hi', StompSpec.PASSCODE_HEADER: 'there'}))

        frame = commands.connect(versions=[StompSpec.VERSION_1_0, StompSpec.VERSION_1_1])
        self.assertEquals(frame, StompFrame(StompSpec.CONNECT, headers={StompSpec.ACCEPT_VERSION_HEADER: '1.0,1.1', StompSpec.HOST_HEADER: ''}))

        frame = commands.connect(versions=[StompSpec.VERSION_1_1])
        self.assertEquals(frame, StompFrame(StompSpec.CONNECT, headers={StompSpec.ACCEPT_VERSION_HEADER: StompSpec.VERSION_1_1, StompSpec.HOST_HEADER: ''}))

        frame = commands.connect(versions=[StompSpec.VERSION_1_1], login='******', passcode='there', host='earth')
        self.assertEquals(frame, StompFrame(StompSpec.CONNECT, headers={StompSpec.ACCEPT_VERSION_HEADER: StompSpec.VERSION_1_1, StompSpec.LOGIN_HEADER: 'hi', StompSpec.PASSCODE_HEADER: 'there', StompSpec.HOST_HEADER: 'earth'}))

        frame = commands.connect(versions=[StompSpec.VERSION_1_1], login='******', passcode='there', host='earth', heartBeats=(1, 2))
        self.assertEquals(frame, StompFrame(StompSpec.CONNECT, headers={StompSpec.ACCEPT_VERSION_HEADER: StompSpec.VERSION_1_1, StompSpec.LOGIN_HEADER: 'hi', StompSpec.PASSCODE_HEADER: 'there', StompSpec.HOST_HEADER: 'earth', StompSpec.HEART_BEAT_HEADER: '1,2'}))

        frame = commands.connect('hi', 'there', None, [StompSpec.VERSION_1_1], 'earth', (1, 2))
        self.assertEquals(frame, StompFrame(StompSpec.CONNECT, headers={StompSpec.ACCEPT_VERSION_HEADER: StompSpec.VERSION_1_1, StompSpec.LOGIN_HEADER: 'hi', StompSpec.PASSCODE_HEADER: 'there', StompSpec.HOST_HEADER: 'earth', StompSpec.HEART_BEAT_HEADER: '1,2'}))

        for heartBeats in [('bla', 'bla'), (-1, 0), (0, -1), (-1, -1), 1, -1, 'bla']:
            self.assertRaises(StompProtocolError, commands.connect, versions=[StompSpec.VERSION_1_1], login='******', passcode='there', host='earth', heartBeats=heartBeats)

        frame = commands.connect(versions=[StompSpec.VERSION_1_1], host='earth', headers={'4711': '0815', StompSpec.HEART_BEAT_HEADER: '1,2'})
        self.assertEquals(frame, StompFrame(StompSpec.CONNECT, headers={StompSpec.ACCEPT_VERSION_HEADER: StompSpec.VERSION_1_1, '4711': '0815', StompSpec.HOST_HEADER: 'earth', StompSpec.HEART_BEAT_HEADER: '1,2'}))
        stompFrame = commands.stomp('hi', 'there', {'4711': '0815'}, [StompSpec.VERSION_1_1], 'earth')
        self.assertEquals(stompFrame.command, StompSpec.STOMP)
        self.assertEquals(stompFrame.headers, commands.connect('hi', 'there', {'4711': '0815'}, [StompSpec.VERSION_1_1], 'earth').headers)
        self.assertRaises(StompProtocolError, commands.stomp, 'hi', 'there', {'4711': '0815'}, [StompSpec.VERSION_1_0], 'earth')
        self.assertRaises(StompProtocolError, commands.stomp, 'hi', 'there', {'4711': '0815'}, None, 'earth')
Exemple #2
0
    def test_connect(self):
        self.assertEqual(commands.connect(), StompFrame(StompSpec.CONNECT))
        self.assertEqual(
            commands.connect(login='******'),
            StompFrame(StompSpec.CONNECT,
                       headers={StompSpec.LOGIN_HEADER: 'hi'}))
        self.assertEqual(
            commands.connect(passcode='there'),
            StompFrame(StompSpec.CONNECT,
                       headers={StompSpec.PASSCODE_HEADER: 'there'}))
        self.assertEqual(
            commands.connect('hi', 'there'),
            StompFrame(StompSpec.CONNECT,
                       headers={
                           StompSpec.LOGIN_HEADER: 'hi',
                           StompSpec.PASSCODE_HEADER: 'there'
                       }))
        self.assertEqual(
            commands.connect('hi', 'there', {'4711': '0815'}),
            StompFrame(StompSpec.CONNECT,
                       headers={
                           StompSpec.LOGIN_HEADER: 'hi',
                           StompSpec.PASSCODE_HEADER: 'there',
                           '4711': '0815'
                       }))

        self.assertEqual(
            commands.connect('hi', 'there', versions=[StompSpec.VERSION_1_0]),
            StompFrame(StompSpec.CONNECT,
                       headers={
                           StompSpec.LOGIN_HEADER: 'hi',
                           StompSpec.PASSCODE_HEADER: 'there'
                       }))

        frame = commands.connect(
            versions=[StompSpec.VERSION_1_0, StompSpec.VERSION_1_1])
        self.assertEqual(
            frame,
            StompFrame(StompSpec.CONNECT,
                       headers={
                           StompSpec.ACCEPT_VERSION_HEADER: '1.0,1.1',
                           StompSpec.HOST_HEADER: ''
                       }))

        frame = commands.connect(versions=[StompSpec.VERSION_1_1])
        self.assertEqual(
            frame,
            StompFrame(StompSpec.CONNECT,
                       headers={
                           StompSpec.ACCEPT_VERSION_HEADER:
                           StompSpec.VERSION_1_1,
                           StompSpec.HOST_HEADER: ''
                       }))

        frame = commands.connect(versions=[StompSpec.VERSION_1_1],
                                 login='******',
                                 passcode='there',
                                 host='earth')
        self.assertEqual(
            frame,
            StompFrame(StompSpec.CONNECT,
                       headers={
                           StompSpec.ACCEPT_VERSION_HEADER:
                           StompSpec.VERSION_1_1,
                           StompSpec.LOGIN_HEADER: 'hi',
                           StompSpec.PASSCODE_HEADER: 'there',
                           StompSpec.HOST_HEADER: 'earth'
                       }))

        frame = commands.connect(versions=[StompSpec.VERSION_1_1],
                                 login='******',
                                 passcode='there',
                                 host='earth',
                                 heartBeats=(1, 2))
        self.assertEqual(
            frame,
            StompFrame(StompSpec.CONNECT,
                       headers={
                           StompSpec.ACCEPT_VERSION_HEADER:
                           StompSpec.VERSION_1_1,
                           StompSpec.LOGIN_HEADER: 'hi',
                           StompSpec.PASSCODE_HEADER: 'there',
                           StompSpec.HOST_HEADER: 'earth',
                           StompSpec.HEART_BEAT_HEADER: '1,2'
                       }))

        frame = commands.connect('hi', 'there', None, [StompSpec.VERSION_1_1],
                                 'earth', (1, 2))
        self.assertEqual(
            frame,
            StompFrame(StompSpec.CONNECT,
                       headers={
                           StompSpec.ACCEPT_VERSION_HEADER:
                           StompSpec.VERSION_1_1,
                           StompSpec.LOGIN_HEADER: 'hi',
                           StompSpec.PASSCODE_HEADER: 'there',
                           StompSpec.HOST_HEADER: 'earth',
                           StompSpec.HEART_BEAT_HEADER: '1,2'
                       }))

        for heartBeats in [('bla', 'bla'), (-1, 0), (0, -1), (-1, -1), 1, -1,
                           'bla']:
            self.assertRaises(StompProtocolError,
                              commands.connect,
                              versions=[StompSpec.VERSION_1_1],
                              login='******',
                              passcode='there',
                              host='earth',
                              heartBeats=heartBeats)

        frame = commands.connect(versions=[StompSpec.VERSION_1_1],
                                 host='earth',
                                 headers={
                                     '4711': '0815',
                                     StompSpec.HEART_BEAT_HEADER: '1,2'
                                 })
        self.assertEqual(
            frame,
            StompFrame(StompSpec.CONNECT,
                       headers={
                           StompSpec.ACCEPT_VERSION_HEADER:
                           StompSpec.VERSION_1_1,
                           '4711': '0815',
                           StompSpec.HOST_HEADER: 'earth',
                           StompSpec.HEART_BEAT_HEADER: '1,2'
                       }))
        stompFrame = commands.stomp('hi', 'there', {'4711': '0815'},
                                    [StompSpec.VERSION_1_1], 'earth')
        self.assertEqual(stompFrame.command, StompSpec.STOMP)
        self.assertEqual(
            stompFrame.headers,
            commands.connect('hi', 'there', {
                '4711': '0815'
            }, [StompSpec.VERSION_1_1], 'earth').headers)
        self.assertRaises(StompProtocolError, commands.stomp, 'hi', 'there',
                          {'4711': '0815'}, [StompSpec.VERSION_1_0], 'earth')
        self.assertRaises(StompProtocolError, commands.stomp, 'hi', 'there',
                          {'4711': '0815'}, None, 'earth')
Exemple #3
0
    def test_session_connect(self):
        session = StompSession(StompSpec.VERSION_1_0, check=False)
        self.assertEqual(session.version, StompSpec.VERSION_1_0)
        for attribute in (session.server, session.id, session.lastSent,
                          session.lastReceived):
            self.assertEqual(attribute, None)
        for attribute in (session.clientHeartBeat, session.serverHeartBeat):
            self.assertEqual(attribute, 0)
        self.assertEqual(session.state, StompSession.DISCONNECTED)
        frame = session.connect(login='', passcode='')
        self.assertEqual(session.state, StompSession.CONNECTING)
        self.assertEqual(
            frame, commands.connect(login='', passcode='', versions=None))
        session.connected(
            StompFrame(StompSpec.CONNECTED, {StompSpec.SESSION_HEADER: 'hi'}))
        self.assertEqual(session.state, StompSession.CONNECTED)
        self.assertEqual(session.version, StompSpec.VERSION_1_0)
        self.assertEqual(session.server, None)
        self.assertEqual(session.id, 'hi')
        frame = session.disconnect()
        self.assertEqual(frame, commands.disconnect())
        session.close()
        self.assertEqual(session.server, None)
        self.assertEqual(session.id, None)
        self.assertEqual(session.state, StompSession.DISCONNECTED)
        self.assertRaises(StompProtocolError,
                          session.connect,
                          login='',
                          passcode='',
                          versions=[StompSpec.VERSION_1_1])

        session = StompSession(version=StompSpec.VERSION_1_1, check=False)
        self.assertEqual(session.version, StompSpec.VERSION_1_1)
        frame = session.connect(login='', passcode='')
        self.assertEqual(
            frame,
            commands.connect('', '', {},
                             [StompSpec.VERSION_1_0, StompSpec.VERSION_1_1]))
        self.assertEqual(session.state, StompSession.CONNECTING)
        session.connected(
            StompFrame(
                StompSpec.CONNECTED, {
                    StompSpec.SERVER_HEADER: 'moon',
                    StompSpec.SESSION_HEADER: '4711',
                    StompSpec.VERSION_HEADER: StompSpec.VERSION_1_1
                }))
        self.assertEqual(session.state, StompSession.CONNECTED)
        self.assertEqual(session.server, 'moon')
        self.assertEqual(session.id, '4711')
        self.assertEqual(session.state, StompSession.CONNECTED)
        self.assertEqual(session.version, StompSpec.VERSION_1_1)
        frame = session.disconnect('4711')
        self.assertEqual(frame, commands.disconnect('4711'))
        session.close()
        self.assertEqual(session.server, None)
        self.assertEqual(session.id, None)
        self.assertEqual(session.state, StompSession.DISCONNECTED)

        session.connect(
            login='',
            passcode='',
            versions=[StompSpec.VERSION_1_0, StompSpec.VERSION_1_1])
        session.connected(
            StompFrame(StompSpec.CONNECTED,
                       {StompSpec.SESSION_HEADER: '4711'}))
        self.assertEqual(session.state, StompSession.CONNECTED)
        self.assertEqual(session.server, None)
        self.assertEqual(session.id, '4711')
        self.assertEqual(session.version, StompSpec.VERSION_1_0)
        frame = session.disconnect()
        session.close()
        self.assertEqual(frame, commands.disconnect())
        self.assertEqual(session.server, None)
        self.assertEqual(session.id, None)
        self.assertEqual(session.state, StompSession.DISCONNECTED)
        self.assertEqual(session.version, StompSpec.VERSION_1_1)

        session = StompSession(version=StompSpec.VERSION_1_1, check=False)
        frame = session.connect(login='',
                                passcode='',
                                versions=[StompSpec.VERSION_1_1])
        self.assertEqual(frame,
                         commands.connect('', '', {}, [StompSpec.VERSION_1_1]))
        self.assertEqual(session._versions, [StompSpec.VERSION_1_1])
        self.assertEqual(session.state, StompSession.CONNECTING)
        session.connected(
            StompFrame(
                StompSpec.CONNECTED, {
                    StompSpec.SERVER_HEADER: 'moon',
                    StompSpec.SESSION_HEADER: '4711',
                    StompSpec.VERSION_HEADER: StompSpec.VERSION_1_1
                }))
        self.assertEqual(session.clientHeartBeat, 0)
        self.assertEqual(session.serverHeartBeat, 0)
        self.assertEqual(session.state, StompSession.CONNECTED)
        self.assertEqual(session._versions,
                         [StompSpec.VERSION_1_0, StompSpec.VERSION_1_1])
        self.assertEqual(session.version, StompSpec.VERSION_1_1)
        session.disconnect('4711')
        session.close()
        self.assertEqual(session.state, StompSession.DISCONNECTED)

        session = StompSession(version=StompSpec.VERSION_1_1, check=False)
        frame = session.connect(login='',
                                passcode='',
                                versions=[StompSpec.VERSION_1_1],
                                heartBeats=(1, 2))
        self.assertEqual(
            frame,
            commands.connect('',
                             '', {}, [StompSpec.VERSION_1_1],
                             heartBeats=(1, 2)))
        session.connected(
            StompFrame(
                StompSpec.CONNECTED, {
                    StompSpec.SERVER_HEADER: 'moon',
                    StompSpec.SESSION_HEADER: '4711',
                    StompSpec.VERSION_HEADER: StompSpec.VERSION_1_1,
                    StompSpec.HEART_BEAT_HEADER: '3,4'
                }))
        self.assertEqual(session.clientHeartBeat, 4)
        self.assertEqual(session.serverHeartBeat, 3)
        session.disconnect()
        session.close()
        self.assertEqual(session.clientHeartBeat, 0)
        self.assertEqual(session.serverHeartBeat, 0)

        session.connect(
            login='',
            passcode='',
            versions=[StompSpec.VERSION_1_0, StompSpec.VERSION_1_1])
        session.connected(
            StompFrame(StompSpec.CONNECTED,
                       {StompSpec.SESSION_HEADER: '4711'}))
        self.assertEqual(session.clientHeartBeat, 0)
        self.assertEqual(session.serverHeartBeat, 0)
        session.disconnect()
        session.close()

        session.connect(
            login='',
            passcode='',
            versions=[StompSpec.VERSION_1_0, StompSpec.VERSION_1_1])
        session.connected(
            StompFrame(
                StompSpec.CONNECTED, {
                    StompSpec.SESSION_HEADER: '4711',
                    StompSpec.HEART_BEAT_HEADER: '3,4'
                }))
        self.assertEqual(session.clientHeartBeat, 0)
        self.assertEqual(session.serverHeartBeat, 0)
        session.disconnect()
        session.close()
Exemple #4
0
    def test_session_connect(self):
        session = StompSession(StompSpec.VERSION_1_0, check=False)
        self.assertEqual(session.version, StompSpec.VERSION_1_0)
        for attribute in (session.server, session.id, session.lastSent, session.lastReceived):
            self.assertEqual(attribute, None)
        for attribute in (session.clientHeartBeat, session.serverHeartBeat):
            self.assertEqual(attribute, 0)
        self.assertEqual(session.state, StompSession.DISCONNECTED)
        frame = session.connect(login='', passcode='')
        self.assertEqual(session.state, StompSession.CONNECTING)
        self.assertEqual(frame, commands.connect(login='', passcode='', versions=None))
        session.connected(StompFrame(StompSpec.CONNECTED, {StompSpec.SESSION_HEADER: 'hi'}))
        self.assertEqual(session.state, StompSession.CONNECTED)
        self.assertEqual(session.version, StompSpec.VERSION_1_0)
        self.assertEqual(session.server, None)
        self.assertEqual(session.id, 'hi')
        frame = session.disconnect()
        self.assertEqual(frame, commands.disconnect())
        session.close()
        self.assertEqual(session.server, None)
        self.assertEqual(session.id, None)
        self.assertEqual(session.state, StompSession.DISCONNECTED)
        self.assertRaises(StompProtocolError, session.connect, login='', passcode='', versions=[StompSpec.VERSION_1_1])

        session = StompSession(version=StompSpec.VERSION_1_1, check=False)
        self.assertEqual(session.version, StompSpec.VERSION_1_1)
        frame = session.connect(login='', passcode='')
        self.assertEqual(frame, commands.connect('', '', {}, [StompSpec.VERSION_1_0, StompSpec.VERSION_1_1]))
        self.assertEqual(session.state, StompSession.CONNECTING)
        session.connected(StompFrame(StompSpec.CONNECTED, {StompSpec.SERVER_HEADER: 'moon', StompSpec.SESSION_HEADER: '4711', StompSpec.VERSION_HEADER: StompSpec.VERSION_1_1}))
        self.assertEqual(session.state, StompSession.CONNECTED)
        self.assertEqual(session.server, 'moon')
        self.assertEqual(session.id, '4711')
        self.assertEqual(session.state, StompSession.CONNECTED)
        self.assertEqual(session.version, StompSpec.VERSION_1_1)
        frame = session.disconnect('4711')
        self.assertEqual(frame, commands.disconnect('4711'))
        session.close()
        self.assertEqual(session.server, None)
        self.assertEqual(session.id, None)
        self.assertEqual(session.state, StompSession.DISCONNECTED)

        session.connect(login='', passcode='', versions=[StompSpec.VERSION_1_0, StompSpec.VERSION_1_1])
        session.connected(StompFrame(StompSpec.CONNECTED, {StompSpec.SESSION_HEADER: '4711'}))
        self.assertEqual(session.state, StompSession.CONNECTED)
        self.assertEqual(session.server, None)
        self.assertEqual(session.id, '4711')
        self.assertEqual(session.version, StompSpec.VERSION_1_0)
        frame = session.disconnect()
        session.close()
        self.assertEqual(frame, commands.disconnect())
        self.assertEqual(session.server, None)
        self.assertEqual(session.id, None)
        self.assertEqual(session.state, StompSession.DISCONNECTED)
        self.assertEqual(session.version, StompSpec.VERSION_1_1)

        session = StompSession(version=StompSpec.VERSION_1_1, check=False)
        frame = session.connect(login='', passcode='', versions=[StompSpec.VERSION_1_1])
        self.assertEqual(frame, commands.connect('', '', {}, [StompSpec.VERSION_1_1]))
        self.assertEqual(session._versions, [StompSpec.VERSION_1_1])
        self.assertEqual(session.state, StompSession.CONNECTING)
        session.connected(StompFrame(StompSpec.CONNECTED, {StompSpec.SERVER_HEADER: 'moon', StompSpec.SESSION_HEADER: '4711', StompSpec.VERSION_HEADER: StompSpec.VERSION_1_1}))
        self.assertEqual(session.clientHeartBeat, 0)
        self.assertEqual(session.serverHeartBeat, 0)
        self.assertEqual(session.state, StompSession.CONNECTED)
        self.assertEqual(session._versions, [StompSpec.VERSION_1_0, StompSpec.VERSION_1_1])
        self.assertEqual(session.version, StompSpec.VERSION_1_1)
        session.disconnect('4711')
        session.close()
        self.assertEqual(session.state, StompSession.DISCONNECTED)

        session = StompSession(version=StompSpec.VERSION_1_1, check=False)
        frame = session.connect(login='', passcode='', versions=[StompSpec.VERSION_1_1], heartBeats=(1, 2))
        self.assertEqual(frame, commands.connect('', '', {}, [StompSpec.VERSION_1_1], heartBeats=(1, 2)))
        session.connected(StompFrame(StompSpec.CONNECTED, {StompSpec.SERVER_HEADER: 'moon', StompSpec.SESSION_HEADER: '4711', StompSpec.VERSION_HEADER: StompSpec.VERSION_1_1, StompSpec.HEART_BEAT_HEADER: '3,4'}))
        self.assertEqual(session.clientHeartBeat, 4)
        self.assertEqual(session.serverHeartBeat, 3)
        session.disconnect()
        session.close()
        self.assertEqual(session.clientHeartBeat, 0)
        self.assertEqual(session.serverHeartBeat, 0)

        session.connect(login='', passcode='', versions=[StompSpec.VERSION_1_0, StompSpec.VERSION_1_1])
        session.connected(StompFrame(StompSpec.CONNECTED, {StompSpec.SESSION_HEADER: '4711'}))
        self.assertEqual(session.clientHeartBeat, 0)
        self.assertEqual(session.serverHeartBeat, 0)
        session.disconnect()
        session.close()

        session.connect(login='', passcode='', versions=[StompSpec.VERSION_1_0, StompSpec.VERSION_1_1])
        session.connected(StompFrame(StompSpec.CONNECTED, {StompSpec.SESSION_HEADER: '4711', StompSpec.HEART_BEAT_HEADER: '3,4'}))
        self.assertEqual(session.clientHeartBeat, 0)
        self.assertEqual(session.serverHeartBeat, 0)
        session.disconnect()
        session.close()