예제 #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)
예제 #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)
예제 #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)
예제 #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)
예제 #5
0
 def setUp(self):
     self.maxDiff = None
     self.ShipmentRequest = ShipmentRequest(**shipment_data)
     self.ShipmentCancelRequest = ShipmentCancelRequest(
         **shipment_cancel_data)
예제 #6
0
 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)
예제 #7
0
 def setUp(self):
     self.maxDiff = None
     self.ShipmentRequest = ShipmentRequest(**package_shipment_data)
예제 #8
0
 def setUp(self):
     self.maxDiff = None
     self.ShipmentRequest = ShipmentRequest(**freight_shipment_data)