def test_get_two_way_number(self):
    number1 = PhoneNumber.objects.create(domain=self.domain, owner_doc_type='X', owner_id='X', phone_number='999123', verified=True, pending_verification=False, is_two_way=True)
    PhoneNumber.objects.create(domain=self.domain, owner_doc_type='X', owner_id='X', phone_number='999123', verified=False, pending_verification=False, is_two_way=False)
    self.assertEqual(PhoneNumber.get_two_way_number('999123'), number1)
    self.assertEqual(PhoneNumber.get_two_way_number('+999 123'), number1)
    self.assertIsNone(PhoneNumber.get_two_way_number('999124'))
    self.assertIsNone(PhoneNumber.get_number_pending_verification('999123'))
    self.assertIsNone(PhoneNumber.get_number_pending_verification('999124'))
    self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)
    number1.phone_number = '999124'
    number1.save()
    self.assertIsNone(PhoneNumber.get_two_way_number('999123'))
    self.assertEqual(PhoneNumber.get_two_way_number('999124'), number1)
    self.assertIsNone(PhoneNumber.get_number_pending_verification('999123'))
    self.assertIsNone(PhoneNumber.get_number_pending_verification('999124'))
    self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)
    number1.delete()
    self.assertIsNone(PhoneNumber.get_two_way_number('999123'))
    self.assertIsNone(PhoneNumber.get_two_way_number('999124'))
    self.assertIsNone(PhoneNumber.get_number_pending_verification('999123'))
    self.assertIsNone(PhoneNumber.get_number_pending_verification('999124'))
    self.assertEqual(PhoneNumber.count_by_domain(self.domain), 1)
def test_get_two_way_number(self):
    number1 = PhoneNumber.objects.create(domain=self.domain, owner_doc_type='X', owner_id='X', phone_number='999123', verified=True, pending_verification=False, is_two_way=True)
    PhoneNumber.objects.create(domain=self.domain, owner_doc_type='X', owner_id='X', phone_number='999123', verified=False, pending_verification=False, is_two_way=False)
    self.assertEqual(PhoneNumber.get_two_way_number('999123'), number1)
    self.assertEqual(PhoneNumber.get_two_way_number('+999 123'), number1)
    self.assertIsNone(PhoneNumber.get_two_way_number('999124'))
    self.assertIsNone(PhoneNumber.get_number_pending_verification('999123'))
    self.assertIsNone(PhoneNumber.get_number_pending_verification('999124'))
    self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)
    number1.phone_number = '999124'
    number1.save()
    self.assertIsNone(PhoneNumber.get_two_way_number('999123'))
    self.assertEqual(PhoneNumber.get_two_way_number('999124'), number1)
    self.assertIsNone(PhoneNumber.get_number_pending_verification('999123'))
    self.assertIsNone(PhoneNumber.get_number_pending_verification('999124'))
    self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)
    number1.delete()
    self.assertIsNone(PhoneNumber.get_two_way_number('999123'))
    self.assertIsNone(PhoneNumber.get_two_way_number('999124'))
    self.assertIsNone(PhoneNumber.get_number_pending_verification('999123'))
    self.assertIsNone(PhoneNumber.get_number_pending_verification('999124'))
    self.assertEqual(PhoneNumber.count_by_domain(self.domain), 1)