Beispiel #1
0
class PhoneTest(GroupCreateDataTest):

    def setUp(self):
        self.backend = self.create_backend(data={'name': 'test-backend'})
        self.router = TestRouterMixin()
        self.app = GroupsApp(router=self.router)

    def _send(self, conn, text):
        msg = IncomingMessage(conn, text)
        self.app.filter(msg)
        return msg

    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)
Beispiel #2
0
class PhoneTest(GroupCreateDataTest):

    def setUp(self):
        self.backend = self.create_backend(data={'name': 'test-backend'})
        self.router = MockRouter()
        self.app = GroupsApp(router=self.router)

    def test_valid_phone(self):
        valid_numbers = ('12223334444', '112223334444', '1112223334444')
        for number in valid_numbers:
            self.assertEqual(None, validate_phone(number))

    def test_invalid_phone(self):
        invalid_numbers = ('2223334444', '11112223334444')
        for number in invalid_numbers:
            self.assertRaises(ValidationError, validate_phone, number)

    def _send(self, conn, text):
        msg = IncomingMessage(conn, text)
        self.app.filter(msg)
        return msg

    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)

    def test_contact_association(self):
        number = '1112223334444'
        contact = self.create_contact({'phone': number})
        other_contact = self.create_contact()
        connection = self.create_connection({'backend': self.backend,
                                             'identity': '+111-222-333-4444'})
        msg = self._send(connection, 'test')
        self.assertEqual(msg.connection.contact_id, contact.id)
        self.assertNotEqual(msg.connection.contact_id, other_contact.id)
Beispiel #3
0
class PhoneTest(GroupCreateDataTest):
    def setUp(self):
        self.backend = self.create_backend(data={"name": "test-backend"})
        self.router = MockRouter()
        self.app = GroupsApp(router=self.router)

    def test_valid_phone(self):
        valid_numbers = ("12223334444", "112223334444", "1112223334444")
        for number in valid_numbers:
            self.assertEqual(None, validate_phone(number))

    def test_invalid_phone(self):
        invalid_numbers = ("2223334444", "11112223334444")
        for number in invalid_numbers:
            self.assertRaises(ValidationError, validate_phone, number)

    def _send(self, conn, text):
        msg = IncomingMessage(conn, text)
        self.app.filter(msg)
        return msg

    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(self.app._normalize_number(number), normalized)
        number = "1 (222) 333-4444"
        self.assertEqual(self.app._normalize_number(number), normalized)
        with patch_settings(COUNTRY_CODE="66"):
            normalized = "662223334444"
            number = "22-23334444"
            self.assertEqual(self.app._normalize_number(number), normalized)
        with patch_settings(COUNTRY_CODE=None):
            normalized = "2223334444"
            number = "22-23334444"
            self.assertEqual(self.app._normalize_number(number), normalized)

    def test_contact_association(self):
        number = "1112223334444"
        contact = self.create_contact({"phone": number})
        other_contact = self.create_contact()
        connection = self.create_connection({"backend": self.backend, "identity": "+111-222-333-4444"})
        msg = self._send(connection, "test")
        self.assertEqual(msg.connection.contact_id, contact.id)
        self.assertNotEqual(msg.connection.contact_id, other_contact.id)
Beispiel #4
0
 def setUp(self):
     self.backend = self.create_backend(data={'name': 'test-backend'})
     self.router = MockRouter()
     self.app = GroupsApp(router=self.router)
Beispiel #5
0
 def setUp(self):
     self.backend = self.create_backend(data={'name': 'test-backend'})
     self.router = MockRouter()
     self.app = GroupsApp(router=self.router)
Beispiel #6
0
 def setUp(self):
     self.backend = self.create_backend(data={"name": "test-backend"})
     self.router = MockRouter()
     self.app = GroupsApp(router=self.router)