def testIsValidShortNumber(self): self.assertTrue( is_valid_short_number( PhoneNumber(country_code=33, national_number=1010))) self.assertTrue(is_valid_short_number_for_region("1010", "FR")) self.assertFalse( is_valid_short_number( PhoneNumber(country_code=33, national_number=123456))) self.assertFalse(is_valid_short_number_for_region("123456", "FR")) # Note that GB and GG share the country calling code 44. self.assertTrue( is_valid_short_number( PhoneNumber(country_code=44, national_number=18001))) # Python version extra test: check invalid region code self.assertFalse(is_valid_short_number_for_region("123456", "XY")) self.assertFalse( is_valid_short_number( PhoneNumber(country_code=99, national_number=123))) # Python version extra test: not matching general desc self.assertFalse(is_valid_short_number_for_region("2123456", "US")) # Python version extra test: shared country code (44 => GB+GG) but not valid in either self.assertFalse( is_valid_short_number( PhoneNumber(country_code=44, national_number=58001)))
def testGetExpectedCost(self): premiumRateExample = shortnumberinfo._example_short_number_for_cost("FR", ShortNumberCost.PREMIUM_RATE) self.assertEqual(ShortNumberCost.PREMIUM_RATE, expected_cost_for_region(_parse(premiumRateExample, "FR"), "FR")) premiumRateNumber = PhoneNumber(country_code=33, national_number=int(premiumRateExample)) self.assertEqual(ShortNumberCost.PREMIUM_RATE, expected_cost(premiumRateNumber)) standardRateExample = shortnumberinfo._example_short_number_for_cost("FR", ShortNumberCost.STANDARD_RATE) self.assertEqual(ShortNumberCost.STANDARD_RATE, expected_cost_for_region(_parse(standardRateExample, "FR"), "FR")) standardRateNumber = PhoneNumber(country_code=33, national_number=int(standardRateExample)) self.assertEqual(ShortNumberCost.STANDARD_RATE, expected_cost(standardRateNumber)) tollFreeExample = shortnumberinfo._example_short_number_for_cost("FR", ShortNumberCost.TOLL_FREE) self.assertEqual(ShortNumberCost.TOLL_FREE, expected_cost_for_region(_parse(tollFreeExample, "FR"), "FR")) tollFreeNumber = PhoneNumber(country_code=33, national_number=int(tollFreeExample)) self.assertEqual(ShortNumberCost.TOLL_FREE, expected_cost(tollFreeNumber)) self.assertEqual(ShortNumberCost.UNKNOWN_COST, expected_cost_for_region(_parse("12345", "FR"), "FR")) unknownCostNumber = PhoneNumber(country_code=33, national_number=12345) self.assertEqual(ShortNumberCost.UNKNOWN_COST, expected_cost(unknownCostNumber)) # Test that an invalid number may nevertheless have a cost other than UNKNOWN_COST. self.assertFalse(is_valid_short_number_for_region("116123", "FR")) invalidNumber = PhoneNumber(country_code=33, national_number=116123) self.assertEqual(ShortNumberCost.TOLL_FREE, expected_cost_for_region(_parse("116123", "FR"), "FR")) self.assertFalse(is_valid_short_number(invalidNumber)) self.assertEqual(ShortNumberCost.TOLL_FREE, expected_cost(invalidNumber)) # Test a nonexistent country code. self.assertEqual(ShortNumberCost.UNKNOWN_COST, expected_cost_for_region(_parse("911", "US"), "ZZ")) unknownCostNumber.country_code = 123 unknownCostNumber.national_number = 911 self.assertEqual(ShortNumberCost.UNKNOWN_COST, expected_cost(unknownCostNumber))
def testIsValidShortNumber(self): self.assertTrue(is_valid_short_number(PhoneNumber(country_code=33, national_number=1010))) self.assertTrue(is_valid_short_number_for_region(_parse("1010", "FR"), "FR")) self.assertFalse(is_valid_short_number(PhoneNumber(country_code=33, national_number=123456))) self.assertFalse(is_valid_short_number_for_region(_parse("123456", "FR"), "FR")) # Note that GB and GG share the country calling code 44. self.assertTrue(is_valid_short_number(PhoneNumber(country_code=44, national_number=18001))) # Python version extra test: check invalid region code self.assertFalse(is_valid_short_number_for_region("123456", "XY")) self.assertFalse(is_valid_short_number(PhoneNumber(country_code=99, national_number=123))) # Python version extra test: not matching general desc self.assertFalse(is_valid_short_number_for_region(_parse("2123456", "US"), "US")) # Python version extra test: shared country code (44 => GB+GG) but not valid in either self.assertFalse(is_valid_short_number(PhoneNumber(country_code=44, national_number=58001)))
def testGetExpectedCost(self): premiumRateExample = shortnumberinfo._example_short_number_for_cost("FR", ShortNumberCost.PREMIUM_RATE) self.assertEqual(ShortNumberCost.PREMIUM_RATE, expected_cost_for_region(_parse(premiumRateExample, "FR"), "FR")) premiumRateNumber = PhoneNumber(country_code=33, national_number=int(premiumRateExample)) self.assertEqual(ShortNumberCost.PREMIUM_RATE, expected_cost(premiumRateNumber)) standardRateExample = shortnumberinfo._example_short_number_for_cost("FR", ShortNumberCost.STANDARD_RATE) self.assertEqual(ShortNumberCost.STANDARD_RATE, expected_cost_for_region(_parse(standardRateExample, "FR"), "FR")) standardRateNumber = PhoneNumber(country_code=33, national_number=int(standardRateExample)) self.assertEqual(ShortNumberCost.STANDARD_RATE, expected_cost(standardRateNumber)) tollFreeExample = shortnumberinfo._example_short_number_for_cost("FR", ShortNumberCost.TOLL_FREE) self.assertEqual(ShortNumberCost.TOLL_FREE, expected_cost_for_region(_parse(tollFreeExample, "FR"), "FR")) tollFreeNumber = PhoneNumber(country_code=33, national_number=int(tollFreeExample)) self.assertEqual(ShortNumberCost.TOLL_FREE, expected_cost(tollFreeNumber)) self.assertEqual(ShortNumberCost.UNKNOWN_COST, expected_cost_for_region(_parse("12345", "FR"), "FR")) unknownCostNumber = PhoneNumber(country_code=33, national_number=12345) self.assertEqual(ShortNumberCost.UNKNOWN_COST, expected_cost(unknownCostNumber)) # Test that an invalid number may nevertheless have a cost other than UNKNOWN_COST. self.assertFalse(is_valid_short_number_for_region(_parse("116123", "FR"), "FR")) invalidNumber = PhoneNumber(country_code=33, national_number=116123) self.assertEqual(ShortNumberCost.TOLL_FREE, expected_cost_for_region(_parse("116123", "FR"), "FR")) self.assertFalse(is_valid_short_number(invalidNumber)) self.assertEqual(ShortNumberCost.TOLL_FREE, expected_cost(invalidNumber)) # Test a nonexistent country code. self.assertEqual(ShortNumberCost.UNKNOWN_COST, expected_cost_for_region(_parse("911", "US"), "ZZ")) unknownCostNumber.country_code = 123 unknownCostNumber.national_number = 911 self.assertEqual(ShortNumberCost.UNKNOWN_COST, expected_cost(unknownCostNumber))