# Path: shippo/test/helper.py
# def create_mock_shipment(asynchronous=False, api_key=None):
#     to_address = shippo.Address.create(api_key=api_key, **TO_ADDRESS)
#     from_address = shippo.Address.create(api_key=api_key, **FROM_ADDRESS)
#     parcel = shippo.Parcel.create(api_key=api_key, **DUMMY_PARCEL)
#     SHIPMENT = DUMMY_SHIPMENT.copy()
#     SHIPMENT['address_from'] = from_address.object_id
#     SHIPMENT['address_to'] = to_address.object_id
#     SHIPMENT['parcels'] = [parcel.object_id]
#     SHIPMENT['asynchronous'] = asynchronous
#     shipment = shippo.Shipment.create(api_key=api_key, **SHIPMENT)
#     return shipment
# 
# DUMMY_ADDRESS = {
#     "name": "Laura Behrens Wu",
#     "company": "Shippo",
#     "street1": "Clayton St.",
#     "street_no": "215",
#     "street2": "",
#     "city": "San Francisco",
#     "state": "CA",
#     "zip": "94117",
#     "country": "US",
#     "phone": "+1 555 341 9393",
#     "metadata": "Customer ID 123456"
# }
# 
# INVALID_ADDRESS = {
#     "name": "Laura Behrens Wu",
#     "company": "Shippo",
#     "street2": "",
#     "city": "San Francisco",
#     "state": "CA",
#     "country": "US",
#     "phone": "+1 555 341 9393",
#     "metadata": "Customer ID 123456"
# }
# 
# class ShippoTestCase(TestCase):
#     RESTORE_ATTRIBUTES = ('api_version', 'api_key')
# 
#     def setUp(self):
#         super(ShippoTestCase, self).setUp()
# 
#         self._shippo_original_attributes = {}
# 
#         for attr in self.RESTORE_ATTRIBUTES:
#             self._shippo_original_attributes[attr] = getattr(
#                 shippo.config, attr)
# 
#         api_base = os.environ.get('SHIPPO_API_BASE')
#         if api_base:
#             shippo.config.api_base = api_base
# 
#         shippo.config.api_key = os.environ.get(
#             'SHIPPO_API_KEY', '51895b669caa45038110fd4074e61e0d')
#         shippo.config.api_version = os.environ.get(
#             'SHIPPO_API_VERSION', '2018-02-08')
# 
#     def tearDown(self):
#         super(ShippoTestCase, self).tearDown()
# 
#         for attr in self.RESTORE_ATTRIBUTES:
#             setattr(shippo.config, attr,
#                     self._shippo_original_attributes[attr])
# 
#     # Python < 2.7 compatibility
#     def assertRaisesRegexp(self, exception, regexp, callable, *args, **kwargs):
#         try:
#             callable(*args, **kwargs)
#         except exception as err:
#             if regexp is None:
#                 return True
# 
#             if isinstance(regexp, str):
#                 regexp = re.compile(regexp)
#             if not regexp.search(str(err)):
#                 raise self.failureException('"%s" does not match "%s"' %
#                                             (regexp.pattern, str(err)))
#         else:
#             raise self.failureException(
#                 '%s was not raised' % (exception.__name__,))


import unittest2
import shippo
from mock import patch
from shippo.test.helper import (
    create_mock_shipment,
    DUMMY_ADDRESS,
    INVALID_ADDRESS,
    ShippoTestCase,
)

    def test_run(self):
        try:
            address = shippo.Address.create(**DUMMY_ADDRESS)
            self.assertEqual(address.is_complete, True)
            address_validated = shippo.Address.validate(address.object_id)
            self.assertEqual(address_validated.is_complete, True)
        except shippo.error.AuthenticationError:
            self.fail('Set your SHIPPO_API_KEY in your os.environ')
        except Exception as inst:
            self.fail("Test failed with exception %s" % inst)

    def test_list_accessors(self):
        try:
            address = shippo.Address.create(**DUMMY_ADDRESS)
        except shippo.error.AuthenticationError:
            self.fail('Set your SHIPPO_API_KEY in your os.environ')

        self.assertEqual(address['object_created'], address.object_created)
        address['foo'] = 'bar'
        self.assertEqual(address.foo, 'bar')

    def test_unicode(self):
        # Make sure unicode requests can be sent
        self.assertRaises(shippo.error.APIError,
                          shippo.Address.retrieve,
                          '☃')

    def test_get_rates(self):
        try:

