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)
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)
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): 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) 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)
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): 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) 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)