def test_invalid_if_exchange_code_starts_with_1_on_valid_11_digit_number(
         self):
     with self.assertRaises(ValueError) as err:
         PhoneNumber("1 (223) 156-7890")
     self.assertEqual(type(err.exception), ValueError)
     self.assertEqual(err.exception.args[0],
                      "exchange code cannot start with one")
Exemplo n.º 2
0
    def test_equality_and_immutability(self):
        n1 = PhoneNumber("716 776 2323")
        n2 = PhoneNumber("(212) 664-7665")
        n3 = PhoneNumber("212-664-7665")
        n4 = PhoneNumber("7167762323")

        # Equality for n1
        self.assertEqual(n1, n1)
        self.assertNotEqual(n1, n2)
        self.assertNotEqual(n1, n3)
        self.assertEqual(n1, n4)
        self.assertEqual(n1 == n2, False)

        # Equality for n2
        self.assertNotEqual(n2, n1)
        self.assertEqual(n2, n2)
        self.assertEqual(n2, n3)
        self.assertNotEqual(n2, n4)
        self.assertEqual(n2 == n2, True)

        # Equality with other objects
        self.assertNotEqual(n1, 4)
        self.assertNotEqual(n1, str(n2))
        self.assertNotEqual(n1, [])

        # Immutability
        with self.assertRaises(Exception):
            n1.area_code = "410"
        with self.assertRaises(Exception):
            n1.prefix = "410"
        with self.assertRaises(Exception):
            n1.line_number = "4105"
        with self.assertRaises(Exception):
            n1.number = "4104104105"
        with self.assertRaises(Exception):
            n1.random_attribute = "4104104105"

        # Hashability
        self.assertEqual(
            {n1, n2, n3, n4},
            {n1, n2},
        )
        self.assertEqual(
            {n1, n2, n3, n4} - {n3},
            {n4},
        )
Exemplo n.º 3
0
    def test_string_formatting(self):
        n1 = PhoneNumber("716 776 2323")
        n2 = PhoneNumber("(212) 664-7665")

        self.assertEqual(f"{n1}", "716-776-2323")
        self.assertEqual(f"{n1:(}", "(716) 776-2323")
        self.assertEqual(f"{n1:-}", "716-776-2323")
        self.assertEqual(f"{n1: }", "716 776 2323")
        self.assertEqual(f"{n1:.}", "716.776.2323")
        self.assertEqual(f"{n1:- }", "716 - 776 - 2323")
        self.assertEqual(f"{n1:. }", "716 . 776 . 2323")
        self.assertEqual(f"{n1:+}", "+17167762323")
        self.assertEqual(f"{n1:+ }", "+1 716 776 2323")

        self.assertEqual(f"{n2:(}", "(212) 664-7665")
        self.assertEqual(f"{n2:-}", "212-664-7665")
        self.assertEqual(f"{n2: }", "212 664 7665")
        self.assertEqual(f"{n2:.}", "212.664.7665")
        self.assertEqual(f"{n2:- }", "212 - 664 - 7665")
        self.assertEqual(f"{n2:. }", "212 . 664 . 7665")
        self.assertEqual(f"{n2:+}", "+12126647665")
        self.assertEqual(f"{n2:+ }", "+1 212 664 7665")
Exemplo n.º 4
0
 def test_non_phone_numbers(self):
     with self.assertRaises(ValueError):
         PhoneNumber("57167762323")
     with self.assertRaises(ValueError):
         PhoneNumber("88-716-776-2323")
     with self.assertRaises(ValueError):
         PhoneNumber("My number is 716-776-2323")
     with self.assertRaises(ValueError):
         PhoneNumber("21 26 64 76 65")
     with self.assertRaises(ValueError):
         PhoneNumber("02126647665")
     with self.assertRaises(ValueError):
         PhoneNumber("212a664b7665")
     with self.assertRaises(ValueError):
         PhoneNumber("2126-647-665")
     self.assertEqual(str(PhoneNumber("716 7762323")), "716-776-2323")
Exemplo n.º 5
0
 def test_pretty_print(self):
     number = PhoneNumber("2234567890")
     self.assertEqual(number.pretty(), "(223) 456-7890")
Exemplo n.º 6
0
 def test_cleans_the_number(self):
     number = PhoneNumber("(223) 456-7890").number
     self.assertEqual(number, "2234567890")
Exemplo n.º 7
0
 def test_invalid_if_area_code_starts_with_0_on_valid_11_digit_number(self):
     with self.assertRaisesWithMessage(ValueError):
         PhoneNumber("1 (023) 456-7890")
Exemplo n.º 8
0
 def test_invalid_if_area_code_starts_with_1(self):
     with self.assertRaisesWithMessage(ValueError):
         PhoneNumber("(123) 456-7890")
Exemplo n.º 9
0
 def test_invalid_with_letters(self):
     with self.assertRaisesWithMessage(ValueError):
         PhoneNumber("123-abc-7890")
Exemplo n.º 10
0
 def test_valid_when_11_digits_and_starting_with_1_even_with_punctuation(
         self):
     number = PhoneNumber("+1 (223) 456-7890").number
     self.assertEqual(number, "2234567890")
Exemplo n.º 11
0
 def test_invalid_with_letters(self):
     with self.assertRaises(ValueError) as err:
         PhoneNumber("523-abc-7890")
     self.assertEqual(type(err.exception), ValueError)
     self.assertEqual(err.exception.args[0], "letters not permitted")
