def test_encode_ack(self): """encoding ack packet """ encoded_message = encode({ 'type': 'ack', 'ackId': 140, 'endpoint': '', 'args': [] }) self.assertEqual(encoded_message, '6:::140') # encoding ack packet with args encoded_message = encode({ 'type': 'ack', 'ackId': 12, 'endpoint': '', 'args': ["woot", "wa"] }) self.assertEqual(encoded_message, '6:::12+["woot","wa"]') # encoding ack packet with args and endpoint encoded_message = encode({ 'type': 'ack', 'ackId': 12, 'endpoint': '/chat', 'args': ["woot", "wa"] }) self.assertEqual(encoded_message, '6::/chat:12+["woot","wa"]')
def test_encode_event(self): """encoding an event packet """ encoded_message = encode({'type': 'event', 'endpoint': '', 'name': 'woot', 'args': [] }) self.assertEqual(encoded_message, '5:::{"name":"woot"}') # encoding an event packet with message id and ack encoded_message = encode({'type': 'event', 'name': 'tobi', 'id': 1, 'ack': True, 'data': '' }) self.assertEqual(encoded_message, '5:1+::{"name":"tobi"}') # encoding an event packet with data encoded_message = encode({'type': 'event', 'name': 'edwald', 'ack': True, 'endpoint': '', 'args': [{"a":"b"}, 2,"3"] }) self.assertEqual(encoded_message, '5:::{"args":[{"a":"b"},2,"3"],"name":"edwald"}')
def test_encode_error(self): """encoding error packet """ encoded_message = encode({'type': 'error', 'reason': '', 'advice': '', 'endpoint': '' }) self.assertEqual(encoded_message, '7:::') # encoding error packet with reason encoded_message = encode({'type': 'error', 'reason': 'transport not supported', 'advice': '', 'endpoint': '' }) self.assertEqual(encoded_message, '7:::0') # encoding error packet with reason and advice encoded_message = encode({'type': 'error', 'reason': 'unauthorized', 'advice': 'reconnect', 'endpoint': '' }) self.assertEqual(encoded_message, '7:::2+0') # encoding error packet with endpoint encoded_message = encode({'type': 'error', 'reason': '', 'advice': '', 'endpoint': '/woot' }) self.assertEqual(encoded_message, '7:::/woot')
def test_encode_connect(self): """encoding a connection packet """ encoded_message = encode({'type': 'connect', 'endpoint': '/tobi', 'qs': '', }) self.assertEqual(encoded_message, '1::/tobi') # encoding a connection packet with query string encoded_message = encode({'type': 'connect', 'endpoint': '/test', 'qs': '?test=1' }) self.assertEqual(encoded_message, '1::/test:?test=1')
def test_encode_ack(self): """encoding ack packet """ encoded_message = encode({'type': 'ack', 'ackId': 140, 'endpoint': '', 'args': [] }) self.assertEqual(encoded_message, '6:::140') # encoding ack packet with args encoded_message = encode({'type': 'ack', 'ackId': 12, 'endpoint': '', 'args': ["woot","wa"] }) self.assertEqual(encoded_message, '6:::12+["woot","wa"]')
def test_encode_message_with_no_endpoint(self): """encoding a message packet """ encoded_message = encode({'type': 'message', 'endpoint': None, 'data': 'woot' }) self.assertEqual(encoded_message, '3:::woot')
def test_encode_message(self): """encoding a message packet """ encoded_message = encode({'type': 'message', 'endpoint': '', 'data': 'woot' }) self.assertEqual(encoded_message, '3:::woot') # encoding a message packet with id and endpoint encoded_message = encode({'type': 'message', 'endpoint': '/tobi', 'id': 5, 'ack': True, 'data': '' }) self.assertEqual(encoded_message, '3:5:/tobi')
def test_encode_noop(self): """encoding a noop packet """ encoded_message = encode({'type': 'noop', 'endpoint': '', 'data': '' }) self.assertEqual(encoded_message, '8::')
def test_encode_json(self): """encoding JSON packet """ encoded_message = encode({'type': 'json', 'endpoint': '', 'data': '2'}) self.assertEqual(encoded_message, '4:::"2"') # encoding json packet with message id and ack data encoded_message = encode({ 'type': 'json', 'id': 1, 'ack': 'data', 'endpoint': '', 'data': { 'a': 'b' } }) self.assertEqual(encoded_message, '4:1+::{"a":"b"}')
def test_encode_json(self): """encoding JSON packet """ encoded_message = encode({'type': 'json', 'endpoint': '', 'data': '2' }) self.assertEqual(encoded_message, '4:::"2"') # encoding json packet with message id and ack data encoded_message = encode({'type': 'json', 'id': 1, 'ack': 'data', 'endpoint': '', 'data': {'a' : 'b'} }) self.assertEqual(encoded_message, '4:1+::{"a":"b"}')
def test_encode_json_decimals(self): """encoding JSON packet with a decimal""" # encoding json packet with message id and ack data encoded_message = encode({'type': 'json', 'id': 1, 'ack': 'data', 'endpoint': '', 'data': {'a' : decimal.Decimal('%f' % (0.5))} }) self.assertEqual(encoded_message, '4:1+::{"a":0.5}')
def test_encode_json_decimals(self): """encoding JSON packet with a decimal""" # encoding json packet with message id and ack data encoded_message = encode({'type': 'json', 'id': 1, 'ack': 'data', 'endpoint': '', 'data': {'a' : decimal.Decimal('%0.1f' % (0.5))} }) self.assertEqual(encoded_message, '4:1+::{"a":0.5}')
def test_encode_event(self): """encoding an event packet """ encoded_message = encode({ 'type': 'event', 'endpoint': '', 'name': 'woot', 'args': [] }) self.assertEqual(encoded_message, '5:::{"name":"woot"}') # encoding an event packet with message id and ack encoded_message = encode({ 'type': 'event', 'name': 'tobi', 'id': 1, 'ack': True, 'data': '' }) self.assertEqual(encoded_message, '5:1::{"name":"tobi"}') # encoding an event packet with message id and ack = 'data' encoded_message = encode({ 'type': 'event', 'name': 'tobi', 'id': 1, 'ack': 'data', 'data': '' }) self.assertEqual(encoded_message, '5:1+::{"name":"tobi"}') # encoding an event packet with data encoded_message = encode({ 'type': 'event', 'name': 'edwald', 'ack': True, 'endpoint': '', 'args': [{ "a": "b" }, 2, "3"] }) self.assertEqual(encoded_message, '5:::{"args":[{"a":"b"},2,"3"],"name":"edwald"}')
def send_packet(self, pkt): """Low-level interface to queue a packet on the wire (encoded as wire protocol""" self.put_client_msg(packet.encode(pkt))
def test_encode_heartbeat(self): """encoding a connection packet """ encoded_message = encode({'type': 'heartbeat', 'endpoint': '' }) self.assertEqual(encoded_message, '2::')
def test_encode_disconnect(self): """encoding a disconnection packet """ encoded_message = encode({'type': 'disconnect', 'endpoint': '/woot'}) self.assertEqual(encoded_message, '0::/woot')
def test_encode_disconnect(self): """encoding a disconnection packet """ encoded_message = encode({'type': 'disconnect', 'endpoint': '/woot' }) self.assertEqual(encoded_message, '0::/woot')
def send_packet(self, pkt): """Low-level interface to queue a packet on the wire (encoded as wire protocol""" self.put_client_msg(packet.encode(pkt, self.json_dumps))
def test_encode_heartbeat(self): """encoding a connection packet """ encoded_message = encode({'type': 'heartbeat', 'endpoint': ''}) self.assertEqual(encoded_message, '2::')