Skip to content

Commit f0b344e

Browse files
committed
added package movement v4 with tests
1 parent a8dd4cf commit f0b344e

File tree

3 files changed

+80
-25
lines changed

3 files changed

+80
-25
lines changed

examples/postal_inquiry.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,24 @@
1515
inquiry.PostalCode = '29631'
1616
inquiry.CountryCode = 'US'
1717

18+
# If you'd like to see some documentation on the ship service WSDL, un-comment
19+
# this line. (Spammy).
20+
#print inquiry.client
21+
22+
# Un-comment this to see your complete, ready-to-send request as it stands
23+
# before it is actually sent. This is useful for seeing what values you can
24+
# change.
25+
#print inquiry.CarrierCode
26+
#print inquiry.ClientDetail
27+
#print inquiry.TransactionDetail
28+
1829
# Fires off the request, sets the 'response' attribute on the object.
1930
inquiry.send_request()
2031

2132
# See the response printed out.
22-
print inquiry.response
33+
print inquiry.response
34+
#print inquiry.client.last_received()
35+
36+
# See the response printed out.
37+
#print inquiry.client.last_sent()
38+

fedex/services/package_movement.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,29 @@
55
codes. Defined by the PackageMovementInformationService WSDL file.
66
"""
77
import logging
8-
from .. base_service import FedexBaseService, FedexError
8+
from ..base_service import FedexBaseService, FedexError
9+
910

1011
class FedexPostalCodeNotFound(FedexError):
1112
"""
1213
Exception: Sent when the postalcode is missing.
1314
"""
1415
pass
1516

17+
1618
class FedexInvalidPostalCodeFormat(FedexError):
1719
"""
1820
Exception: Sent when the postal code is invalid
1921
"""
2022
pass
2123

24+
2225
class PostalCodeInquiryRequest(FedexBaseService):
2326
"""
2427
The postal code inquiry enables customers to validate postal codes
2528
and service commitments.
2629
"""
30+
2731
def __init__(self, config_obj, postal_code=None, country_code=None, *args, **kwargs):
2832
"""
2933
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
3539
@param country_code: ISO country code to which the postal code belongs to.
3640
"""
3741
self._config_obj = config_obj
38-
42+
3943
# Holds version info for the VersionId SOAP object.
4044
self._version_info = {'service_id': 'pmis', 'major': '4',
41-
'intermediate': '0', 'minor': '0'}
45+
'intermediate': '0', 'minor': '0'}
4246
self.PostalCode = postal_code
4347
self.CountryCode = country_code
44-
45-
48+
4649
# Call the parent FedexBaseService class for basic setup work.
4750
super(PostalCodeInquiryRequest, self).__init__(self._config_obj,
48-
'PackageMovementInformationService_v4.wsdl',
49-
*args, **kwargs)
50-
51+
'PackageMovementInformationService_v4.wsdl',
52+
*args, **kwargs)
5153

5254
def _check_response_for_request_errors(self):
5355
"""
@@ -59,19 +61,22 @@ def _check_response_for_request_errors(self):
5961
if notification.Severity == "ERROR":
6062
if "Postal Code Not Found" in notification.Message:
6163
raise FedexPostalCodeNotFound(notification.Code,
62-
notification.Message)
64+
notification.Message)
6365

6466
elif "Invalid Postal Code Format" in self.response.Notifications:
6567
raise FedexInvalidPostalCodeFormat(notification.Code,
66-
notification.Message)
68+
notification.Message)
6769
else:
6870
raise FedexError(notification.Code,
6971
notification.Message)
70-
72+
7173
def _prepare_wsdl_objects(self):
72-
pass
73-
74-
74+
"""
75+
Preps the WSDL data structures for the user.
76+
"""
77+
78+
self.CarrierCode = 'FDXE'
79+
7580
def _assemble_and_send_request(self):
7681
"""
7782
Fires off the Fedex request.
@@ -80,21 +85,20 @@ def _assemble_and_send_request(self):
8085
ON FedexBaseService AND IS INHERITED.
8186
"""
8287
client = self.client
83-
84-
88+
8589
# We get an exception like this when specifying an IntegratorId:
8690
# suds.TypeNotFound: Type not found: 'IntegratorId'
8791
# Setting it to None does not seem to appease it.
88-
92+
8993
del self.ClientDetail.IntegratorId
90-
94+
9195
# Fire off the query.
9296
response = client.service.postalCodeInquiry(WebAuthenticationDetail=self.WebAuthenticationDetail,
93-
ClientDetail=self.ClientDetail,
94-
TransactionDetail=self.TransactionDetail,
95-
Version=self.VersionId,
96-
PostalCode = self.PostalCode,
97-
CountryCode = self.CountryCode)
97+
ClientDetail=self.ClientDetail,
98+
TransactionDetail=self.TransactionDetail,
99+
Version=self.VersionId,
100+
PostalCode=self.PostalCode,
101+
CountryCode=self.CountryCode,
102+
CarrierCode=self.CarrierCode)
98103

99104
return response
100-
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
Test module for the Fedex PackageMovementInformationService WSDL.
3+
"""
4+
5+
import unittest
6+
7+
import sys
8+
sys.path.insert(0, '..')
9+
from fedex.services.package_movement import PostalCodeInquiryRequest
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 PackageMovementServiceTests(unittest.TestCase):
17+
"""
18+
These tests verify that the package movement service WSDL is in good shape.
19+
"""
20+
def test_postal_inquiry(self):
21+
22+
inquiry = PostalCodeInquiryRequest(CONFIG_OBJ)
23+
inquiry.PostalCode = '29631'
24+
inquiry.CountryCode = 'US'
25+
26+
inquiry.send_request()
27+
28+
assert inquiry.response
29+
assert inquiry.response.HighestSeverity == 'SUCCESS'
30+
31+
32+
33+
if __name__ == "__main__":
34+
35+
unittest.main()

0 commit comments

Comments
 (0)