Exemplo n.º 1
0
 def setUp(self):
     self.api = endicia.Endicia(EndiciaTestConfig, debug=True)
     self.shipper = Address('Adobe',
                            "345 Park Avenue",
                            'San Jose',
                            'CA',
                            95110,
                            'US',
                            phone='5122901212',
                            email='*****@*****.**')
     self.recipient = Address('Apple',
                              "1 Infinite Loop",
                              'Cupertino',
                              'CA',
                              95014,
                              'US',
                              phone='5122901212',
                              email='*****@*****.**')
     self.intl_recipient = Address('Apple Canada',
                                   "7495 Birchmount Road",
                                   'Markham',
                                   'ON',
                                   "L3R 5G2",
                                   'CA',
                                   phone='9055135800',
                                   email='*****@*****.**')
     self.package = endicia.Package(endicia.Package.shipment_types[0], 3,
                                    endicia.Package.shapes[1], 10, 10, 10)
Exemplo n.º 2
0
def TestFedexGroundCertification():
    test_cases = [
        (
            Address('TC #4', '20 FedEx Parkway', 'Kansas City', 'MO', 64112, 'US', address2='2nd Floor Suite 2001', phone=5152961616, is_residence=False),
            fedex.Package(20.0 * 16, 12, 12, 12),
            fedex.SERVICES[0],
            fedex.PACKAGES[-1],
            False, # Email alert
            False, # Evening
        ),
        (
            Address('TC #20', '456 Roswell Rd', 'Atlanta', 'GA', 30328, 'US', phone=5152961616),
            fedex.Package(20.0 * 16, 5, 5, 108),
            fedex.SERVICES[1],
            fedex.PACKAGES[-1],
            False, # Email alert
            False, # Evening
        ),
        (
            Address('TC #21', '987 Main St', 'Boston', 'MA', '02129', 'US', phone=5152961616),
            fedex.Package(20.0 * 16, 5, 5, 108, require_signature=True),
            fedex.SERVICES[1],
            fedex.PACKAGES[-1],
            False, # Email alert
            False, # Evening
        ),
        (
            Address('TC #23', '321 Jay St', 'New York', 'NY', '11201', 'US', phone=5152961616),
            fedex.Package(20.0 * 16, 5, 5, 108, require_signature=True),
            fedex.SERVICES[1],
            fedex.PACKAGES[-1],
            False, # Email alert
            True,  # Evening
        ),
        (
            Address('TC #24', '456 Roswell Rd', 'Atlanta', 'GA', 30328, 'US', phone=5152961616),
            fedex.Package(20.0 * 16, 5, 5, 108, require_signature=True),
            fedex.SERVICES[1],
            fedex.PACKAGES[-1],
            False, # Email alert
            True,  # Evening
        ),
    ]
    
    f = fedex.Fedex(FedexConfig)
    
    for case in test_cases:
        try:
            print case
            recipient, package, service, package_type, email, evening = case
            packages = [ package ]
            response = f.label(packages, package_type, service, shipper, recipient, email, evening=evening)
            
            for info in response['info']:
                _show_file(extension='.png', data=info['label'])
        except fedex.FedexError as e:
            print e
