本文整理汇总了Python中corehq.apps.sms.models.PhoneNumber.count_by_domain方法的典型用法代码示例。如果您正苦于以下问题:Python PhoneNumber.count_by_domain方法的具体用法?Python PhoneNumber.count_by_domain怎么用?Python PhoneNumber.count_by_domain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.sms.models.PhoneNumber
的用法示例。
在下文中一共展示了PhoneNumber.count_by_domain方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_number_pending_verification
# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import count_by_domain [as 别名]
def test_get_number_pending_verification(self):
number1 = PhoneNumber.objects.create(
domain=self.domain,
owner_doc_type='X',
owner_id='X',
phone_number='999123',
verified=False,
pending_verification=True,
is_two_way=False
)
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.assertIsNone(PhoneNumber.get_two_way_number('999123'))
self.assertIsNone(PhoneNumber.get_two_way_number('999124'))
self.assertEqual(PhoneNumber.get_number_pending_verification('999123'), number1)
self.assertEqual(PhoneNumber.get_number_pending_verification('+999 123'), number1)
self.assertIsNone(PhoneNumber.get_number_pending_verification('999124'))
self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)
# test cache clear on save
number1.phone_number = '999124'
number1.save()
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.assertEqual(PhoneNumber.get_number_pending_verification('999124'), number1)
self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)
# test promotion to two-way
number1.set_two_way()
number1.set_verified()
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)
# test cache clear on delete
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)
示例2: test_delete_phone_numbers_for_owners
# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import count_by_domain [as 别名]
def test_delete_phone_numbers_for_owners(self):
with self.create_case_contact('9990001') as case1, \
self.create_case_contact('9990002') as case2, \
self.create_case_contact('9990003') as case3:
self.assertEqual(len(PhoneNumber.by_owner_id(case1.case_id)), 1)
self.assertEqual(len(PhoneNumber.by_owner_id(case2.case_id)), 1)
self.assertEqual(len(PhoneNumber.by_owner_id(case3.case_id)), 1)
self.assertEqual(PhoneNumber.count_by_domain(self.domain), 3)
delete_phone_numbers_for_owners([case2.case_id, case3.case_id])
self.assertEqual(len(PhoneNumber.by_owner_id(case1.case_id)), 1)
self.assertEqual(len(PhoneNumber.by_owner_id(case2.case_id)), 0)
self.assertEqual(len(PhoneNumber.by_owner_id(case3.case_id)), 0)
self.assertEqual(PhoneNumber.count_by_domain(self.domain), 1)
示例3: test_phone_number_already_in_use
# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import count_by_domain [as 别名]
def test_phone_number_already_in_use(self):
self.assertEqual(PhoneNumber.count_by_domain(self.domain), 0)
with create_test_case(self.domain, 'participant', 'test1', drop_signals=False) as case1, \
create_test_case(self.domain, 'participant', 'test2', drop_signals=False) as case2:
case1 = self.set_case_property(case1, 'contact_phone_number', '99987658765')
case1 = self.set_case_property(case1, 'contact_phone_number_is_verified', '1')
case2 = self.set_case_property(case2, 'contact_phone_number', '99987698769')
case2 = self.set_case_property(case2, 'contact_phone_number_is_verified', '1')
self.assertIsNotNone(self.get_case_phone_number(case1))
self.assertIsNotNone(self.get_case_phone_number(case2))
self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)
case2 = self.set_case_property(case2, 'contact_phone_number', '99987658765')
self.assertIsNotNone(self.get_case_phone_number(case1))
self.assertIsNotNone(self.get_case_phone_number(case2))
self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)
self.assertPhoneNumberDetails(case1, '99987658765', None, None, True, False, True)
self.assertPhoneNumberDetails(case2, '99987658765', None, None, False, False, False)
示例4: test_invalid_phone_format
# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import count_by_domain [as 别名]
def test_invalid_phone_format(self):
extra_number = 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
)
self.assertEqual(PhoneNumber.count_by_domain(self.domain), 1)
with create_test_case(self.domain, 'participant', 'test1', drop_signals=False) as case:
case = self.set_case_property(case, 'contact_phone_number', '99987658765')
case = self.set_case_property(case, 'contact_phone_number_is_verified', '1')
self.assertIsNotNone(self.get_case_phone_number(case))
self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)
case = self.set_case_property(case, 'contact_phone_number', 'xyz')
self.assertIsNone(self.get_case_phone_number(case))
self.assertEqual(PhoneNumber.count_by_domain(self.domain), 1)
self.assertEqual(PhoneNumber.get_two_way_number('999123'), extra_number)
示例5: test_case_soft_delete
# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import count_by_domain [as 别名]
def test_case_soft_delete(self):
extra_number = 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
)
self.assertEqual(PhoneNumber.count_by_domain(self.domain), 1)
with create_test_case(self.domain, 'participant', 'test1', drop_signals=False) as case:
case = self.set_case_property(case, 'contact_phone_number', '99987658765')
case = self.set_case_property(case, 'contact_phone_number_is_verified', '1')
self.assertIsNotNone(self.get_case_phone_number(case))
self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)
tag_cases_as_deleted_and_remove_indices(self.domain, [case.case_id], '123', datetime.utcnow())
self.assertIsNone(self.get_case_phone_number(case))
self.assertEqual(PhoneNumber.count_by_domain(self.domain), 1)
self.assertEqual(PhoneNumber.get_two_way_number('999123'), extra_number)
示例6: test_case_phone_number_updates
# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import count_by_domain [as 别名]
def test_case_phone_number_updates(self):
extra_number = 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
)
self.assertEqual(PhoneNumber.count_by_domain(self.domain), 1)
with create_test_case(self.domain, 'participant', 'test1', drop_signals=False) as case:
self.assertIsNone(self.get_case_phone_number(case))
case = self.set_case_property(case, 'contact_phone_number', '99987658765')
self.assertPhoneNumberDetails(case, '99987658765', None, None, False, False, False)
pk = self.get_case_phone_number(case).pk
self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)
case = self.set_case_property(case, 'contact_phone_number_is_verified', '1')
self.assertPhoneNumberDetails(case, '99987658765', None, None, True, False, True, pk=pk)
self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)
case = self.set_case_property(case, 'contact_phone_number', '99987698769')
self.assertPhoneNumberDetails(case, '99987698769', None, None, True, False, True)
pk = self.get_case_phone_number(case).pk
self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)
case = self.set_case_property(case, 'contact_backend_id', 'sms-backend')
self.assertPhoneNumberDetails(case, '99987698769', 'sms-backend', None, True, False, True, pk=pk)
self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)
case = self.set_case_property(case, 'contact_ivr_backend_id', 'ivr-backend')
self.assertPhoneNumberDetails(case, '99987698769', 'sms-backend', 'ivr-backend', True, False, True,
pk=pk)
self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)
# If phone entry is ahead of the case in terms of contact_last_modified, no update should happen
v = self.get_case_phone_number(case)
v.contact_last_modified += timedelta(days=1)
v.save()
with patch('corehq.apps.sms.models.PhoneNumber.save') as mock_save:
case = self.set_case_property(case, 'contact_phone_number', '99912341234')
self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)
mock_save.assert_not_called()
self.assertEqual(PhoneNumber.get_two_way_number('999123'), extra_number)
示例7: test_by_domain
# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import count_by_domain [as 别名]
def test_by_domain(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
)
number2 = PhoneNumber.objects.create(
domain=self.domain,
owner_doc_type='X',
owner_id='X',
phone_number='999124',
verified=False,
pending_verification=False,
is_two_way=False
)
number3 = PhoneNumber.objects.create(
domain=self.domain + 'X',
owner_doc_type='X',
owner_id='X',
phone_number='999124',
verified=True,
pending_verification=False,
is_two_way=True
)
self.addCleanup(number3.delete)
self.assertEqual(
set(PhoneNumber.by_domain(self.domain)),
set([number1, number2])
)
self.assertEqual(
set(PhoneNumber.by_domain(self.domain, ids_only=True)),
set([number1.couch_id, number2.couch_id])
)
self.assertEqual(PhoneNumber.count_by_domain(self.domain), 2)