def test_dataReceived_unexpected_exception(self): class MyError(Exception): pass stomp = StompClient() stomp.cmdMap['DISCONNECT'] = mock.Mock(side_effect=MyError) self.assertRaises(MyError, stomp.dataReceived, stomper.disconnect())
def test_dataReceived_binary(self): body = binascii.a2b_hex('f0000a09') hdrs = {'foo': '1', 'content-length': str(len(body))} frame = {'cmd': 'MESSAGE', 'headers': hdrs, 'body': body} frameBytes = createFrame(frame).pack() stomp = StompClient() stomp.cmdMap[frame['cmd']] = mock.Mock() stomp.dataReceived(frameBytes) self.assertEquals(1, stomp.cmdMap[frame['cmd']].call_count) stomp.cmdMap[frame['cmd']].assert_called_with({'cmd': frame['cmd'], 'headers': hdrs, 'body': body})
def test_dataReceived_multiple_messages(self): hdrs = {'foo': '1'} body = 'blah' frame = {'cmd': 'MESSAGE', 'headers': hdrs, 'body': body} frameBytes = createFrame(frame).pack() + createFrame(frame).pack() stomp = StompClient() stomp.cmdMap[frame['cmd']] = mock.Mock() stomp.dataReceived(frameBytes) self.assertEquals(2, stomp.cmdMap[frame['cmd']].call_count) stomp.cmdMap[frame['cmd']].assert_called_with({'cmd': frame['cmd'], 'headers': hdrs, 'body': body})
def test_dataReceived_partial_message(self): hdrs = {'foo': '1'} body = 'blah' frame = {'cmd': 'MESSAGE', 'headers': hdrs, 'body': body} frameBytes = createFrame(frame).pack() split = 8 stomp = StompClient() stomp.cmdMap[frame['cmd']] = mock.Mock() stomp.dataReceived(frameBytes[:split]) stomp.dataReceived(frameBytes[split:]) self.assertEquals(1, stomp.cmdMap[frame['cmd']].call_count) stomp.cmdMap[frame['cmd']].assert_called_with({'cmd': frame['cmd'], 'headers': hdrs, 'body': body})