Example #1
0
 def test_normalize_number(self):
     """
     All numbers should be stripped of non-numeric characters and, if
     defined, should be prepended with the COUNTRY_CODE
     """
     normalized = '12223334444'
     number = '1-222-333-4444'
     self.assertEqual(normalize_number(number), normalized)
     number = '1 (222) 333-4444'
     self.assertEqual(normalize_number(number), normalized)
     with patch_settings(COUNTRY_CODE='66'):
         normalized = '662223334444'
         number = '22-23334444'
         self.assertEqual(normalize_number(number), normalized)
     with patch_settings(COUNTRY_CODE=None):
         normalized = '2223334444'
         number = '22-23334444'
         self.assertEqual(normalize_number(number), normalized)
Example #2
0
 def _associate_contact(self, connection):
     normalized_number = normalize_number(connection.identity)
     self.debug('Normalized number: {0}'.format(normalized_number))
     try:
         contact = Contact.objects.get(phone=normalized_number)
     except Contact.DoesNotExist:
         self.debug('Failed to find matching contact')
         contact = None
     if contact:
         self.debug('Associating connection to {0}'.format(contact))
         connection.contact = contact
         connection.save()
Example #3
0
 def _associate_contact(self, connection):
     normalized_number = normalize_number(connection.identity)
     self.debug('Normalized number: {0}'.format(normalized_number))
     try:
         contact = Contact.objects.get(phone=normalized_number)
     except Contact.DoesNotExist:
         self.debug('Failed to find matching contact')
         contact = None
     if contact:
         self.debug('Associating connection to {0}'.format(contact))
         connection.contact = contact
         connection.save()
Example #4
0
    def test_contact_association(self):
        number = normalize_number('13364130840', ('US',))
        connection = self.create_connection({'backend': self.backend,
                                             'identity': number})
        contact = self.create_contact()
        connection.contact = contact
        connection.save()

        other_contact = self.create_contact()
        another_connection = self.create_connection({'backend': self.backend,
                                                     'identity': '3364130840'})
        msg = self._send([another_connection], 'test')
        self.assertEqual(msg.connections[0].contact, contact)
        self.assertNotEqual(msg.connections[0].contact, other_contact)
Example #5
0
 def _normalize_number(self, number):
     return normalize_number(number)