Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_pickup_batch(noon_on_next_monday):
# Create a Batch containing multiple Shipments. Then we try to buy a Pickup and assert if it was bought.
pickup_address = easypost.Address.create(
verify=['delivery'],
name='Jarrett Streebin',
company='EasyPost',
street1='1 MONTGOMERY ST STE 400',
city='San Francisco',
state='CA',
zip='94104',
phone='415-456-7890'
)
shipments = [
{
'to_address': {
'name': 'Customer',
'street1': '8308 Fenway Rd',
'city': 'Bethesda',
def test_address_unicode():
# Create an address with unicode field and assert if it was created correctly.
state = u'DELEGACI\xf3N BENITO JU\xe1REZ'
address = easypost.Address.create(state=state)
assert address.state == state
def test_address_creation_verification():
# Create an address and then verify some fields to test whether it was created just fine.
address = easypost.Address.create(
company='EasyPost',
street1='118 2nd St',
street2='4th Fl',
city='San Francisco',
state='CA',
zip='94105',
phone='415-456-7890'
)
address.verify()
address = easypost.Address.retrieve(address.id)
assert address.country == 'US'
assert address.email is None
assert address.federal_tax_id is None
assert address.state == 'CA'
def test_address_bytestring():
# Create an address with a bytestring field and assert if it was created correctly.
state = u'DELEGACI\xf3N BENITO JU\xe1REZ'
address = easypost.Address.create(state=state.encode('utf-8'))
assert address.state == state
def test_batch_create_and_buy():
# We create Address and Parcel objects. We then try to create a Batch containing a shipment. Finally,
# Finally, we assert on saved and returned data.
# from address and parcel don't change
from_address = easypost.Address.create(
name='Simpler Postage Inc.',
street1='388 Townsend St',
street2='Apt 20',
city='San Francisco',
state='CA',
zip='94107',
phone='415-456-7890'
)
parcel = easypost.Parcel.create(
predefined_package='RegionalRateBoxA',
weight=64
)
# # populate order_list from db, csv, etc.
order_list = [{
def test_single_pickup(noon_on_next_monday):
"""Create a Shipment, buy it, and then buy a pickup for it"""
pickup_address = easypost.Address.create(
verify=['delivery'],
name='Jarrett Streebin',
company='EasyPost',
street1='1 MONTGOMERY ST STE 400',
city='San Francisco',
state='CA',
zip='94104',
phone='415-456-7890'
)
shipment = easypost.Shipment.create(
to_address={
'name': 'Customer',
'street1': '8308 Fenway Rd',
'city': 'Bethesda',
'state': 'MD',
def test_shipment_creation():
# We create a shipment and assert on values saved.
# create a to address and a from address
to_address = easypost.Address.create(
name="Sawyer Bateman",
street1="1A Larkspur Cres.",
street2="",
city="St. Albert",
state="AB",
zip="t8n2m4",
country="CA",
phone="780-283-9384"
)
from_address = easypost.Address.create(
company="EasyPost",
street1="118 2nd St",
street2="4th Fl",
city="San Francisco",
state="CA",
zip="94105",
phone="415-456-7890"
)
# create a parcel
parcel = easypost.Parcel.create(
length=10.2,
width=7.8,
height=4.3,
weight=21.2
)
def test_shipment_creation():
# We create a shipment and assert on values saved.
# create a to address and a from address
to_address = easypost.Address.create(
name="Sawyer Bateman",
street1="1A Larkspur Cres.",
street2="",
city="St. Albert",
state="AB",
zip="t8n2m4",
country="CA",
phone="780-283-9384"
)
from_address = easypost.Address.create(
company="EasyPost",
street1="118 2nd St",
street2="4th Fl",
city="San Francisco",
state="CA",
zip="94105",
weight=21.1
)
customs_info = easypost.CustomsInfo.create(
customs_certify=1,
customs_signer="Hector Hammerfall",
contents_type="gift",
contents_explanation="",
eel_pfc="NOEEI 30.37(a)",
non_delivery_option="return",
restriction_type="none",
restriction_comments="",
customs_items=[customs_item]
)
# create shipment
shipment = easypost.Shipment.create(
to_address=to_address,
from_address=from_address,
parcel=parcel,
customs_info=customs_info
)
rate_id = shipment.rates[0].id
assert rate_id is not None
shipment.get_rates()
new_rate_id = shipment.rates[0].id
assert new_rate_id is not None
assert new_rate_id != rate_id
# Assert address values match
def test_single_pickup(noon_on_next_monday):
"""Create a Shipment, buy it, and then buy a pickup for it"""
pickup_address = easypost.Address.create(
verify=['delivery'],
name='Jarrett Streebin',
company='EasyPost',
street1='1 MONTGOMERY ST STE 400',
city='San Francisco',
state='CA',
zip='94104',
phone='415-456-7890'
)
shipment = easypost.Shipment.create(
to_address={
'name': 'Customer',
'street1': '8308 Fenway Rd',
'city': 'Bethesda',
'state': 'MD',
'zip': '20817',
'country': 'US'
},
from_address=pickup_address,
parcel={
'weight': 21.2
},
)
shipment.buy(rate=shipment.lowest_rate('USPS', 'Priority'), insurance=100.00)