예제 #1
0
 def test_valid_postal_code_ok(self):
     """Verify validating a good postal code succeeds."""
     validator = postal_code_validator.PostalCodeValidator(
         self.fn_postal_data)
     for country in self.good_postal_codes:
         self.assertEqual(
             validator.valid_postal_code(country,
                                         self.good_postal_codes[country]),
             self.good_postal_codes[country])
예제 #2
0
 def test_invalid_postal_code_fails(self):
     """Verify validating a bad postal code fails."""
     validator = postal_code_validator.PostalCodeValidator(
         self.fn_postal_data)
     for country in self.bad_postal_codes:
         self.assertEqual(
             validator.valid_postal_code(country,
                                         self.bad_postal_codes[country]),
             None)
예제 #3
0
    def test_supported_countries(self):
        """Verify supported countries returns the correct number."""
        validator = postal_code_validator.PostalCodeValidator()
        validator.load_country("GB", self.sample_postal_data["GB"])
        validator.load_country("DE", self.sample_postal_data["GB"])
        validator.load_country("JP", self.sample_postal_data["GB"])

        self.assertEqual(len(validator.supported_countries()), 3)
        for country in ["GB", "DE", "JP"]:
            self.assertTrue(country in validator.supported_countries())
예제 #4
0
 def test_valid_postal_code_invalid_country(self):
     """Verify validating a postal code with an invalid country code."""
     validator = postal_code_validator.PostalCodeValidator(
         self.fn_postal_data)
     self.assertRaises(postal_code_validator.UnsupportedCountryError,
                       validator.valid_postal_code, "ZZ", "doesn't matter")
예제 #5
0
 def test_load_country_data_from_xml_ok(self):
     """Verify loading postal data from CLDR postalCodeData.xml formatted file."""
     validator = postal_code_validator.PostalCodeValidator(
         self.fn_postal_data)
     self.assertTrue(len(validator.postal_code_patterns.keys()) > 3)
예제 #6
0
 def test_load_country_invalid_iso_code(self):
     """Verify loading a non-2-digit country code fails."""
     validator = postal_code_validator.PostalCodeValidator()
     self.assertRaises(postal_code_validator.InvalidISO2DCountryCodeError,
                       validator.load_country, "GBX",
                       self.sample_postal_data["GB"])
예제 #7
0
 def test_load_country_ok(self):
     """Verify loading valid country postal code data."""
     validator = postal_code_validator.PostalCodeValidator()
     validator.load_country("GB", self.sample_postal_data["GB"])
     self.assertTrue(
         validator.valid_postal_code("GB", self.good_postal_codes["GB"]))
예제 #8
0
 def test_invalid_postal_code_global_fails(self):
     """Verify validating a globally unknown postal code without country code fails."""
     validator = postal_code_validator.PostalCodeValidator(
         self.fn_postal_data)
     self.assertEqual(validator.valid_postal_code_global("97x60"), None)
예제 #9
0
 def test_valid_postal_code_global_ok(self):
     """Verify validating a good postal code without country code succeeds."""
     # YY = Mayotte, valid postal code is 97660
     validator = postal_code_validator.PostalCodeValidator(
         self.fn_postal_data)
     self.assertEqual(validator.valid_postal_code_global("97660"), "97660")
예제 #10
0
 def test_valid_postal_code_unsupported_country(self):
     """Verify validating a postal code for an unsupported country fails."""
     validator = postal_code_validator.PostalCodeValidator(
         self.fn_postal_data)
     self.assertRaises(postal_code_validator.InvalidISO2DCountryCodeError,
                       validator.valid_postal_code, "abc", "doesn't matter")