Example #1
0
    def create(args: Union[ShipmentRequest, dict]) -> IRequestFrom:
        """Submit a shipment creation to a carrier.
        This operation is often referred to as Buying a shipping label
        
        Args:
            args (Union[TrackingRequest, dict]): the shipment creation request payload

        Returns:
            IRequestWith: a lazy request dataclass instance
        """
        logger.debug(f"create a shipment. payload: {DP.jsonify(args)}")
        payload = args if isinstance(
            args, ShipmentRequest) else ShipmentRequest(**args)

        def action(gateway: Gateway):
            request: Serializable = gateway.mapper.create_shipment_request(
                payload)
            response: Deserializable = gateway.proxy.create_shipment(request)

            @fail_safe(gateway)
            def deserialize():
                return gateway.mapper.parse_shipment_response(response)

            return IDeserialize(deserialize)

        return IRequestFrom(action)
Example #2
0
 def test_create_shipment_with_package_preset_request(self):
     requests = gateway.mapper.create_shipment_request(
         ShipmentRequest(**shipment_with_package_preset_data))
     pipeline = requests.serialize()
     request = pipeline["create_shipment"]()
     self.assertEqual(request.data.serialize(),
                      ShipmentRequestWithPackagePresetXML)
Example #3
0
    def create(args: Union[ShipmentRequest, dict]):
        payload = (args if isinstance(args, ShipmentRequest) else
                   ShipmentRequest(**args))

        def action(gateway: Gateway):
            request: Serializable = gateway.mapper.create_shipment_request(
                payload)
            response: Deserializable = gateway.proxy.create_shipment(request)

            def deserialize():
                return gateway.mapper.parse_shipment_response(response)

            return IDeserialize(deserialize)

        return IRequestWith(action)
Example #4
0
    def create(args: Union[ShipmentRequest, dict]):
        logger.debug(f'create a shipment. payload: {jsonify(args)}')
        payload = (args if isinstance(args, ShipmentRequest) else
                   ShipmentRequest(**args))

        def action(gateway: Gateway):
            request: Serializable = gateway.mapper.create_shipment_request(
                payload)
            response: Deserializable = gateway.proxy.create_shipment(request)

            @fail_safe(gateway)
            def deserialize():
                return gateway.mapper.parse_shipment_response(response)

            return IDeserialize(deserialize)

        return IRequestWith(action)
Example #5
0
 def setUp(self):
     self.maxDiff = None
     self.ShipmentRequest = ShipmentRequest(**shipment_data)
     self.ShipmentCancelRequest = ShipmentCancelRequest(
         **shipment_cancel_data)
 def test_create_package_shipment_with_package_preset_request(self):
     request = gateway.mapper.create_shipment_request(
         ShipmentRequest(**package_shipment_with_package_preset_data))
     self.assertEqual(request.serialize(), ShipmentRequestWithPresetXML)
Example #7
0
 def setUp(self):
     self.maxDiff = None
     self.ShipmentRequest = ShipmentRequest(**package_shipment_data)
Example #8
0
 def setUp(self):
     self.maxDiff = None
     self.ShipmentRequest = ShipmentRequest(**freight_shipment_data)