Пример #1
0
    def test_bad_creation(self):
        """SerialAPIGetCapabilities bad packet"""
        body = [0x10, 0x20, 0x35, 0x86, 0x19, 0xa7, 0x87, 0x23,
                0x07, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0xa7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x05,
                0x00, 0x80 ]
        # OK Packet
        packet = Packet(0x01, length=0x2b, packet_type=0x01, message_type=0x07,
                        body=body, checksum=0xe1)
        message = SerialAPIGetCapabilities(packet)

        # Bad preamble
        packet.preamble = 0x00
        assert_that(calling(SerialAPIGetCapabilities).with_args(packet),
                    raises(ValueError))
        packet.preamble = 0x01

        # Bad length
        packet.length = 0x24
        assert_that(calling(SerialAPIGetCapabilities).with_args(packet),
                    raises(ValueError))
        packet.length = 0x2b

        # Bad packet type
        packet.packet_type = 0x00
        assert_that(calling(SerialAPIGetCapabilities).with_args(packet),
                    raises(ValueError))
        packet.packet_type = 0x01

        # Bad message type
        packet.message_type = 0x03
        assert_that(calling(SerialAPIGetCapabilities).with_args(packet),
                    raises(ValueError))
        packet.message_type = 0x07
Пример #2
0
    def test_bad_creation(self):
        """ZWGetControllerCapabilities bad packet"""
        body = [0x0f]
        # OK Packet
        packet = Packet(0x01, length=0x04, packet_type=0x01, message_type=0x05,
                        body=body, checksum=0xe1)
        message = ZWGetControllerCapabilities(packet)

        # Bad preamble
        packet.preamble = 0x00
        assert_that(calling(ZWGetControllerCapabilities).with_args(packet),
                    raises(ValueError))
        packet.preamble = 0x01

        # Bad length
        packet.length = 0x03
        assert_that(calling(ZWGetControllerCapabilities).with_args(packet),
                    raises(ValueError))
        packet.length = 0x04

        # Bad packet type
        packet.packet_type = 0x00
        assert_that(calling(ZWGetControllerCapabilities).with_args(packet),
                    raises(ValueError))
        packet.packet_type = 0x01

        # Bad message type
        packet.message_type = 0x03
        assert_that(calling(ZWGetControllerCapabilities).with_args(packet),
                    raises(ValueError))
        packet.message_type = 0x05
Пример #3
0
    def test_bad_creation(self):
        """SerialAPIGetInitData bad packet"""
        body = [
            0x15, 0x23, 0x1d, 0x07, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0xa7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x05,
            0x00
        ]
        # OK Packet
        packet = Packet(0x01,
                        length=0x25,
                        packet_type=0x01,
                        message_type=0x02,
                        body=body,
                        checksum=0xe1)
        message = SerialAPIGetInitData(packet)

        # Bad preamble
        packet.preamble = 0x00
        assert_that(
            calling(SerialAPIGetInitData).with_args(packet),
            raises(ValueError))
        packet.preamble = 0x01

        # Bad length
        packet.length = 0x24
        assert_that(
            calling(SerialAPIGetInitData).with_args(packet),
            raises(ValueError))
        packet.length = 0x25

        # Bad packet type
        packet.packet_type = 0x00
        assert_that(
            calling(SerialAPIGetInitData).with_args(packet),
            raises(ValueError))
        packet.packet_type = 0x01

        # Bad message type
        packet.message_type = 0x03
        assert_that(
            calling(SerialAPIGetInitData).with_args(packet),
            raises(ValueError))
        packet.message_type = 0x02

        # Bad body bitmap length
        packet.body[2] = 0x1c
        assert_that(
            calling(SerialAPIGetInitData).with_args(packet),
            raises(ValueError))
        packet.body[2] = 0x1d
Пример #4
0
    def test_bad_creation(self):
        """SerialAPIGetCapabilities bad packet"""
        body = [
            0x10, 0x20, 0x35, 0x86, 0x19, 0xa7, 0x87, 0x23, 0x07, 0x02, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa7, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x81, 0x05, 0x00, 0x80
        ]
        # OK Packet
        packet = Packet(0x01,
                        length=0x2b,
                        packet_type=0x01,
                        message_type=0x07,
                        body=body,
                        checksum=0xe1)
        message = SerialAPIGetCapabilities(packet)

        # Bad preamble
        packet.preamble = 0x00
        assert_that(
            calling(SerialAPIGetCapabilities).with_args(packet),
            raises(ValueError))
        packet.preamble = 0x01

        # Bad length
        packet.length = 0x24
        assert_that(
            calling(SerialAPIGetCapabilities).with_args(packet),
            raises(ValueError))
        packet.length = 0x2b

        # Bad packet type
        packet.packet_type = 0x00
        assert_that(
            calling(SerialAPIGetCapabilities).with_args(packet),
            raises(ValueError))
        packet.packet_type = 0x01

        # Bad message type
        packet.message_type = 0x03
        assert_that(
            calling(SerialAPIGetCapabilities).with_args(packet),
            raises(ValueError))
        packet.message_type = 0x07
Пример #5
0
    def test_bad_creation(self):
        """SerialAPIGetInitData bad packet"""
        body = [0x15, 0x23, 0x1d, 
                0x07, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0xa7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81,
                0x05, 0x00]
        # OK Packet
        packet = Packet(0x01, length=0x25, packet_type=0x01, message_type=0x02,
                        body=body, checksum=0xe1)
        message = SerialAPIGetInitData(packet)

        # Bad preamble
        packet.preamble = 0x00
        assert_that(calling(SerialAPIGetInitData).with_args(packet),
                    raises(ValueError))
        packet.preamble = 0x01

        # Bad length
        packet.length = 0x24
        assert_that(calling(SerialAPIGetInitData).with_args(packet),
                    raises(ValueError))
        packet.length = 0x25

        # Bad packet type
        packet.packet_type = 0x00
        assert_that(calling(SerialAPIGetInitData).with_args(packet),
                    raises(ValueError))
        packet.packet_type = 0x01

        # Bad message type
        packet.message_type = 0x03
        assert_that(calling(SerialAPIGetInitData).with_args(packet),
                    raises(ValueError))
        packet.message_type = 0x02

        # Bad body bitmap length
        packet.body[2] = 0x1c
        assert_that(calling(SerialAPIGetInitData).with_args(packet),
                    raises(ValueError))        
        packet.body[2] = 0x1d
Пример #6
0
    def test_bad_creation(self):
        """ZWGetControllerCapabilities bad packet"""
        body = [0x0f]
        # OK Packet
        packet = Packet(0x01,
                        length=0x04,
                        packet_type=0x01,
                        message_type=0x05,
                        body=body,
                        checksum=0xe1)
        message = ZWGetControllerCapabilities(packet)

        # Bad preamble
        packet.preamble = 0x00
        assert_that(
            calling(ZWGetControllerCapabilities).with_args(packet),
            raises(ValueError))
        packet.preamble = 0x01

        # Bad length
        packet.length = 0x03
        assert_that(
            calling(ZWGetControllerCapabilities).with_args(packet),
            raises(ValueError))
        packet.length = 0x04

        # Bad packet type
        packet.packet_type = 0x00
        assert_that(
            calling(ZWGetControllerCapabilities).with_args(packet),
            raises(ValueError))
        packet.packet_type = 0x01

        # Bad message type
        packet.message_type = 0x03
        assert_that(
            calling(ZWGetControllerCapabilities).with_args(packet),
            raises(ValueError))
        packet.message_type = 0x05