diff --git a/examples/track_shipment.py b/examples/track_shipment.py index 04f0faf..d26bf87 100755 --- a/examples/track_shipment.py +++ b/examples/track_shipment.py @@ -10,21 +10,54 @@ logging.basicConfig(level=logging.INFO) # NOTE: TRACKING IS VERY ERRATIC ON THE TEST SERVERS. YOU MAY NEED TO USE -# PRODUCTION KEYS/PASSWORDS/ACCOUNT #. +# PRODUCTION KEYS/PASSWORDS/ACCOUNT #. THE TEST SERVERS OFTEN RETURN A NOT FOUND ERROR. +# WHEN TESTING IN PRODUCTION, GIVE SOME TIME FOR THE TRACKING TO PROPAGATE. + + # We're using the FedexConfig object from example_config.py in this dir. -track = FedexTrackRequest(CONFIG_OBJ) -track.TrackPackageIdentifier.Type = 'TRACKING_NUMBER_OR_DOORTAG' -track.TrackPackageIdentifier.Value = '798114182456' +customer_transaction_id = "*** TrackService Request v10 using Python ***" # Optional transaction_id +track = FedexTrackRequest(CONFIG_OBJ, customer_transaction_id=customer_transaction_id) + +# Track by Tracking Number +track.SelectionDetails.PackageIdentifier.Type = 'TRACKING_NUMBER_OR_DOORTAG' +track.SelectionDetails.PackageIdentifier.Value = '781820562774' + +# FedEx operating company or delete +del track.SelectionDetails.OperatingCompany + +# Can optionally set the TrackingNumberUniqueIdentifier +# del track.SelectionDetails.TrackingNumberUniqueIdentifier + +# If you'd like to see some documentation on the ship service WSDL, un-comment +# this line. (Spammy). +#print track.client + +# Un-comment this to see your complete, ready-to-send request as it stands +# before it is actually sent. This is useful for seeing what values you can +# change. +#print track.SelectionDetails +#print track.ClientDetail +#print track.TransactionDetail + # Fires off the request, sets the 'response' attribute on the object. track.send_request() # See the response printed out. print track.response +#print rate_request.client.last_received() + +# See the request printed out. +#print track.client.last_sent() # Look through the matches (there should only be one for a tracking number # query), and show a few details about each shipment. print "== Results ==" -for match in track.response.TrackDetails: +#print track.response +for match in track.response.CompletedTrackDetails[0].TrackDetails: print "Tracking #:", match.TrackingNumber - print "Status:", match.StatusDescription \ No newline at end of file + print "Tracking # UniqueID:", match.TrackingNumberUniqueIdentifier + print "Status:", match.StatusDetail.Description + print "Status AncillaryDetails Reason:", match.StatusDetail.AncillaryDetails[-1].Reason + print "Status AncillaryDetails Description:", match.StatusDetail.AncillaryDetails[-1].ReasonDescription + print "Commit Message:", match.ServiceCommitMessage diff --git a/fedex/services/track_service.py b/fedex/services/track_service.py index cc0301a..e9158b0 100644 --- a/fedex/services/track_service.py +++ b/fedex/services/track_service.py @@ -45,19 +45,16 @@ def __init__(self, config_obj, *args, **kwargs): # Holds version info for the VersionId SOAP object. self._version_info = { 'service_id': 'trck', - 'major': '5', + 'major': '10', 'intermediate': '0', 'minor': '0' } - self.TrackPackageIdentifier = None + self.SelectionDetails = None """@ivar: Holds the TrackPackageIdentifier WSDL object.""" - - self.TrackingNumberUniqueIdentifier = kwargs.pop('tracking_number_unique_id', None) - - """@ivar: Holds the TrackingNumberUniqueIdentifier WSDL object.""" + # Call the parent FedexBaseService class for basic setup work. super(FedexTrackRequest, self).__init__( - self._config_obj, 'TrackService_v5.wsdl', *args, **kwargs) + self._config_obj, 'TrackService_v10.wsdl', *args, **kwargs) self.IncludeDetailedScans = False def _prepare_wsdl_objects(self): @@ -66,10 +63,21 @@ def _prepare_wsdl_objects(self): number or a few different things as per the Fedex spec. """ - self.TrackPackageIdentifier = self.client.factory.create('TrackPackageIdentifier') + self.SelectionDetails = self.client.factory.create('TrackSelectionDetail') + + # Default to Fedex + self.SelectionDetails.CarrierCode = 'FDXE' + + TrackPackageIdentifier = self.client.factory.create('TrackPackageIdentifier') + # Default to tracking number. - self.TrackPackageIdentifier.Type = 'TRACKING_NUMBER_OR_DOORTAG' - + TrackPackageIdentifier.Type = 'TRACKING_NUMBER_OR_DOORTAG' + + self.SelectionDetails.PackageIdentifier = TrackPackageIdentifier + + # Set Default as None. 'INCLUDE_DETAILED_SCANS' or None + self.TrackRequestProcessingOptionType = None + def _check_response_for_request_errors(self): """ Checks the response to see if there were any errors specific to @@ -99,6 +107,6 @@ def _assemble_and_send_request(self): ClientDetail=self.ClientDetail, TransactionDetail=self.TransactionDetail, Version=self.VersionId, - IncludeDetailedScans=self.IncludeDetailedScans, - PackageIdentifier=self.TrackPackageIdentifier, - TrackingNumberUniqueIdentifier = self.TrackingNumberUniqueIdentifier) + SelectionDetails=self.SelectionDetails, + TrackRequestProcessingOptionType=self.TrackRequestProcessingOptionType) + diff --git a/tests/t_track_service.py b/tests/t_track_service.py deleted file mode 100644 index f58575c..0000000 --- a/tests/t_track_service.py +++ /dev/null @@ -1,28 +0,0 @@ -""" -Test module for the Fedex ShipService WSDL. -""" -import unittest -from fedex.services.track_service import FedexTrackRequest -import common - -# Common global config object for testing. -CONFIG_OBJ = common.get_test_config() - -class TrackServiceTests(unittest.TestCase): - """ - These tests verify that the shipping service WSDL is in good shape. - """ - def test_track(self): - """ - Test shipment tracking. Query for a tracking number and make sure the - first (and hopefully only) result matches up. - """ - track = FedexTrackRequest(CONFIG_OBJ) - track.TrackPackageIdentifier.Type = 'TRACKING_NUMBER_OR_DOORTAG' - track.TrackPackageIdentifier.Value = '798114182456' - track.send_request() - - for match in track.response.TrackDetails: - # This should be the same tracking number on the response that we - # asked for in the request. - self.assertEqual(match.TrackingNumber, tracking_num) diff --git a/tests/test_track_service.py b/tests/test_track_service.py new file mode 100644 index 0000000..5cfd67d --- /dev/null +++ b/tests/test_track_service.py @@ -0,0 +1,48 @@ +""" +Test module for the Fedex ShipService WSDL. +""" + +import unittest + +import sys +sys.path.insert(0, '..') +from fedex.services.track_service import FedexTrackRequest + +# Common global config object for testing. +from common import get_test_config +CONFIG_OBJ = get_test_config() + + +class TrackServiceTests(unittest.TestCase): + """ + These tests verify that the shipping service WSDL is in good shape. + """ + def test_track(self): + # Test shipment tracking. Query for a tracking number and make sure the + # first (and hopefully only) result matches up. + + tracking_num = '781820562774' + + track = FedexTrackRequest(CONFIG_OBJ) + + # Track by Tracking Number + track.SelectionDetails.PackageIdentifier.Type = 'TRACKING_NUMBER_OR_DOORTAG' + track.SelectionDetails.PackageIdentifier.Value = tracking_num + + # FedEx operating company or delete + del track.SelectionDetails.OperatingCompany + + track.send_request() + + assert track.response + + # Uncomment below if testing in production with a valid tracking number + # for match in track.response.CompletedTrackDetails[0].TrackDetails: + # # This should be the same tracking number on the response that we + # # asked for in the request. + # assert match.TrackingNumber == tracking_num + + +if __name__ == "__main__": + + unittest.main()