def test_ack_with_bad_json(self): """ NOTE: this test differs from original, as we prefer throwing an error then silently ignore (read the ZEN). """ with self.assertRaises(DecodeError): Packet.decode(b'6:::1+{"++]')
def test_connect_with_querystring(self): msg = Packet.decode(b'1::/test:?test=1') self.assertMsg(msg, type="connect", endpoint="/test", qs={"test": ["1"]})
def test_connect(self): msg = Packet.decode(b'1::/tobi') self.assertMsg(msg, type="connect", endpoint="/tobi", qs={})
def test_heartbeat(self): msg = Packet.decode(b'2::') self.assertMsg(msg, type="heartbeat")
def test_message_with_id_and_endpoint(self): msg = Packet.decode(b'3:5:/tobi') self.assertMsg(msg, type="message", id=b'5', ack=True, data=b"", endpoint="/tobi")
def test_message(self): msg = Packet.decode(b'3:::woot') self.assertMsg(msg, type="message", data=b"woot")
def test_event_with_data(self): msg = Packet.decode(b'5:::{"name":"edwald","args":[{"a": "b"},2,"3"]}') self.assertMsg(msg, type="event", name="edwald", args=[{"a": "b"}, 2, "3"])
def test_error_with_reason(self): msg = Packet.decode(b"7:::0") self.assertMsg(msg, type="error", reason="transport not supported", advice="")
def test_json_with_message_id_and_ack(self): msg = Packet.decode(b'4:1+::{"a":"b"}') self.assertMsg(msg, type="json", id=b'1', ack="data", data={"a": "b"})
def test_json(self): msg = Packet.decode(b'4:::"2"') self.assertMsg(msg, type="json", data=b'2')
def test_ack_with_args(self): msg = Packet.decode(b'6:::12+["woot","wa"]') self.assertMsg(msg, type="ack", ackid=b'12', args=["woot", "wa"])
def test_ack(self): msg = Packet.decode(b"6:::140") self.assertMsg(msg, type="ack", ackid=b'140', args=[])
def test_error_with_endpoint(self): msg = Packet.decode(b"7::/woot") self.assertMsg(msg, type="error", reason="", advice="", endpoint="/woot")
def test_error_with_reason_and_advice(self): msg = Packet.decode(b"7:::2+0") self.assertMsg(msg, type="error", reason="unauthorized", advice="reconnect")
def test_disconnect(self): msg = Packet.decode(b'0::/woot') self.assertMsg(msg, type="disconnect", endpoint="/woot")
def test_event(self): msg = Packet.decode(b'5:::{"name":"woot"}') self.assertMsg(msg, type="event", name="woot", args=[])
def test_decoding_newline(self): msg = Packet.decode(b'3:::\n') self.assertMsg(msg, type="message", data=b"\n")
def test_error(self): msg = Packet.decode(b"7:::") self.assertMsg(msg, type="error", reason="", advice="")