# Path: shippo/test/helper.py
# def create_mock_shipment(asynchronous=False, api_key=None):
#     to_address = shippo.Address.create(api_key=api_key, **TO_ADDRESS)
#     from_address = shippo.Address.create(api_key=api_key, **FROM_ADDRESS)
#     parcel = shippo.Parcel.create(api_key=api_key, **DUMMY_PARCEL)
#     SHIPMENT = DUMMY_SHIPMENT.copy()
#     SHIPMENT['address_from'] = from_address.object_id
#     SHIPMENT['address_to'] = to_address.object_id
#     SHIPMENT['parcels'] = [parcel.object_id]
#     SHIPMENT['asynchronous'] = asynchronous
#     shipment = shippo.Shipment.create(api_key=api_key, **SHIPMENT)
#     return shipment
# 
# DUMMY_ADDRESS = {
#     "name": "Laura Behrens Wu",
#     "company": "Shippo",
#     "street1": "Clayton St.",
#     "street_no": "215",
#     "street2": "",
#     "city": "San Francisco",
#     "state": "CA",
#     "zip": "94117",
#     "country": "US",
#     "phone": "+1 555 341 9393",
#     "metadata": "Customer ID 123456"
# }
# 
# INVALID_ADDRESS = {
#     "name": "Laura Behrens Wu",
#     "company": "Shippo",
#     "street2": "",
#     "city": "San Francisco",
#     "state": "CA",
#     "country": "US",
#     "phone": "+1 555 341 9393",
#     "metadata": "Customer ID 123456"
# }
# 
# class ShippoTestCase(TestCase):
#     RESTORE_ATTRIBUTES = ('api_version', 'api_key')
# 
#     def setUp(self):
#         super(ShippoTestCase, self).setUp()
# 
#         self._shippo_original_attributes = {}
# 
#         for attr in self.RESTORE_ATTRIBUTES:
#             self._shippo_original_attributes[attr] = getattr(
#                 shippo.config, attr)
# 
#         api_base = os.environ.get('SHIPPO_API_BASE')
#         if api_base:
#             shippo.config.api_base = api_base
# 
#         shippo.config.api_key = os.environ.get(
#             'SHIPPO_API_KEY', '51895b669caa45038110fd4074e61e0d')
#         shippo.config.api_version = os.environ.get(
#             'SHIPPO_API_VERSION', '2018-02-08')
# 
#     def tearDown(self):
#         super(ShippoTestCase, self).tearDown()
# 
#         for attr in self.RESTORE_ATTRIBUTES:
#             setattr(shippo.config, attr,
#                     self._shippo_original_attributes[attr])
# 
#     # Python < 2.7 compatibility
#     def assertRaisesRegexp(self, exception, regexp, callable, *args, **kwargs):
#         try:
#             callable(*args, **kwargs)
#         except exception as err:
#             if regexp is None:
#                 return True
# 
#             if isinstance(regexp, str):
#                 regexp = re.compile(regexp)
#             if not regexp.search(str(err)):
#                 raise self.failureException('"%s" does not match "%s"' %
#                                             (regexp.pattern, str(err)))
#         else:
#             raise self.failureException(
#                 '%s was not raised' % (exception.__name__,))


# Path: shippo/test/integration/test_integration.py
import unittest2
import shippo
from mock import patch
from shippo.test.helper import (
    create_mock_shipment,
    DUMMY_ADDRESS,
    INVALID_ADDRESS,
    ShippoTestCase,
)


    def test_run(self):
        try:
            address = shippo.Address.create(**DUMMY_ADDRESS)
            self.assertEqual(address.is_complete, True)
            address_validated = shippo.Address.validate(address.object_id)
            self.assertEqual(address_validated.is_complete, True)
        except shippo.error.AuthenticationError:
            self.fail('Set your SHIPPO_API_KEY in your os.environ')
        except Exception as inst:
            self.fail("Test failed with exception %s" % inst)

    def test_list_accessors(self):
        try:
            address = shippo.Address.create(**DUMMY_ADDRESS)
        except shippo.error.AuthenticationError:
            self.fail('Set your SHIPPO_API_KEY in your os.environ')

        self.assertEqual(address['object_created'], address.object_created)
        address['foo'] = 'bar'
        self.assertEqual(address.foo, 'bar')

    def test_unicode(self):
        # Make sure unicode requests can be sent
        self.assertRaises(shippo.error.APIError,
                          shippo.Address.retrieve,
                          '☃')

    def test_get_rates(self):
        try:

            shipment = create_mock_shipment()