From f0b344e5cfe35c84394d10bf567bdd5cf448395d Mon Sep 17 00:00:00 2001 From: radlws Date: Tue, 1 Dec 2015 11:45:12 -0500 Subject: [PATCH] added package movement v4 with tests --- examples/postal_inquiry.py | 18 ++++++++- fedex/services/package_movement.py | 52 ++++++++++++++------------ tests/test_package_movement_service.py | 35 +++++++++++++++++ 3 files changed, 80 insertions(+), 25 deletions(-) create mode 100644 tests/test_package_movement_service.py diff --git a/examples/postal_inquiry.py b/examples/postal_inquiry.py index 6de94cc..d4aa459 100755 --- a/examples/postal_inquiry.py +++ b/examples/postal_inquiry.py @@ -15,8 +15,24 @@ inquiry.PostalCode = '29631' inquiry.CountryCode = 'US' +# If you'd like to see some documentation on the ship service WSDL, un-comment +# this line. (Spammy). +#print inquiry.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 inquiry.CarrierCode +#print inquiry.ClientDetail +#print inquiry.TransactionDetail + # Fires off the request, sets the 'response' attribute on the object. inquiry.send_request() # See the response printed out. -print inquiry.response \ No newline at end of file +print inquiry.response +#print inquiry.client.last_received() + +# See the response printed out. +#print inquiry.client.last_sent() + diff --git a/fedex/services/package_movement.py b/fedex/services/package_movement.py index c8d7e00..eb0faf9 100755 --- a/fedex/services/package_movement.py +++ b/fedex/services/package_movement.py @@ -5,7 +5,8 @@ codes. Defined by the PackageMovementInformationService WSDL file. """ import logging -from .. base_service import FedexBaseService, FedexError +from ..base_service import FedexBaseService, FedexError + class FedexPostalCodeNotFound(FedexError): """ @@ -13,17 +14,20 @@ class FedexPostalCodeNotFound(FedexError): """ pass + class FedexInvalidPostalCodeFormat(FedexError): """ Exception: Sent when the postal code is invalid """ pass + class PostalCodeInquiryRequest(FedexBaseService): """ The postal code inquiry enables customers to validate postal codes and service commitments. """ + def __init__(self, config_obj, postal_code=None, country_code=None, *args, **kwargs): """ Sets up an inquiry request. The optional keyword args @@ -35,19 +39,17 @@ def __init__(self, config_obj, postal_code=None, country_code=None, *args, **kwa @param country_code: ISO country code to which the postal code belongs to. """ self._config_obj = config_obj - + # Holds version info for the VersionId SOAP object. self._version_info = {'service_id': 'pmis', 'major': '4', - 'intermediate': '0', 'minor': '0'} + 'intermediate': '0', 'minor': '0'} self.PostalCode = postal_code self.CountryCode = country_code - - + # Call the parent FedexBaseService class for basic setup work. super(PostalCodeInquiryRequest, self).__init__(self._config_obj, - 'PackageMovementInformationService_v4.wsdl', - *args, **kwargs) - + 'PackageMovementInformationService_v4.wsdl', + *args, **kwargs) def _check_response_for_request_errors(self): """ @@ -59,19 +61,22 @@ def _check_response_for_request_errors(self): if notification.Severity == "ERROR": if "Postal Code Not Found" in notification.Message: raise FedexPostalCodeNotFound(notification.Code, - notification.Message) + notification.Message) elif "Invalid Postal Code Format" in self.response.Notifications: raise FedexInvalidPostalCodeFormat(notification.Code, - notification.Message) + notification.Message) else: raise FedexError(notification.Code, notification.Message) - + def _prepare_wsdl_objects(self): - pass - - + """ + Preps the WSDL data structures for the user. + """ + + self.CarrierCode = 'FDXE' + def _assemble_and_send_request(self): """ Fires off the Fedex request. @@ -80,21 +85,20 @@ def _assemble_and_send_request(self): ON FedexBaseService AND IS INHERITED. """ client = self.client - - + # We get an exception like this when specifying an IntegratorId: # suds.TypeNotFound: Type not found: 'IntegratorId' # Setting it to None does not seem to appease it. - + del self.ClientDetail.IntegratorId - + # Fire off the query. response = client.service.postalCodeInquiry(WebAuthenticationDetail=self.WebAuthenticationDetail, - ClientDetail=self.ClientDetail, - TransactionDetail=self.TransactionDetail, - Version=self.VersionId, - PostalCode = self.PostalCode, - CountryCode = self.CountryCode) + ClientDetail=self.ClientDetail, + TransactionDetail=self.TransactionDetail, + Version=self.VersionId, + PostalCode=self.PostalCode, + CountryCode=self.CountryCode, + CarrierCode=self.CarrierCode) return response - \ No newline at end of file diff --git a/tests/test_package_movement_service.py b/tests/test_package_movement_service.py new file mode 100644 index 0000000..41bb0a0 --- /dev/null +++ b/tests/test_package_movement_service.py @@ -0,0 +1,35 @@ +""" +Test module for the Fedex PackageMovementInformationService WSDL. +""" + +import unittest + +import sys +sys.path.insert(0, '..') +from fedex.services.package_movement import PostalCodeInquiryRequest + +# Common global config object for testing. +from common import get_test_config +CONFIG_OBJ = get_test_config() + + +class PackageMovementServiceTests(unittest.TestCase): + """ + These tests verify that the package movement service WSDL is in good shape. + """ + def test_postal_inquiry(self): + + inquiry = PostalCodeInquiryRequest(CONFIG_OBJ) + inquiry.PostalCode = '29631' + inquiry.CountryCode = 'US' + + inquiry.send_request() + + assert inquiry.response + assert inquiry.response.HighestSeverity == 'SUCCESS' + + + +if __name__ == "__main__": + + unittest.main()