Exemplo n.º 3
0
    def validate(self, recipient):
        client = self._get_client('XAV.wsdl')
        #client = self.soapClient('XAV.wsdl')
        #wsdl_url = self.wsdlURL('XAV.wsdl')
        #client = SoapClient(wsdl = wsdl_url, trace=True)
        #return client

        self._add_security_header(client)
        if not self.debug:
            client.set_options(
                location='https://onlinetools.ups.com/webservices/XAV')

        request = client.factory.create('ns0:RequestType')
        request.RequestOption = 3  # Address Validation w/ Classification

        address = client.factory.create('ns2:AddressKeyFormatType')
        address.ConsigneeName = recipient.name
        address.AddressLine = [recipient.address1, recipient.address2]
        address.PoliticalDivision2 = recipient.city
        address.PoliticalDivision1 = recipient.state
        address.PostcodePrimaryLow = recipient.zip
        address.CountryCode = self._normalized_country_code(recipient.country)

        try:
            reply = client.service.ProcessXAV(request,
                                              AddressKeyFormat=address)

            result = {}

            result['candidates'] = list()
            if hasattr(reply, 'Candidate'):
                for c in reply.Candidate:
                    name = c.AddressKeyFormat.ConsigneeName if hasattr(
                        c.AddressKeyFormat, 'ConsigneeName') else ''
                    a = Address(name, c.AddressKeyFormat.AddressLine[0],
                                c.AddressKeyFormat.PoliticalDivision2,
                                c.AddressKeyFormat.PoliticalDivision1,
                                c.AddressKeyFormat.PostcodePrimaryLow,
                                c.AddressKeyFormat.CountryCode)
                    if len(c.AddressKeyFormat.AddressLine) > 1:
                        a.address2 = c.AddressKeyFormat.AddressLine[1]

                    if a not in result['candidates']:
                        result['candidates'].append(a)

            if hasattr(reply, 'AddressClassification'):
                # Need some better names maybe
                result['class_code'] = reply.AddressClassification.Code
                result[
                    'class_description'] = reply.AddressClassification.Description

            result['valid'] = hasattr(reply, 'ValidAddressIndicator')
            result['ambiguous'] = hasattr(reply, 'AmbiguousAddressIndicator')
            return result
        except suds.WebFault as e:
            raise UPSError(e.fault, e.document)
Exemplo n.º 4
0
    def validate(self, recipient):
        client = self._get_client("XAV.wsdl")
        # client = self.soapClient('XAV.wsdl')
        # wsdl_url = self.wsdlURL('XAV.wsdl')
        # client = SoapClient(wsdl = wsdl_url, trace=True)
        # return client

        self._add_security_header(client)
        if not self.debug:
            client.set_options(location="https://onlinetools.ups.com/webservices/XAV")

        request = client.factory.create("ns0:RequestType")
        request.RequestOption = 3  # Address Validation w/ Classification

        address = client.factory.create("ns2:AddressKeyFormatType")
        address.ConsigneeName = recipient.name
        address.AddressLine = [recipient.address1, recipient.address2]
        address.PoliticalDivision2 = recipient.city
        address.PoliticalDivision1 = recipient.state
        address.PostcodePrimaryLow = recipient.zip
        address.CountryCode = self._normalized_country_code(recipient.country)

        try:
            reply = client.service.ProcessXAV(request, AddressKeyFormat=address)

            result = {}

            result["candidates"] = list()
            if hasattr(reply, "Candidate"):
                for c in reply.Candidate:
                    name = c.AddressKeyFormat.ConsigneeName if hasattr(c.AddressKeyFormat, "ConsigneeName") else ""
                    a = Address(
                        name,
                        c.AddressKeyFormat.AddressLine[0],
                        c.AddressKeyFormat.PoliticalDivision2,
                        c.AddressKeyFormat.PoliticalDivision1,
                        c.AddressKeyFormat.PostcodePrimaryLow,
                        c.AddressKeyFormat.CountryCode,
                    )
                    if len(c.AddressKeyFormat.AddressLine) > 1:
                        a.address2 = c.AddressKeyFormat.AddressLine[1]

                    if a not in result["candidates"]:
                        result["candidates"].append(a)

            if hasattr(reply, "AddressClassification"):
                # Need some better names maybe
                result["class_code"] = reply.AddressClassification.Code
                result["class_description"] = reply.AddressClassification.Description

            result["valid"] = hasattr(reply, "ValidAddressIndicator")
            result["ambiguous"] = hasattr(reply, "AmbiguousAddressIndicator")
            return result
        except suds.WebFault as e:
            raise UPSError(e.fault, e.document)
Exemplo n.º 5
0
    def __init__(self,
                 pkg,
                 picking=None,
                 from_address=None,
                 to_address=None,
                 customs=None,
                 config=None,
                 test=None):
        self.pkg = pkg
        self.picking = picking
        self.customs = customs

        if config == None:
            config = settings.UPS_CONFIG

        # Are we running in test mode? If so, we'll
        # need to use UPS's sandbox servers.
        if picking and picking.logis_company and test == None:
            test = picking.logis_company.test_mode

        self.api = UPS(config, debug=(test if test != None else False))

        # Get the shipper and recipient addresses for this order.
        if picking and not from_address:
            from_address = picking.company_id.partner_id
            from_address.state = from_address.state_id.code
            from_address.country = from_address.country_id.name

        if picking and not to_address:
            to_address = picking.partner_id or ''
            to_address.state = to_address.state_id.code
            to_address.country = to_address.country_id.name

        # Create the Address objects that we'll later pass to our Endicia object.
        self.shipper = Address(from_address.name,
                               from_address.street,
                               from_address.city,
                               from_address.state,
                               from_address.zip,
                               from_address.country,
                               address2=from_address.street2,
                               phone=from_address.phone)
        self.recipient = Address(to_address.name,
                                 to_address.street,
                                 to_address.city,
                                 to_address.state,
                                 to_address.zip,
                                 to_address.country,
                                 address2=to_address.street2,
                                 phone=to_address.phone)
