コード例 #1
0
class TestAddressValidation(unittest.TestCase):
    """
    Test the :class:`AddressValidation`
    """

    @classmethod
    def setUpClass(self):
        """Check if the variables for initialising the test case is available
        in the environment"""
        assert 'UPS_LICENSE_NO' in os.environ, \
            "UPS_LICENSE_NO not given. Hint:Use export UPS_LICENSE_NO=<number>"
        assert 'UPS_SHIPPER_NO' in os.environ, \
            "UPS_SHIPPER_NO not given. Hint:Use export UPS_SHIPPER_NO=<number>"
        assert 'UPS_USER_ID' in os.environ, \
            "UPS_USER_ID not given. Hint:Use export UPS_USER_ID=<user_id>"
        assert 'UPS_PASSWORD' in os.environ, \
            "UPS_PASSWORD not given. Hint:Use export UPS_PASSWORD=<password>"

    def setUp(self):
        """Initialise a AddressValidation.
        """
        logging.disable(logging.DEBUG)
        self.address_validation = AddressValidation(
            os.environ['UPS_LICENSE_NO'],
            os.environ['UPS_USER_ID'],
            os.environ['UPS_PASSWORD'],
            True            # Test must be performed in sandbox anyway
        )

    def test_010_address_validation_true(self):
        "Test the address validation of correct address"
        address_validation_type = AddressValidation.request_type(
            CountryCode="US", City="MIAMI", StateProvinceCode="FL",
            PostalCode="33101"
        )
        response = self.address_validation.request(address_validation_type)

        self.assertEqual(
            response.AddressValidationResult.Quality, 1.0
        )
        print etree.tostring(response, pretty_print=True)

    def test_020_address_validation_false(self):
        "Test the address validation of wrong address"
        address_validation_type = AddressValidation.request_type(
            CountryCode="US", City="MIAMI", StateProvinceCode="FL",
            PostalCode="12345"
        )
        response = self.address_validation.request(address_validation_type)

        self.assertTrue(
            len(response.AddressValidationResult) > 1
        )
        print etree.tostring(response, pretty_print=True)
コード例 #2
0
 def setUp(self):
     """Initialise a AddressValidation.
     """
     logging.disable(logging.DEBUG)
     self.address_validation = AddressValidation(
         os.environ['UPS_LICENSE_NO'],
         os.environ['UPS_USER_ID'],
         os.environ['UPS_PASSWORD'],
         True            # Test must be performed in sandbox anyway
     )
コード例 #3
0
    def test_020_address_validation_false(self):
        "Test the address validation of wrong address"
        address_validation_type = AddressValidation.request_type(
            CountryCode="US", City="MIAMI", StateProvinceCode="FL",
            PostalCode="12345"
        )
        response = self.address_validation.request(address_validation_type)

        self.assertTrue(
            len(response.AddressValidationResult) > 1
        )
        print etree.tostring(response, pretty_print=True)
コード例 #4
0
    def test_010_address_validation_true(self):
        "Test the address validation of correct address"
        address_validation_type = AddressValidation.request_type(
            CountryCode="US", City="MIAMI", StateProvinceCode="FL",
            PostalCode="33101"
        )
        response = self.address_validation.request(address_validation_type)

        self.assertEqual(
            response.AddressValidationResult.Quality, 1.0
        )
        print etree.tostring(response, pretty_print=True)