Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion examples/postal_inquiry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
print inquiry.response
#print inquiry.client.last_received()

# See the response printed out.
#print inquiry.client.last_sent()

52 changes: 28 additions & 24 deletions fedex/services/package_movement.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,29 @@
codes. Defined by the PackageMovementInformationService WSDL file.
"""
import logging
from .. base_service import FedexBaseService, FedexError
from ..base_service import FedexBaseService, FedexError


class FedexPostalCodeNotFound(FedexError):
"""
Exception: Sent when the postalcode is missing.
"""
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
Expand All @@ -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):
"""
Expand All @@ -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.
Expand All @@ -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

35 changes: 35 additions & 0 deletions tests/test_package_movement_service.py
Original file line number Diff line number Diff line change
@@ -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()