Exemplo n.º 6
0
def TestFedexProd():
    test_cases = [
        (
            Address('TC #4', '20 FedEx Parkway', 'Kansas City', 'MO', 64112, 'US', address2='2nd Floor Suite 2001', phone=5152961616, is_residence=False),
            fedex.Package(20.0 * 16, 12, 12, 12),
            fedex.SERVICES[0],
            fedex.PACKAGES[-1],
            False, # Email alert
            False, # Evening
        ),
    ]
    
    from test_config import FedexConfigProd
    
    f = fedex.Fedex(FedexConfigProd, debug=False)
    
    for case in test_cases:
        try:
            print case
            recipient, package, service, package_type, email, evening = case
            packages = [ package ]
            response = f.label(packages, package_type, service, shipper, recipient, email, evening=evening)
            
            for info in response['info']:
                _show_file(extension='.png', data=info['label'])
        except fedex.FedexError as e:
            print e
Exemplo n.º 7
0
    def TestDomestic(self):
        # Test 'validate' function.
        recipient = Address(
            "Apple", "1 Infinite Loop", "Cupertino", "CA", 95014, "US", phone="5122901212", email="*****@*****.**"
        )
        self.assertTrue(self.api.validate(recipient)["valid"], msg="UPS thinks Apple's HQ address isn't valid.")

        bad_recipient = Address(
            "Apple",
            "1 Park Place.",
            "San Diego",
            "CA",
            95014,
            "US",
            phone="5122901212",
            email="*****@*****.**",
            address2="#502",
        )
        self.assertFalse(self.api.validate(bad_recipient)["valid"], msg="UPS thinks our invalid address is valid.")

        # Test 'label' function.
        validate = False
        recipient.is_residence = True
        package = Package(20.0 * 16, 12, 12, 12, value=1000, require_signature=3, reference="a12302b")
        response = self.api.label(
            [package], self.shipper, recipient, ups.SERVICES[2][0], ups.PACKAGES[7][0], validate, [self.test_email]
        )
        status = response["status"]
        self.assertIn("shipments", response)

        for shipment in response["shipments"]:
            self.assertIn("tracking_number", shipment)
            self.assertIn("cost", shipment)

        # Test 'rate' function.
        for package_type in ups.PACKAGES:
            package_code = package_type[0]
            response = self.api.rate(packages, package_code, shipper, r)
Exemplo n.º 8
0
    def TestIntl(self):
        recipients = [
            Address('Bazaarvoice', 'One Lyric Square', 'London', '', 'W6 0NB', 'GB', phone='+44 (0)208 080', email='*****@*****.**'),
            Address('Some Recipient', '24 Tennant st', 'EDINBURGH', 'Midlothian', 'EH6 5ND', 'GB', phone='+44 (0)208 080', email='*****@*****.**')
        ]
        packages = [
            Package(2.0 * 16, 12, 12, 12, value=100, require_signature=2, reference='a12302b')
        ]
        products = [
            Product(total=10, value=2, quantity=5, description='It\'s just a bunch of widgets', country = 'CA'),
            Product(total=10, value=2, quantity=5, description='It\'s just a bunch of widgets', country = 'CA')
        ]
        
        for recipient in recipients:
            validate = True
            recipient.is_residence = True
            response = self.api.label(intl_packages, self.shipper, recipient, ups.SERVICES[9][0], ups.PACKAGES[5][0], validate, [ self.test_email ], create_commercial_invoice=True, customs_info=products)
            self.assertIn("status", response)
            self.assertIn("shipments", response)

            for info in response['shipments']:
                self.assertIn("tracking_number", info)
                self.assertIn("cost", info)