Exemplo n.º 12
0
 def test_invalid_when_more_than_11_digits(self):
     with self.assertRaises(ValueError) as err:
         PhoneNumber("321234567890")
     self.assertEqual(type(err.exception), ValueError)
     self.assertEqual(err.exception.args[0], "more than 11 digits")
Exemplo n.º 13
0
 def test_invalid_when_11_digits_does_not_start_with_a_1(self):
     with self.assertRaises(ValueError) as err:
         PhoneNumber("22234567890")
     self.assertEqual(type(err.exception), ValueError)
     self.assertEqual(err.exception.args[0], "11 digits must start with 1")
Exemplo n.º 14
0
 def test_invalid_when_9_digits(self):
     with self.assertRaises(ValueError) as err:
         PhoneNumber("123456789")
     self.assertEqual(type(err.exception), ValueError)
     self.assertEqual(err.exception.args[0], "incorrect number of digits")
Exemplo n.º 15
0
    'Network$Parameter non-existent or not implemented � passed on':
    49,
    'Subscriber$EKTS facility rejected by network':
    50,
    'Network$Requested facility not implemented':
    51
}

good_outcalls = dict()
total_outcalls = dict()

# ima ih 9872
for row in numbers_csv:
    #print(row)
    line_count += 1
    phone_number = PhoneNumber()
    cur_id += 1
    hash = row['PHONE_NUMBER']
    hashes_to_id[hash] = cur_id
    id_to_hashes[cur_id] = hash
    phone_number['hash'] = hash
    phone_number['id'] = cur_id
    country_id = country_to_id[code_to_country[row['OPERATOR_COUNTRY_ISO2']]]
    # DON'T ONE HOT COUNTRIES IN [1, 266]
    # phone_number['country'] = one_hot_vec(countries_num, country_id)
    phone_number['country'] = country_id
    n_type = row['NUMBER_TYPE']
    phone_type = one_hot_vec(7, number_types[n_type])
    phone_number['type'] = phone_type
    phone_number['blacklist'] = 0 if row['BLACK_LIST_FLAG'] == 'FALSE' else 1
    phone_number['a2p'] = int(row['A2P_SMS_FLAG'])
Exemplo n.º 16
0
 def test_invalid_when_11_digits_does_not_start_with_a_1(self):
     with self.assertRaisesWithMessage(ValueError):
         PhoneNumber("22234567890")
Exemplo n.º 17
0
 def test_valid_when_11_digits_and_starting_with_1(self):
     number = PhoneNumber("12234567890").number
     self.assertEqual(number, "2234567890")
Exemplo n.º 18
0
 def test_invalid_with_punctuations(self):
     with self.assertRaises(ValueError) as err:
         PhoneNumber("523-@:!-7890")
     self.assertEqual(type(err.exception), ValueError)
     self.assertEqual(err.exception.args[0], "punctuations not permitted")
Exemplo n.º 19
0
 def test_invalid_when_more_than_11_digits(self):
     with self.assertRaisesWithMessage(ValueError):
         PhoneNumber("321234567890")
Exemplo n.º 20
0
 def test_invalid_if_area_code_starts_with_1(self):
     with self.assertRaises(ValueError) as err:
         PhoneNumber("(123) 456-7890")
     self.assertEqual(type(err.exception), ValueError)
     self.assertEqual(err.exception.args[0], "area code cannot start with one")
Exemplo n.º 21
0
 def test_invalid_with_punctuations(self):
     with self.assertRaisesWithMessage(ValueError):
         PhoneNumber("123-@:!-7890")
Exemplo n.º 22
0
 def test_invalid_if_exchange_code_starts_with_0(self):
     with self.assertRaises(ValueError) as err:
         PhoneNumber("(223) 056-7890")
     self.assertEqual(type(err.exception), ValueError)
     self.assertEqual(err.exception.args[0], "exchange code cannot start with zero")
Exemplo n.º 23
0
 def test_invalid_if_exchange_code_starts_with_0(self):
     with self.assertRaisesWithMessage(ValueError):
         PhoneNumber("(223) 056-7890")
Exemplo n.º 24
0
 def test_invalid_if_area_code_starts_with_0_on_valid_11_digit_number(self):
     with self.assertRaises(ValueError) as err:
         PhoneNumber("1 (023) 456-7890")
     self.assertEqual(type(err.exception), ValueError)
     self.assertEqual(err.exception.args[0], "area code cannot start with zero")
Exemplo n.º 25
0
 def test_invalid_if_exchange_code_starts_with_1_on_valid_11_digit_number(
         self):
     with self.assertRaisesWithMessage(ValueError):
         PhoneNumber("1 (223) 156-7890")
Exemplo n.º 26
0
 def test_cleans_numbers_with_dots(self):
     number = PhoneNumber("223.456.7890").number
     self.assertEqual(number, "2234567890")
Exemplo n.º 27
0
 def test_area_code(self):
     number = PhoneNumber("2234567890")
     self.assertEqual(number.area_code, "223")
Exemplo n.º 28
0
 def test_cleans_numbers_with_multiple_spaces(self):
     number = PhoneNumber("223 456   7890   ").number
     self.assertEqual(number, "2234567890")
Exemplo n.º 29
0
 def test_pretty_print_with_full_us_phone_number(self):
     number = PhoneNumber("12234567890")
     self.assertEqual(number.pretty(), "(223) 456-7890")
Exemplo n.º 30
0
 def test_invalid_when_9_digits(self):
     with self.assertRaisesWithMessage(ValueError):
         PhoneNumber("123456789")