Exemplo n.º 1
0
    def testIsCarrierSpecific(self):
        carrierSpecificNumber = PhoneNumber(country_code=1,
                                            national_number=33669)
        self.assertTrue(
            shortnumberinfo.is_carrier_specific(carrierSpecificNumber))
        self.assertTrue(
            shortnumberinfo.is_carrier_specific_for_region(
                _parse("33669", "US"), "US"))

        notCarrierSpecificNumber = PhoneNumber(country_code=1,
                                               national_number=911)
        self.assertFalse(
            shortnumberinfo.is_carrier_specific(notCarrierSpecificNumber))
        self.assertFalse(
            shortnumberinfo.is_carrier_specific_for_region(
                _parse("911", "US"), "US"))

        carrierSpecificNumberForSomeRegion = PhoneNumber(country_code=1,
                                                         national_number=211)
        self.assertTrue(
            shortnumberinfo.is_carrier_specific(
                carrierSpecificNumberForSomeRegion))
        self.assertTrue(
            shortnumberinfo.is_carrier_specific_for_region(
                carrierSpecificNumberForSomeRegion, "US"))
        self.assertFalse(
            shortnumberinfo.is_carrier_specific_for_region(
                carrierSpecificNumberForSomeRegion, "BB"))
        # Python version extra test: check invalid region code
        self.assertFalse(
            shortnumberinfo.is_carrier_specific_for_region(
                carrierSpecificNumberForSomeRegion, "XY"))
 def testCarrierSpecificShortNumbers(self):
     wrongTagCounter = 0
     for regionCode in phonenumberutil.SUPPORTED_SHORT_REGIONS:
         # Test the carrier-specific tag.
         metadata = PhoneMetadata.short_metadata_for_region(regionCode, None)
         desc = metadata.carrier_specific
         if desc.example_number is not None:
             exampleNumber = desc.example_number
             carrierSpecificNumber = phonenumberutil.parse(exampleNumber, regionCode)
             if (not fullmatch(re.compile(desc.possible_number_pattern), exampleNumber) or
                 not shortnumberinfo.is_carrier_specific(carrierSpecificNumber)):
                 wrongTagCounter += 1
                 prnt("Carrier-specific test failed for %s" % regionCode, file=sys.stderr)
         # TODO: Test other tags here
     self.assertEqual(0, wrongTagCounter)
 def testCarrierSpecificShortNumbers(self):
     wrongTagCounter = 0
     for regionCode in phonenumberutil.SUPPORTED_SHORT_REGIONS:
         # Test the carrier-specific tag.
         metadata = PhoneMetadata.short_metadata_for_region(
             regionCode, None)
         desc = metadata.carrier_specific
         if desc.example_number is not None:
             exampleNumber = desc.example_number
             carrierSpecificNumber = phonenumberutil.parse(
                 exampleNumber, regionCode)
             if (not fullmatch(re.compile(desc.possible_number_pattern),
                               exampleNumber)
                     or not shortnumberinfo.is_carrier_specific(
                         carrierSpecificNumber)):
                 wrongTagCounter += 1
                 prnt("Carrier-specific test failed for %s" % regionCode,
                      file=sys.stderr)
         # TODO: Test other tags here
     self.assertEqual(0, wrongTagCounter)
 def testIsCarrierSpecific(self):
     # Python version extra test: hit is_carrier_specific entrypoint
     esNumber = PhoneNumber(country_code=34, national_number=123)
     self.assertTrue(shortnumberinfo.is_carrier_specific(esNumber))
     esNumber.national_number = 512345678
     self.assertFalse(shortnumberinfo.is_carrier_specific(esNumber))
 def testIsCarrierSpecific(self):
     # Python version extra test: hit is_carrier_specific entrypoint
     esNumber = PhoneNumber(country_code=34, national_number=123)
     self.assertTrue(shortnumberinfo.is_carrier_specific(esNumber))
     esNumber.national_number = 512345678
     self.assertFalse(shortnumberinfo.is_carrier_specific(esNumber))