Exemplo n.º 9
0
    def TestDomestic(self):
        # Test 'validate' function.
        recipient = Address('Apple', "1 Infinite Loop", 'Cupertino', 'CA', 95014, 'US', phone='5122901212', email='*****@*****.**')
        self.assertTrue(self.api.validate(recipient)["valid"], msg = "UPS thinks Apple's HQ address isn't valid.")
        
        bad_recipient = Address('Apple', "1 Park Place.", 'San Diego', 'CA', 95014, 'US', phone='5122901212', email='*****@*****.**', address2='#502')
        self.assertFalse(self.api.validate(bad_recipient)["valid"], msg = "UPS thinks our invalid address is valid.")
    
        # Test 'label' function.
        validate = False
        recipient.is_residence = True
        package = Package(20.0 * 16, 12, 12, 12, value=1000, require_signature=3, reference='a12302b')
        response = self.api.label([package], self.shipper, recipient, ups.SERVICES[2][0], ups.PACKAGES[7][0], validate, [ self.test_email ])
        status = response['status']
        self.assertIn("shipments", response)

        for shipment in response['shipments']:
            self.assertIn("tracking_number", shipment)
            self.assertIn("cost", shipment)
   
        # Test 'rate' function. 
        for package_type in ups.PACKAGES:
            package_code = package_type[0]
            response = self.api.rate(packages, package_code, shipper, r)
Exemplo n.º 10
0
from shipping import Address
from shipping import Package
from ups import PACKAGES
import logging
logging.basicConfig(level=logging.ERROR)
from shipping import setLoggingLevel
setLoggingLevel(logging.ERROR)
logging.getLogger('%s.ups' % __name__).setLevel(logging.DEBUG)

white_house = Address('Mr. President',
                      '1600 Pennsylvania Avenue NW',
                      'Washington',
                      'DC',
                      '20500',
                      'US',
                      company_name='White House')
powells = Address('Manager',
                  '1005 W Burnside',
                  'Portland',
                  'OR',
                  '97209',
                  'US',
                  is_residence=False,
                  company_name='Powell\'s City of Books')
our_place = Address('Wholesale Imports Guy',
                    '4957 Summer Ave',
                    'Memphis',
                    'TN',
                    '38122',
                    'US',
                    company_name='WholesaleImport.com')
Exemplo n.º 11
0
def TestFedexExpressCertification():
    test_cases = [
        (
            Address('TC #1',
                    '123 Bishop Rd',
                    'Honolulu',
                    'HI',
                    96819,
                    'US',
                    phone=5152961616),
            fedex.Package(1.0 * 16, 12, 12, 12),
            fedex.SERVICES[5],
            fedex.PACKAGES[0],
            False,  # Email alert
            False,  # Evening
        ),
        (
            Address('TC #4',
                    '789 Davies',
                    'Englewood',
                    'CO',
                    80112,
                    'US',
                    phone=5152961616),
            fedex.Package(1.0 * 16, 12, 12, 12),
            fedex.SERVICES[4],
            fedex.PACKAGES[0],
            False,  # Email alert
            False,  # Evening
        ),
        (
            Address('TC #7',
                    '6050 Rockwell Ave',
                    'Anchorage',
                    'AK',
                    99501,
                    'US',
                    phone=5152961616),
            fedex.Package(5.0 * 16, 12, 12, 12),
            fedex.SERVICES[3],
            fedex.PACKAGES[1],
            False,  # Email alert
            False,  # Evening
        ),
        (
            Address('TC #8',
                    '44 Binney St',
                    'Boston',
                    'MA',
                    02115,
                    'US',
                    phone=5152961616),
            fedex.Package(1.0 * 16, 12, 12, 12),
            fedex.SERVICES[6],
            fedex.PACKAGES[0],
            False,  # Email alert
            False,  # Evening
        ),
        (
            Address('TC #9',
                    '16 Court St',
                    'New York',
                    'NY',
                    10211,
                    'US',
                    phone=5152961616),
            fedex.Package(8.0 * 16, 7, 10, 15),
            fedex.SERVICES[6],
            fedex.PACKAGES[3],
            False,  # Email alert
            False,  # Evening
        ),
        (
            Address('TC #10',
                    'SW 129th St',
                    'Miami',
                    'FL',
                    33156,
                    'US',
                    phone=5152961616),
            fedex.Package(1.0 * 16, 12, 12, 12),
            fedex.SERVICES[2],
            fedex.PACKAGES[0],
            False,  # Email alert
            False,  # Evening
        ),
        (
            Address('TC #11',
                    '36 Charles Lane',
                    'Baltimore',
                    'MD',
                    21201,
                    'US',
                    phone=5152961616),
            fedex.Package(150 * 16, 10, 10, 15),
            fedex.SERVICES[2],
            fedex.PACKAGES[3],
            False,  # Email alert
            False,  # Evening
        ),
    ]

    f = fedex.Fedex(FedexTestConfig)

    for case in test_cases:
        try:
            print case
            recipient, package, service, package_type, email, evening = case
            packages = [package]
            response = f.label(packages,
                               package_type,
                               service,
                               shipper,
                               recipient,
                               email,
                               evening=evening)

            for info in response['info']:
                _show_file(extension='.png', data=info['label'])
        except fedex.FedexError as e:
            print e
