Skip to content

Commit 89a0d84

Browse files
committed
added rate service v18, added test
1 parent a8dd4cf commit 89a0d84

File tree

4 files changed

+103
-24
lines changed

4 files changed

+103
-24
lines changed

examples/freight_rate_request.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,31 @@
2929

3030
rate_request.RequestedShipment.FreightShipmentDetail.FedExFreightAccountNumber = CONFIG_OBJ.freight_account_number
3131

32-
rate_request.RequestedShipment.Shipper.Address.PostalCode = '72601'
33-
rate_request.RequestedShipment.Shipper.Address.CountryCode = 'US'
32+
33+
# Shipper
34+
rate_request.RequestedShipment.Shipper.AccountNumber = CONFIG_OBJ.freight_account_number
35+
rate_request.RequestedShipment.Shipper.Contact.PersonName = 'Sender Name'
36+
rate_request.RequestedShipment.Shipper.Contact.CompanyName = 'Some Company'
37+
rate_request.RequestedShipment.Shipper.Contact.PhoneNumber = '9012638716'
38+
rate_request.RequestedShipment.Shipper.Address.StreetLines = ['2000 Freight LTL Testing']
3439
rate_request.RequestedShipment.Shipper.Address.City = 'Harrison'
3540
rate_request.RequestedShipment.Shipper.Address.StateOrProvinceCode = 'AR'
41+
rate_request.RequestedShipment.Shipper.Address.PostalCode = '72601'
42+
rate_request.RequestedShipment.Shipper.Address.CountryCode = 'US'
3643
rate_request.RequestedShipment.Shipper.Address.Residential = False
44+
45+
# Recipient
46+
rate_request.RequestedShipment.Recipient.Address.City = 'Harrison'
47+
rate_request.RequestedShipment.Recipient.Address.StateOrProvinceCode = 'AR'
3748
rate_request.RequestedShipment.Recipient.Address.PostalCode = '72601'
3849
rate_request.RequestedShipment.Recipient.Address.CountryCode = 'US'
39-
rate_request.RequestedShipment.Recipient.Address.StateOrProvinceCode = 'AR'
40-
rate_request.RequestedShipment.Recipient.Address.City = 'Harrison'
50+
rate_request.RequestedShipment.Shipper.Address.Residential = False
51+
52+
# Payment
53+
payment = rate_request.create_wsdl_object_of_type('Payment')
54+
payment.PaymentType = "SENDER"
55+
payment.Payor.ResponsibleParty = rate_request.RequestedShipment.Shipper
56+
rate_request.RequestedShipment.ShippingChargesPayment = payment
4157

4258
#include estimated duties and taxes in rate quote, can be ALL or NONE
4359
rate_request.RequestedShipment.EdtRequestType = 'NONE'
@@ -92,11 +108,13 @@
92108

93109
# Fires off the request, sets the 'response' attribute on the object.
94110
rate_request.send_request()
111+
#print rate_request.client.last_received()
95112

96113
# This will show the reply to your rate_request being sent. You can access the
97114
# attributes through the response attribute on the request object. This is
98115
# good to un-comment to see the variables returned by the FedEx reply.
99-
#print rate_request.response
116+
print rate_request.response
117+
#print rate_request.client.last_sent()
100118

101119
# Here is the overall end result of the query.
102120
print "HighestSeverity:", rate_request.response.HighestSeverity

examples/rate_request.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
# Set this to the INFO level to see the response from Fedex printed in stdout.
1616
logging.basicConfig(level=logging.INFO)
1717

18+
1819
# This is the object that will be handling our tracking request.
1920
# We're using the FedexConfig object from example_config.py in this dir.
20-
rate_request = FedexRateServiceRequest(CONFIG_OBJ)
21+
customer_transaction_id = "*** RateService Request v18 using Python ***" # Optional transaction_id
22+
rate_request = FedexRateServiceRequest(CONFIG_OBJ, customer_transaction_id=customer_transaction_id)
2123

2224
# If you wish to have transit data returned with your request you
2325
# need to uncomment the following
@@ -94,6 +96,11 @@
9496
# attributes through the response attribute on the request object. This is
9597
# good to un-comment to see the variables returned by the FedEx reply.
9698
#print rate_request.response
99+
#print rate_request.client.last_received()
100+
101+
# See the response printed out.
102+
#print rate_request.client.last_sent()
103+
97104

98105
# Here is the overall end result of the query.
99106
print "HighestSeverity:", rate_request.response.HighestSeverity
@@ -107,5 +114,5 @@
107114

108115
for rate_detail in service.RatedShipmentDetails:
109116
print "%s: Net FedEx Charge %s %s" % (service.ServiceType, rate_detail.ShipmentRateDetail.TotalNetFedExCharge.Currency,
110-
rate_detail.ShipmentRateDetail.TotalNetFedExCharge.Amount)
117+
rate_detail.ShipmentRateDetail.TotalNetFedExCharge.Amount)
111118

fedex/services/rate_service.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"""
88

99
from datetime import datetime
10-
from .. base_service import FedexBaseService
10+
from ..base_service import FedexBaseService
1111

1212

1313
class FedexRateServiceRequest(FedexBaseService):
@@ -27,19 +27,19 @@ def __init__(self, config_obj, *args, **kwargs):
2727
"""
2828

