def test_eq(): a, b = packets.PacketLogin(), packets.PacketLogin() assert a == b b.name = 'test' assert a != b b = packets.PacketList assert a != b
def test_pack_pl(): buf = [] assert _binarypack.pack_pl([], buf) == 2 assert "".join(buf) == b"\x00\x00" buf = [] assert _binarypack.pack_pl( [packets.PacketLogin(), packets.PacketLogin()], buf) == 44 assert "".join(buf) == \ b'\x00\x02\n\x00\x12\x00\x07unknown\x00\x07' \ b'unknown\n\x00\x12\x00\x07unknown\x00\x07unknown'
def test_dataReceived(self): global packetReceived_args packetReceived_args = [] self.protocol.packetReceived = lambda *a: packetReceived_args.append(a) self.protocol.transport = self.mock_transport([]) self.protocol.dataReceived(protocol.protocol_handshake) assert self.protocol.established packed = binarypack.pack(packets.PacketLogin()) self.protocol.dataReceived(packed) assert packetReceived_args == [(packets.PacketLogin(), )] packetReceived_args = [] # small chunks for c in packed: self.protocol.dataReceived(c) assert packetReceived_args == [(packets.PacketLogin(), )] packetReceived_args = [] # big chunks (2.5 + 0.5 packets) self.protocol.dataReceived(packed + packed + packed[:-3]) assert len(packetReceived_args) == 2 assert packetReceived_args[0] == (packets.PacketLogin(), ) assert packetReceived_args[1] == (packets.PacketLogin(), ) self.protocol.dataReceived(packed[-3:]) assert len(packetReceived_args) == 3 assert packetReceived_args[2] == (packets.PacketLogin(), )
def test_unpack_pl(): assert _binarypack.unpack_pl(b"\x00\x00", 0) == (2, []) assert _binarypack.unpack_pl( b'\x00\x02\n\x00\x12\x00\x07unknown\x00\x07' \ b'unknown\n\x00\x12\x00\x07unknown\x00\x07unknown' , 0) == (44, [packets.PacketLogin(), packets.PacketLogin()])
def botLogin(self, name, password): """login for bots""" self.sendPacket(packets.PacketLogin(name=name, password=password))