Exemple #1
0
    def test_create_rate(self, http_mock):
        Rating.fetch(self.RateRequest).from_(gateway)

        url = http_mock.call_args[1]["url"]
        self.assertEqual(
            url,
            f"{gateway.settings.server_url}/EWS/V2/Estimating/EstimatingService.asmx",
        )
Exemple #2
0
    def test_get_rates(self):
        with patch("purplship.mappers.[carrier].proxy.http") as mock:
            mock.return_value = "<a></a>"
            Rating.fetch(self.RateRequest).from_(gateway)

            self.assertEqual(
                mock.call_args[1]["url"],
                f"{gateway.settings.server_url}",
            )
Exemple #3
0
    def test_get_rates(self):
        with patch("purplship.mappers.canpar.proxy.http") as mock:
            mock.return_value = "<a></a>"
            Rating.fetch(self.RateRequest).from_(gateway)

            self.assertEqual(
                mock.call_args[1]["url"],
                f"{gateway.settings.server_url}/CanparRatingService.CanparRatingServiceHttpSoap12Endpoint/",
            )
            self.assertEqual(mock.call_args[1]["headers"]["soapaction"],
                             "urn:rateShipment")
Exemple #4
0
    def test_get_rates(self):
        with patch("purplship.mappers.ics_courier.proxy.http") as mock:
            mock.return_value = "<a></a>"
            Rating.fetch(self.RateRequest).from_(gateway)

            self.assertEqual(
                mock.call_args[1]["url"],
                gateway.settings.server_url,
            )
            self.assertEqual(mock.call_args[1]["headers"]["soapaction"],
                             "http://www.icscourier.ca/GetEstimatedCharges")
 def test_parse_rate_response_errors(self):
     with patch("purplship.mappers.usps.proxy.http") as mock:
         mock.return_value = ERROR_XML
         parsed_response = Rating.fetch(
             self.RateRequest).from_(gateway).parse()
         self.assertEqual(DP.to_dict(parsed_response),
                          DP.to_dict(PARSED_ERRORS))
 def test_parse_rate_missing_args_error(self):
     with patch("purplship.mappers.canadapost.proxy.http") as mock:
         mock.return_value = QuoteMissingArgsError
         parsed_response = Rating.fetch(
             self.RateRequest).from_(gateway).parse()
         self.assertEqual(DP.to_dict(parsed_response),
                          DP.to_dict(ParsedQuoteMissingArgsError))
    def test_create_rate_request_with_package_preset_missing_weight(self, _):
        processing_error = (Rating.fetch(
            RateRequest(
                **RateWithPresetMissingWeightPayload)).from_(gateway).parse())

        self.assertEqual(DP.to_dict(processing_error),
                         DP.to_dict(ProcessingError))
Exemple #8
0
 def test_parse_rate_vol_weight_higher_response(self):
     with patch("purplship.mappers.dhl_express.proxy.http") as mock:
         mock.return_value = RateVolWeightHigher
         parsed_response = Rating.fetch(self.RateRequest).from_(gateway).parse()
         self.assertEqual(
             DP.to_dict(parsed_response), DP.to_dict(ParsedRateVolWeightHigher)
         )
 def test_parse_rate_error(self):
     with patch("purplship.mappers.ups.proxy.http") as mock:
         mock.return_value = RateteParsingErrorXML
         parsed_response = Rating.fetch(
             self.RateRequest).from_(gateway).parse()
         self.assertEqual(DP.to_dict(parsed_response),
                          DP.to_dict(ParsedRateteParsingError))
Exemple #10
0
    def test_parse_rate_response(self):
        with patch("purplship.mappers.canpar.proxy.http") as mock:
            mock.return_value = RateResponseXml
            parsed_response = Rating.fetch(
                self.RateRequest).from_(gateway).parse()

            self.assertEqual(DP.to_dict(parsed_response),
                             DP.to_dict(ParsedQuoteResponse))
Exemple #11
0
    def test_parse_rate_response(self):
        with patch("purplship.mappers.usps_international.proxy.http") as mock:
            mock.return_value = RATE_RESPONSE_XML
            parsed_response = Rating.fetch(
                self.RateRequest).from_(gateway).parse()

            self.assertEqual(DP.to_dict(parsed_response),
                             DP.to_dict(PARSED_RATE_RESPONSE))
Exemple #12
0
    def test_get_rate_invalid_origin(self):
        us_account_gateway = purplship.gateway["dhl_express"].create(
            dict(
                site_id="site_id",
                password="******",
                carrier_id="carrier_id",
                account_number="123456789",
                id="testing_id",
                account_country_code="US",
            ))
        parsed_response = (Rating.fetch(
            self.RateRequest).from_(us_account_gateway).parse())

        self.assertEqual(
            DP.to_dict(parsed_response),
            DP.to_dict(ParsedInvalidOriginResponse),
        )
Exemple #13
0
    def test_get_rate_invalid_destination(self):
        ca_account_gateway = purplship.gateway["dhl_express"].create(
            dict(
                site_id="site_id",
                password="******",
                carrier_id="carrier_id",
                account_number="123456789",
                id="testing_id",
                account_country_code="CA",
            ))
        invalid_destination_request = RateRequest(
            **{
                **RatePayload,
                "recipient": {
                    **RatePayload["recipient"], "country_code": "CA"
                },
            })
        parsed_response = (Rating.fetch(invalid_destination_request).from_(
            ca_account_gateway).parse())

        self.assertEqual(
            DP.to_dict(parsed_response),
            DP.to_dict(ParsedInvalidDestinationResponse),
        )
Exemple #14
0
    def test_get_rates(self, http_mock):
        Rating.fetch(self.RateRequest).from_(gateway)

        url = http_mock.call_args[1]["url"]
        self.assertEqual(url,
                         f"{gateway.proxy.settings.server_url}/rs/ship/price")
Exemple #15
0
    def test_package_get_quotes(self, http_mock):
        Rating.fetch(self.RateRequest).from_(gateway)

        url = http_mock.call_args[1]["url"]
        self.assertEqual(url, f"{gateway.settings.server_url}/Rate")