本文整理汇总了Python中corehq.apps.sms.models.PhoneNumber.save方法的典型用法代码示例。如果您正苦于以下问题:Python PhoneNumber.save方法的具体用法?Python PhoneNumber.save怎么用?Python PhoneNumber.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.sms.models.PhoneNumber
的用法示例。
在下文中一共展示了PhoneNumber.save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testSQLSyncToCouch
# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import save [as 别名]
def testSQLSyncToCouch(self):
self.assertEqual(self.getCouchCount(), 0)
self.assertEqual(self.getSQLCount(), 0)
# Test Create
sql_obj = PhoneNumber()
self.setRandomSQLObjectValues(sql_obj)
sql_obj.save()
sleep(1)
self.assertEqual(self.getCouchCount(), 1)
self.assertEqual(self.getSQLCount(), 1)
couch_obj = VerifiedNumber.get(sql_obj.couch_id)
self.checkFieldValues(couch_obj, sql_obj, PhoneNumber._migration_get_fields())
self.assertTrue(VerifiedNumber.get_db().get_rev(couch_obj._id).startswith('2-'))
# Test Update
self.setRandomSQLObjectValues(sql_obj)
sql_obj.save()
sleep(1)
self.assertEqual(self.getCouchCount(), 1)
self.assertEqual(self.getSQLCount(), 1)
couch_obj = VerifiedNumber.get(sql_obj.couch_id)
self.checkFieldValues(couch_obj, sql_obj, PhoneNumber._migration_get_fields())
self.assertTrue(VerifiedNumber.get_db().get_rev(couch_obj._id).startswith('3-'))
# Test Delete
couch_id = couch_obj._id
sql_obj.delete()
with self.assertRaises(ResourceNotFound):
VerifiedNumber.get(couch_id)
self.assertEqual(self.getCouchCount(), 0)
self.assertEqual(self.getSQLCount(), 0)
示例2: test_sms
# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import save [as 别名]
def test_sms(self):
from corehq.apps.sms.models import PhoneNumber, MessagingEvent, MessagingSubEvent
expected_object_counts = Counter({PhoneNumber: 1, MessagingEvent: 1, MessagingSubEvent: 1})
phone_number = PhoneNumber(
domain=self.domain_name,
owner_doc_type='CommCareCase',
owner_id='fake-owner-id1',
phone_number='99912341234',
backend_id=None,
ivr_backend_id=None,
verified=True,
is_two_way=True,
pending_verification=False,
contact_last_modified=datetime.utcnow()
)
phone_number.save()
event = MessagingEvent.objects.create(
domain=self.domain_name,
date=datetime.utcnow(),
source=MessagingEvent.SOURCE_REMINDER,
content_type=MessagingEvent.CONTENT_SMS,
status=MessagingEvent.STATUS_COMPLETED
)
MessagingSubEvent.objects.create(
parent=event,
date=datetime.utcnow(),
recipient_type=MessagingEvent.RECIPIENT_CASE,
content_type=MessagingEvent.CONTENT_SMS,
status=MessagingEvent.STATUS_COMPLETED
)
self._dump_and_load(expected_object_counts)
示例3: save_verified_number
# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import save [as 别名]
def save_verified_number(self, domain, phone_number, verified, backend_id=None, ivr_backend_id=None, only_one_number_allowed=False):
"""
Saves the given phone number as this contact's verified phone number.
backend_id - the name of an SMSBackend to use when sending SMS to
this number; if specified, this will override any project or
global settings for which backend will be used to send sms to
this number
return The PhoneNumber
raises InvalidFormatException if the phone number format is invalid
raises PhoneNumberInUseException if the phone number is already in use by another contact
"""
from corehq.apps.sms.models import PhoneNumber
phone_number = apply_leniency(phone_number)
self.verify_unique_number(phone_number)
if only_one_number_allowed:
v = self.get_verified_number()
else:
v = self.get_verified_number(phone_number)
if v is None:
v = PhoneNumber(
owner_doc_type=self.doc_type,
owner_id=self.get_id
)
v.domain = domain
v.phone_number = phone_number
v.verified = verified
v.backend_id = backend_id
v.ivr_backend_id = ivr_backend_id
v.save()
示例4: _sync_case_phone_number
# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import save [as 别名]
def _sync_case_phone_number(contact_case):
phone_info = contact_case.get_phone_info()
lock_keys = ['sync-case-phone-number-for-%s' % contact_case.case_id]
if phone_info.phone_number:
lock_keys.append('verifying-phone-number-%s' % phone_info.phone_number)
with CriticalSection(lock_keys, timeout=5 * 60):
phone_number = contact_case.get_verified_number()
if (
phone_number and
phone_number.contact_last_modified and
phone_number.contact_last_modified >= contact_case.server_modified_on
):
return
if phone_info.requires_entry:
try:
contact_case.verify_unique_number(phone_info.phone_number)
except (InvalidFormatException, PhoneNumberInUseException):
if phone_number:
phone_number.delete()
return
if not phone_number:
phone_number = PhoneNumber(
domain=contact_case.domain,
owner_doc_type=contact_case.doc_type,
owner_id=contact_case.case_id,
)
elif _phone_number_is_same(phone_number, phone_info):
return
phone_number.phone_number = phone_info.phone_number
phone_number.backend_id = phone_info.sms_backend_id
phone_number.ivr_backend_id = phone_info.ivr_backend_id
phone_number.verified = True
phone_number.contact_last_modified = contact_case.server_modified_on
phone_number.save()
else:
if phone_number:
phone_number.delete()
示例5: _test_cache_clear
# 需要导入模块: from corehq.apps.sms.models import PhoneNumber [as 别名]
# 或者: from corehq.apps.sms.models.PhoneNumber import save [as 别名]
def _test_cache_clear(self, refresh_each_time=True):
"""
A test to make sure that the cache clearing is working as expected.
This test gets run twice using different values for refresh_each_time.
This makes sure that the mechanism used for clearing the cache works
whether you're updating a document you just saved or getting a document
fresh from the database and updating it.
"""
created = PhoneNumber(
domain='phone-number-test',
owner_doc_type='CommCareCase',
owner_id='fake-owner-id1',
phone_number='99912341234',
backend_id=None,
ivr_backend_id=None,
verified=True,
pending_verification=False,
is_two_way=True,
contact_last_modified=datetime.utcnow()
)
created.save()
self.assertNoMatch('99952345234', '52345234', 'fake-owner-id2')
self.assertMatch(created, '99912341234', '12341234', 'fake-owner-id1')
# Update Phone Number
if refresh_each_time:
created = PhoneNumber.objects.get(pk=created.pk)
created.phone_number = '99952345234'
created.save()
self.assertNoMatch('99912341234', '12341234', 'fake-owner-id2')
self.assertMatch(created, '99952345234', '52345234', 'fake-owner-id1')
# Update Owner Id
if refresh_each_time:
created = PhoneNumber.objects.get(pk=created.pk)
created.owner_id = 'fake-owner-id2'
created.save()
self.assertNoMatch('99912341234', '12341234', 'fake-owner-id1')
self.assertMatch(created, '99952345234', '52345234', 'fake-owner-id2')
created.delete()
self.assertNoMatch('99952345234', '52345234', 'fake-owner-id2')