Пример #1
0
    def test_should_create_payload_from_data_when_dst_port_factory_is_defined_and_parse_method_is_called(self):
        # GIVEN
        data = any_data()

        message_info = common.MessageInfo()
        message_info.src_port = any_port()
        message_info.dst_port = any_port()

        factory = UdpBasedOnSrcDstPortsPayloadFactory(
            src_dst_port_based_payload_factories={
                message_info.dst_port: BytesPayloadFactory()
            })

        # WHEN
        actual_data = factory.parse(io.BytesIO(data), message_info)

        # THEN
        self.assertEqual(data, actual_data.data)
Пример #2
0
    def test_should_create_payload_from_data_when_dst_port_factory_is_defined_and_parse_method_is_called(self):
        # GIVEN
        data = any_data()

        message_info = common.MessageInfo()
        message_info.src_port = any_port()
        message_info.dst_port = any_port()

        factory = UdpBasedOnSrcDstPortsPayloadFactory(
            src_dst_port_based_payload_factories={
                message_info.dst_port: UDPBytesPayloadFactory()
            })

        # WHEN
        actual_data = factory.parse(io.BytesIO(data), message_info)

        # THEN
        self.assertEqual(data, actual_data.data)
Пример #3
0
    def test_should_raise_RuntimeError_when_parse_method_is_called_but_required_factory_is_not_defined(self):
        # GIVEN
        data = any_data()

        message_info = common.MessageInfo()
        message_info.src_port = any_port()
        message_info.dst_port = any_port()

        factory = UdpBasedOnSrcDstPortsPayloadFactory(src_dst_port_based_payload_factories={})

        # THEN
        self.assertRaises(RuntimeError, factory.parse, io.BytesIO(data), message_info)