Exemplo n.º 12
0
except ImportError:
    logging.error("Could not find FedexTestConfig in tests.config module.")
    exit(1)

from . import _show_file
import unittest
from shipping import Package, Address
import sys
sys.path.append('../')

import fedex

shipper = Address('Adobe',
                  "345 Park Avenue",
                  'San Jose',
                  'CA',
                  95110,
                  'US',
                  phone='5122901212',
                  email='*****@*****.**')
recipient = Address('Apple',
                    "1 Infinite Loop",
                    'Cupertino',
                    'CA',
                    95014,
                    'US',
                    phone='5122901212',
                    email='*****@*****.**')


def TestFedexGroundCertification():
    test_cases = [
Exemplo n.º 13
0
 def setUp(self):
     self.api = ups.UPS(UPSTestConfig, debug=True)
     self.shipper = Address('Adobe', "345 Park Avenue", 'San Jose', 'CA', 95110, 'US', phone='5122901212', email='*****@*****.**')
     self.test_email = '*****@*****.**'
Exemplo n.º 14
0
    from test_config import UPSConfig, EndiciaConfig
    from test_config import FedexConfigDebug as FedexConfig
except:
    print 'HELLO THERE! test_config not found. If you want to run this test, you need to setup test_config.py with your account information.'
    raise

import os, tempfile
from shipping import Package, Address, Product
import sys
sys.path.append('../')

import ups
import endicia
import fedex

shipper = Address('Adobe', "345 Park Avenue", 'San Jose', 'CA', 95110, 'US', phone='5122901212', email='*****@*****.**')
recipient = Address('Apple', "1 Infinite Loop", 'Cupertino', 'CA', 95014, 'US', phone='5122901212', email='*****@*****.**')
bad_recipient = Address('Apple', "1 Park Place.", 'San Diego', 'CA', 95014, 'US', phone='5122901212', email='*****@*****.**', address2='#502')
recipient_intl = Address('Apple', "1 Infinite Loop", 'Cupertino', 'CA', 95014, 'CA', phone='5122901212', email='*****@*****.**')
recipient_intl2 = Address('Bazaarvoice', 'One Lyric Square', 'London', '', 'W6 0NB', 'GB', phone='+44 (0)208 080', email='*****@*****.**')
# recipient_intl3 = Address('Bazaarvoice', '111 Rue Francis de Pressensé', 'villeurbanne', '', '69100', 'FR', phone='+44 (0)208 080', email='*****@*****.**')
recipient_intl4 = Address('Some Recipient', '24 Tennant st', 'EDINBURGH', 'Midlothian', 'EH6 5ND', 'GB', phone='+44 (0)208 080', email='*****@*****.**')
# recipient_intl5 = Address('Bazaarvoice', 'Flat 3 Gainsborough Court', 'London', '', 'W6 0NB', 'GB', phone='+44 (0)208 080', email='*****@*****.**')
# recipient_intl6 = Address('Bazaarvoice', 'One Lyric Square', 'London', '', 'W6 0NB', 'GB', phone='+44 (0)208 080', email='*****@*****.**')

def _show_file(extension, data):
    with tempfile.NamedTemporaryFile(suffix=extension, delete=False) as temp_file:
        temp_file.write(data)
        os.system('open %s' % temp_file.name)

class P(object):