def testIsPossibleShortNumber(self): possibleNumber = PhoneNumber(country_code=33, national_number=123456) self.assertTrue(is_possible_short_number(possibleNumber)) self.assertTrue(is_possible_short_number_for_region(_parse("123456", "FR"), "FR")) impossibleNumber = PhoneNumber(country_code=33, national_number=9) self.assertFalse(is_possible_short_number(impossibleNumber)) # Note that GB and GG share the country calling code 44, and that this # number is possible but not valid. self.assertTrue(is_possible_short_number(PhoneNumber(country_code=44, national_number=11001))) # Python version extra test: check invalid region code self.assertFalse(is_possible_short_number_for_region(_parse("123456", "US"), "XY"))
def testIsPossibleShortNumber(self): possibleNumber = PhoneNumber(country_code=33, national_number=123456) self.assertTrue(is_possible_short_number(possibleNumber)) self.assertTrue(is_possible_short_number_for_region(_parse("123456", "FR"), "FR")) impossibleNumber = PhoneNumber(country_code=33, national_number=9) self.assertFalse(is_possible_short_number(impossibleNumber)) # Note that GB and GG share the country calling code 44, and that this # number is possible but not valid. self.assertTrue(is_possible_short_number(PhoneNumber(country_code=44, national_number=11001))) # Python version extra test: check invalid region code self.assertFalse(is_possible_short_number_for_region("123456", "XY"))
def testEmergency(self): wrongTypeCounter = 0 for regionCode in shortnumberinfo.SUPPORTED_SHORT_REGIONS: metadata = PhoneMetadata.short_metadata_for_region(regionCode, None) desc = metadata.emergency if desc is not None and desc.example_number is not None: exampleNumber = desc.example_number phoneNumber = phonenumberutil.parse(exampleNumber, regionCode) if (not is_possible_short_number_for_region(phoneNumber, regionCode) or not is_emergency_number(exampleNumber, regionCode)): wrongTypeCounter += 1 prnt("Emergency example number test failed for %s" % regionCode, file=sys.stderr) elif shortnumberinfo.expected_cost_for_region(phoneNumber, regionCode) != ShortNumberCost.TOLL_FREE: wrongTypeCounter += 1 prnt("Emergency example number not toll free for %s" % regionCode, file=sys.stderr) self.assertEqual(0, wrongTypeCounter)