2929
self._config_obj = config_obj
30-
30+
3131
# Holds version info for the VersionId SOAP object.
32-
self._version_info = {'service_id': 'crs', 'major': '16',
33-
'intermediate': '0', 'minor': '0'}
34-
32+
self._version_info = {'service_id': 'crs', 'major': '18',
33+
'intermediate': '0', 'minor': '0'}
34+
3535
self.RequestedShipment = None
3636
"""@ivar: Holds the RequestedShipment WSDL object."""
3737
# Call the parent FedexBaseService class for basic setup work.
38-
super(FedexRateServiceRequest, self).__init__(self._config_obj,
39-
'RateService_v16.wsdl',
40-
*args, **kwargs)
38+
super(FedexRateServiceRequest, self).__init__(self._config_obj,
39+
'RateService_v18.wsdl',
40+
*args, **kwargs)
4141
self.ClientDetail.Region = config_obj.express_region_code
42-
42+
4343
def _prepare_wsdl_objects(self):
4444
"""
4545
This is the data that will be used to create your shipment. Create
@@ -52,7 +52,7 @@ def _prepare_wsdl_objects(self):
5252
# This is the primary data structure for processShipment requests.
5353
self.RequestedShipment = self.client.factory.create('RequestedShipment')
5454
self.RequestedShipment.ShipTimestamp = datetime.now()
55-
55+
5656
TotalWeight = self.client.factory.create('Weight')
5757
# Start at nothing.
5858
TotalWeight.Value = 0.0
@@ -61,33 +61,33 @@ def _prepare_wsdl_objects(self):
6161
# This is the total weight of the entire shipment. Shipments may
6262
# contain more than one package.
6363
self.RequestedShipment.TotalWeight = TotalWeight
64-
64+
6565
# This is the top level data structure for Shipper information.
6666
ShipperParty = self.client.factory.create('Party')
6767
ShipperParty.Address = self.client.factory.create('Address')
6868
ShipperParty.Contact = self.client.factory.create('Contact')
69-
69+
7070
# Link the ShipperParty to our master data structure.
7171
self.RequestedShipment.Shipper = ShipperParty
7272

7373
# This is the top level data structure for Recipient information.
7474
RecipientParty = self.client.factory.create('Party')
7575
RecipientParty.Contact = self.client.factory.create('Contact')
7676
RecipientParty.Address = self.client.factory.create('Address')
77-
77+
7878
# Link the RecipientParty object to our master data structure.
7979
self.RequestedShipment.Recipient = RecipientParty
80-
80+
8181
Payor = self.client.factory.create('Payor')
8282
# Grab the account number from the FedexConfig object by default.
8383
Payor.AccountNumber = self._config_obj.account_number
8484
# Assume US.
8585
Payor.CountryCode = 'US'
86-
86+
8787
# Start with no packages, user must add them.
8888
self.RequestedShipment.PackageCount = 0
8989
self.RequestedShipment.RequestedPackageLineItems = []
90-
90+
9191
# This is good to review if you'd like to see what the data structure
9292
# looks like.
9393
self.logger.debug(self.RequestedShipment)
@@ -108,7 +108,7 @@ def _assemble_and_send_request(self):
108108
Version=self.VersionId,
109109
RequestedShipment=self.RequestedShipment,
110110
ReturnTransitAndCommit=self.ReturnTransitAndCommit)
111-
111+
112112
def add_package(self, package_item):
113113
"""
114114
Adds a package to the ship request.

tests/test_rate_service.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""
2+
Test module for the Fedex RateService WSDL.
3+
"""
4+
5+
import unittest
6+
7+
import sys
8+
sys.path.insert(0, '..')
9+
from fedex.services.rate_service import FedexRateServiceRequest
10+
11+
# Common global config object for testing.
12+
from common import get_test_config
13+
CONFIG_OBJ = get_test_config()
14+
15+
16+
class RateServiceTests(unittest.TestCase):
17+
"""
18+
These tests verify that the rate service WSDL is in good shape.
19+
"""
20+
def test_rate(self):
21+
22+
rate = FedexRateServiceRequest(CONFIG_OBJ)
23+
24+
rate.RequestedShipment.DropoffType = 'REGULAR_PICKUP'
25+
rate.RequestedShipment.ServiceType = 'FEDEX_GROUND'
26+
rate.RequestedShipment.PackagingType = 'YOUR_PACKAGING'
27+
28+
rate.RequestedShipment.Shipper.Address.StateOrProvinceCode = 'SC'
29+
rate.RequestedShipment.Shipper.Address.PostalCode = '29631'
30+
rate.RequestedShipment.Shipper.Address.CountryCode = 'US'
31+
32+
rate.RequestedShipment.Recipient.Address.StateOrProvinceCode = 'NC'
33+
rate.RequestedShipment.Recipient.Address.PostalCode = '27577'
34+
rate.RequestedShipment.Recipient.Address.CountryCode = 'US'
35+
36+
rate.RequestedShipment.EdtRequestType = 'NONE'
37+
rate.RequestedShipment.ShippingChargesPayment.PaymentType = 'SENDER'
38+
39+
package1_weight = rate.create_wsdl_object_of_type('Weight')
40+
package1_weight.Value = 1.0
41+
package1_weight.Units = "LB"
42+
package1 = rate.create_wsdl_object_of_type('RequestedPackageLineItem')
43+
package1.Weight = package1_weight
44+
package1.PhysicalPackaging = 'BOX'
45+
package1.GroupPackageCount = 1
46+
rate.add_package(package1)
47+
48+
rate.send_request()
49+
50+
assert rate.response.HighestSeverity == 'SUCCESS'
51+
52+
if __name__ == "__main__":
53+
54+
unittest.main()

0 commit comments

Comments
 (0)