Пример #1
0
    def test_from_wire_bad_input(self):
        raw_data = 'b'.encode()

        with self.assertRaises(PayloadParseError):
            DataPacket.from_wire(raw_data)

        code, message = (9, 'message ελληνικά'.encode())
        raw_data = b''.join((struct.pack('!H', code), message))
        with self.assertRaises(InvalidErrorcodeError):
            ErrorPacket.from_wire(raw_data)
Пример #2
0
    def test_from_wire_good_input(self):
        blockn, data = (7, 'non-ascii data ελληνικά'.encode())
        raw_data = b''.join((struct.pack('!H', blockn), data))
        packet = DataPacket.from_wire(raw_data)

        self.assertEqual(blockn, packet.blockn)
        self.assertEqual(data, packet.data)
Пример #3
0
    def test_to_wire(self):
        opcode, blockn, data = (DataPacket.opcode, 7, 'data ελληνικά'.encode())
        raw_data = b''.join((struct.pack('!HH', opcode, blockn), data))

        packet = DataPacket(blockn, data)
        self.assertEqual(packet.to_wire(), raw_data)
Пример #4
0
    def test_from_wire_bad_input(self):
        raw_data = 'b'.encode()

        with self.assertRaises(PayloadParseError):
            DataPacket.from_wire(raw_data)
Пример #5
0
    def test_from_wire(self):
        blockn = 12
        raw_data = struct.pack('!H', blockn)
        packet = DataPacket.from_wire(raw_data)

        self.assertEqual(blockn, packet.blockn)