本文整理汇总了Python中corehq.apps.sms.models.CommConnectCase.wrap方法的典型用法代码示例。如果您正苦于以下问题:Python CommConnectCase.wrap方法的具体用法?Python CommConnectCase.wrap怎么用?Python CommConnectCase.wrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.sms.models.CommConnectCase
的用法示例。
在下文中一共展示了CommConnectCase.wrap方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from corehq.apps.sms.models import CommConnectCase [as 别名]
# 或者: from corehq.apps.sms.models.CommConnectCase import wrap [as 别名]
def setUp(self):
super(AllBackendTest, self).setUp()
backend_api.TEST = True
self.domain_obj = Domain(name='all-backend-test')
self.domain_obj.save()
self.create_account_and_subscription(self.domain_obj.name)
self.domain_obj = Domain.get(self.domain_obj._id)
self.test_phone_number = '99912345'
self.contact1 = CommCareCase(domain=self.domain_obj.name)
self.contact1.set_case_property('contact_phone_number', self.test_phone_number)
self.contact1.set_case_property('contact_phone_number_is_verified', '1')
self.contact1.save()
self.contact1 = CommConnectCase.wrap(self.contact1.to_json())
# For use with megamobile only
self.contact2 = CommCareCase(domain=self.domain_obj.name)
self.contact2.set_case_property('contact_phone_number', '63%s' % self.test_phone_number)
self.contact2.set_case_property('contact_phone_number_is_verified', '1')
self.contact2.save()
self.contact2 = CommConnectCase.wrap(self.contact2.to_json())
self.unicel_backend = UnicelBackend(name='UNICEL', is_global=True)
self.unicel_backend.save()
self.mach_backend = MachBackend(name='MACH', is_global=True)
self.mach_backend.save()
self.tropo_backend = TropoBackend(name='TROPO', is_global=True)
self.tropo_backend.save()
self.http_backend = HttpBackend(name='HTTP', is_global=True)
self.http_backend.save()
self.telerivet_backend = TelerivetBackend(name='TELERIVET', is_global=True,
webhook_secret='telerivet-webhook-secret')
self.telerivet_backend.save()
self.test_backend = TestSMSBackend(name='TEST', is_global=True)
self.test_backend.save()
self.grapevine_backend = GrapevineBackend(name='GRAPEVINE', is_global=True)
self.grapevine_backend.save()
self.twilio_backend = TwilioBackend(name='TWILIO', is_global=True)
self.twilio_backend.save()
self.megamobile_backend = MegamobileBackend(name='MEGAMOBILE', is_global=True)
self.megamobile_backend.save()
self.smsgh_backend = SMSGHBackend(name='SMSGH', is_global=True)
self.smsgh_backend.save()
if not hasattr(settings, 'SIMPLE_API_KEYS'):
settings.SIMPLE_API_KEYS = {}
settings.SIMPLE_API_KEYS['grapevine-test'] = 'grapevine-api-key'
示例2: setUp
# 需要导入模块: from corehq.apps.sms.models import CommConnectCase [as 别名]
# 或者: from corehq.apps.sms.models.CommConnectCase import wrap [as 别名]
def setUp(self):
self.domain = "test-domain"
self.domain2 = "test-domain2"
self.domain_obj = Domain(name=self.domain)
self.domain_obj.save()
self.domain_obj = Domain.get(self.domain_obj._id) # Prevent resource conflict
self.backend1 = TestCaseBackend(name="BACKEND1",is_global=True)
self.backend1.save()
self.backend2 = TestCaseBackend(name="BACKEND2",is_global=True)
self.backend2.save()
self.backend3 = TestCaseBackend(name="BACKEND3",is_global=True)
self.backend3.save()
self.backend4 = TestCaseBackend(name="BACKEND4",is_global=True)
self.backend4.save()
self.backend5 = TestCaseBackend(name="BACKEND5",domain=self.domain,is_global=False,authorized_domains=[])
self.backend5.save()
self.backend6 = TestCaseBackend(name="BACKEND6",domain=self.domain2,is_global=False,authorized_domains=[self.domain])
self.backend6.save()
self.backend7 = TestCaseBackend(name="BACKEND7",domain=self.domain2,is_global=False,authorized_domains=[])
self.backend7.save()
self.backend8 = TestCaseBackend(name="BACKEND",domain=self.domain,is_global=False,authorized_domains=[])
self.backend8.save()
self.backend9 = TestCaseBackend(name="BACKEND",domain=self.domain2,is_global=False,authorized_domains=[self.domain])
self.backend9.save()
self.backend10 = TestCaseBackend(name="BACKEND",is_global=True)
self.backend10.save()
self.backend_mapping1 = BackendMapping(is_global=True,prefix="*",backend_id=self.backend1._id)
self.backend_mapping1.save()
self.backend_mapping2 = BackendMapping(is_global=True,prefix="1",backend_id=self.backend2._id)
self.backend_mapping2.save()
self.backend_mapping3 = BackendMapping(is_global=True,prefix="91",backend_id=self.backend3._id)
self.backend_mapping3.save()
self.backend_mapping4 = BackendMapping(is_global=True,prefix="265",backend_id=self.backend4._id)
self.backend_mapping4.save()
self.case = CommCareCase(domain=self.domain)
self.case.set_case_property("contact_phone_number","15551234567")
self.case.set_case_property("contact_phone_number_is_verified", "1")
self.case.save()
self.contact = CommConnectCase.wrap(self.case.to_json())
settings.SMS_LOADED_BACKENDS.append("corehq.apps.sms.tests.TestCaseBackend")
示例3: handle
# 需要导入模块: from corehq.apps.sms.models import CommConnectCase [as 别名]
# 或者: from corehq.apps.sms.models.CommConnectCase import wrap [as 别名]
def handle(self, *args, **options):
if len(args) == 0:
raise CommandError("Usage: python manage.py check_case_verified_numbers <domain1 domain2 ...>")
make_fixes = options["fix"]
for domain in args:
print "*** Processing Domain %s ***" % domain
for case in get_cases_in_domain(domain):
contact_phone_number = case.get_case_property("contact_phone_number")
contact_phone_number_is_verified = case.get_case_property("contact_phone_number_is_verified")
contact_backend_id = case.get_case_property("contact_backend_id")
contact_ivr_backend_id = case.get_case_property("contact_ivr_backend_id")
contact = CommConnectCase.wrap(case.to_json())
verified_numbers = contact.get_verified_numbers(include_pending=True)
should_have_entry = contact_phone_number_is_verified and contact_phone_number is not None and contact_phone_number != "" and str(contact_phone_number) != "0" and not case.closed
has_entry = len(verified_numbers) > 0
if len(verified_numbers) > 1:
print "skipping case %s, multiple verified number entries found" % case._id
continue
if has_entry:
verified_number = sorted(verified_numbers.iteritems())[0][1]
if not verified_number.verified:
print "skipping case %s, unverified number found" % case._id
continue
if has_entry and should_have_entry:
if verified_number.phone_number != contact_phone_number or verified_number.backend_id != contact_backend_id or verified_number.ivr_backend_id != contact_ivr_backend_id:
print "DISCREPANCY: case %s case properties don't match the verified number entry" % case._id
if make_fixes:
try:
contact.save_verified_number(contact.domain, contact_phone_number, True, contact_backend_id, ivr_backend_id=contact_ivr_backend_id, only_one_number_allowed=True)
except (InvalidFormatException, PhoneNumberInUseException):
contact.delete_verified_number()
elif has_entry and not should_have_entry:
print "DISCREPANCY: case %s has a verified number but should not" % case._id
if make_fixes:
contact.delete_verified_number()
elif not has_entry and should_have_entry:
try:
contact.verify_unique_number(contact_phone_number)
except InvalidFormatException:
print "DISCREPANCY: case %s does not have a verified number because number format is invalid" % case._id
except PhoneNumberInUseException:
print "DISCREPANCY: case %s does not have a verified number because number is already in use" % case._id
else:
print "DISCREPANCY: case %s does not have a verified number but should" % case._id
if make_fixes:
contact.save_verified_number(contact.domain, contact_phone_number, True, contact_backend_id, ivr_backend_id=contact_ivr_backend_id, only_one_number_allowed=True)
else:
# Doesn't have an entry, and shouldn't have an entry
pass
示例4: __test_contact_level_backend
# 需要导入模块: from corehq.apps.sms.models import CommConnectCase [as 别名]
# 或者: from corehq.apps.sms.models.CommConnectCase import wrap [as 别名]
def __test_contact_level_backend(self):
# Test sending to verified number with a contact-level backend owned by the domain
self.case.set_case_property('contact_backend_id', 'BACKEND')
self.case.save()
self.contact = CommConnectCase.wrap(self.case.to_json())
verified_number = self.contact.get_verified_number()
self.assertTrue(verified_number is not None)
self.assertEqual(verified_number.backend_id, 'BACKEND')
self.assertEqual(verified_number.phone_number, '15551234567')
with patch(
'corehq.messaging.smsbackends.test.models.SQLTestSMSBackend.send',
autospec=True
) as mock_send:
self.assertTrue(send_sms_to_verified_number(verified_number, 'Test for domain BACKEND'))
self.assertEqual(mock_send.call_count, 1)
self.assertEqual(mock_send.call_args[0][0].pk, self.backend8.pk)
# Test sending to verified number with a contact-level backend granted to the domain by another domain
self.backend8.name = 'BACKEND8'
self.backend8.save()
with patch(
'corehq.messaging.smsbackends.test.models.SQLTestSMSBackend.send',
autospec=True
) as mock_send:
self.assertTrue(send_sms_to_verified_number(verified_number, 'Test for shared domain BACKEND'))
self.assertEqual(mock_send.call_count, 1)
self.assertEqual(mock_send.call_args[0][0].pk, self.backend9.pk)
# Test sending to verified number with a contact-level global backend
self.backend9.name = 'BACKEND9'
self.backend9.save()
with patch(
'corehq.messaging.smsbackends.test.models.SQLTestSMSBackend.send',
autospec=True
) as mock_send:
self.assertTrue(send_sms_to_verified_number(verified_number, 'Test for global BACKEND'))
self.assertEqual(mock_send.call_count, 1)
self.assertEqual(mock_send.call_args[0][0].pk, self.backend10.pk)
# Test raising exception if contact-level backend is not found
self.backend10.name = 'BACKEND10'
self.backend10.save()
with self.assertRaises(BadSMSConfigException):
send_sms_to_verified_number(verified_number, 'Test for unknown BACKEND')
示例5: test_backend
# 需要导入模块: from corehq.apps.sms.models import CommConnectCase [as 别名]
# 或者: from corehq.apps.sms.models.CommConnectCase import wrap [as 别名]
#.........这里部分代码省略.........
self.assertFalse(self.backend4.invoke_doc_exists())
self.assertFalse(self.backend5.invoke_doc_exists())
self.assertFalse(self.backend6.invoke_doc_exists())
self.assertFalse(self.backend7.invoke_doc_exists())
self.assertFalse(self.backend8.invoke_doc_exists())
self.assertFalse(self.backend9.invoke_doc_exists())
self.assertFalse(self.backend10.invoke_doc_exists())
self.backend2.delete_invoke_doc()
self.assertFalse(self.backend2.invoke_doc_exists())
# Test sending to verified number with default domain backend
self.domain_obj.default_sms_backend_id = self.backend5._id
self.domain_obj.save()
self.assertTrue(send_sms_to_verified_number(verified_number, "Test for BACKEND5"))
self.assertFalse(self.backend1.invoke_doc_exists())
self.assertFalse(self.backend2.invoke_doc_exists())
self.assertFalse(self.backend3.invoke_doc_exists())
self.assertFalse(self.backend4.invoke_doc_exists())
self.assertTrue(self.backend5.invoke_doc_exists())
self.assertFalse(self.backend6.invoke_doc_exists())
self.assertFalse(self.backend7.invoke_doc_exists())
self.assertFalse(self.backend8.invoke_doc_exists())
self.assertFalse(self.backend9.invoke_doc_exists())
self.assertFalse(self.backend10.invoke_doc_exists())
self.backend5.delete_invoke_doc()
self.assertFalse(self.backend5.invoke_doc_exists())
# Test sending to verified number with a contact-level backend owned by the domain
self.case.set_case_property("contact_backend_id", "BACKEND")
self.case.save()
self.contact = CommConnectCase.wrap(self.case.to_json())
verified_number = self.contact.get_verified_number()
self.assertTrue(verified_number is not None)
self.assertEqual(verified_number.backend_id, "BACKEND")
self.assertEqual(verified_number.phone_number, "15551234567")
self.assertTrue(send_sms_to_verified_number(verified_number, "Test for BACKEND"))
self.assertFalse(self.backend1.invoke_doc_exists())
self.assertFalse(self.backend2.invoke_doc_exists())
self.assertFalse(self.backend3.invoke_doc_exists())
self.assertFalse(self.backend4.invoke_doc_exists())
self.assertFalse(self.backend5.invoke_doc_exists())
self.assertFalse(self.backend6.invoke_doc_exists())
self.assertFalse(self.backend7.invoke_doc_exists())
self.assertTrue(self.backend8.invoke_doc_exists())
self.assertFalse(self.backend9.invoke_doc_exists())
self.assertFalse(self.backend10.invoke_doc_exists())
self.backend8.delete_invoke_doc()
self.assertFalse(self.backend8.invoke_doc_exists())
# Test sending to verified number with a contact-level backend granted to the domain by another domain
self.backend8.delete()
self.assertTrue(send_sms_to_verified_number(verified_number, "Test for BACKEND"))
self.assertFalse(self.backend1.invoke_doc_exists())
self.assertFalse(self.backend2.invoke_doc_exists())
self.assertFalse(self.backend3.invoke_doc_exists())
self.assertFalse(self.backend4.invoke_doc_exists())
self.assertFalse(self.backend5.invoke_doc_exists())
self.assertFalse(self.backend6.invoke_doc_exists())
self.assertFalse(self.backend7.invoke_doc_exists())
self.assertTrue(self.backend9.invoke_doc_exists())
示例6: setUp
# 需要导入模块: from corehq.apps.sms.models import CommConnectCase [as 别名]
# 或者: from corehq.apps.sms.models.CommConnectCase import wrap [as 别名]
def setUp(self):
super(BackendTestCase, self).setUp()
self.domain = "test-domain"
self.domain2 = "test-domain2"
self.site, self.site_created = self.get_or_create_site()
self.domain_obj = Domain(name=self.domain)
self.domain_obj.save()
generator.instantiate_accounting_for_tests()
self.account = BillingAccount.get_or_create_account_by_domain(
self.domain_obj.name, created_by="automated-test"
)[0]
plan = DefaultProductPlan.get_default_plan_by_domain(self.domain_obj, edition=SoftwarePlanEdition.ADVANCED)
self.subscription = Subscription.new_domain_subscription(self.account, self.domain_obj.name, plan)
self.subscription.is_active = True
self.subscription.save()
self.domain_obj = Domain.get(self.domain_obj._id) # Prevent resource conflict
self.backend1 = TestCaseBackend(name="BACKEND1", is_global=True)
self.backend1.save()
self.backend2 = TestCaseBackend(name="BACKEND2", is_global=True)
self.backend2.save()
self.backend3 = TestCaseBackend(name="BACKEND3", is_global=True)
self.backend3.save()
self.backend4 = TestCaseBackend(name="BACKEND4", is_global=True)
self.backend4.save()
self.backend5 = TestCaseBackend(name="BACKEND5", domain=self.domain, is_global=False, authorized_domains=[])
self.backend5.save()
self.backend6 = TestCaseBackend(
name="BACKEND6", domain=self.domain2, is_global=False, authorized_domains=[self.domain]
)
self.backend6.save()
self.backend7 = TestCaseBackend(name="BACKEND7", domain=self.domain2, is_global=False, authorized_domains=[])
self.backend7.save()
self.backend8 = TestCaseBackend(name="BACKEND", domain=self.domain, is_global=False, authorized_domains=[])
self.backend8.save()
self.backend9 = TestCaseBackend(
name="BACKEND", domain=self.domain2, is_global=False, authorized_domains=[self.domain]
)
self.backend9.save()
self.backend10 = TestCaseBackend(name="BACKEND", is_global=True)
self.backend10.save()
self.backend_mapping1 = BackendMapping(is_global=True, prefix="*", backend_id=self.backend1._id)
self.backend_mapping1.save()
self.backend_mapping2 = BackendMapping(is_global=True, prefix="1", backend_id=self.backend2._id)
self.backend_mapping2.save()
self.backend_mapping3 = BackendMapping(is_global=True, prefix="91", backend_id=self.backend3._id)
self.backend_mapping3.save()
self.backend_mapping4 = BackendMapping(is_global=True, prefix="265", backend_id=self.backend4._id)
self.backend_mapping4.save()
self.backend_mapping5 = BackendMapping(is_global=True, prefix="256", backend_id=self.backend5._id)
self.backend_mapping5.save()
self.backend_mapping6 = BackendMapping(is_global=True, prefix="25670", backend_id=self.backend6._id)
self.backend_mapping6.save()
self.backend_mapping7 = BackendMapping(is_global=True, prefix="25675", backend_id=self.backend7._id)
self.backend_mapping7.save()
self.case = CommCareCase(domain=self.domain)
self.case.set_case_property("contact_phone_number", "15551234567")
self.case.set_case_property("contact_phone_number_is_verified", "1")
self.case.save()
self.contact = CommConnectCase.wrap(self.case.to_json())
settings.SMS_LOADED_BACKENDS.append("corehq.apps.sms.tests.TestCaseBackend")
示例7: setUp
# 需要导入模块: from corehq.apps.sms.models import CommConnectCase [as 别名]
# 或者: from corehq.apps.sms.models.CommConnectCase import wrap [as 别名]
#.........这里部分代码省略.........
)
self.backend5 = SQLTestSMSBackend.objects.create(
name='BACKEND5',
domain=self.domain,
is_global=False,
hq_api_id=SQLTestSMSBackend.get_api_id()
)
self.backend6 = SQLTestSMSBackend.objects.create(
name='BACKEND6',
domain=self.domain2,
is_global=False,
hq_api_id=SQLTestSMSBackend.get_api_id()
)
self.backend6.set_shared_domains([self.domain])
self.backend7 = SQLTestSMSBackend.objects.create(
name='BACKEND7',
domain=self.domain2,
is_global=False,
hq_api_id=SQLTestSMSBackend.get_api_id()
)
self.backend8 = SQLTestSMSBackend.objects.create(
name='BACKEND',
domain=self.domain,
is_global=False,
hq_api_id=SQLTestSMSBackend.get_api_id()
)
self.backend9 = SQLTestSMSBackend.objects.create(
name='BACKEND',
domain=self.domain2,
is_global=False,
hq_api_id=SQLTestSMSBackend.get_api_id()
)
self.backend9.set_shared_domains([self.domain])
self.backend10 = SQLTestSMSBackend.objects.create(
name='BACKEND',
is_global=True,
hq_api_id=SQLTestSMSBackend.get_api_id()
)
self.backend_mapping1 = SQLMobileBackendMapping.objects.create(
is_global=True,
backend_type=SQLMobileBackend.SMS,
prefix='*',
backend=self.backend1
)
self.backend_mapping2 = SQLMobileBackendMapping.objects.create(
is_global=True,
backend_type=SQLMobileBackend.SMS,
prefix='1',
backend=self.backend2
)
self.backend_mapping3 = SQLMobileBackendMapping.objects.create(
is_global=True,
backend_type=SQLMobileBackend.SMS,
prefix='91',
backend=self.backend3
)
self.backend_mapping4 = SQLMobileBackendMapping.objects.create(
is_global=True,
backend_type=SQLMobileBackend.SMS,
prefix='265',
backend=self.backend4
)
self.backend_mapping5 = SQLMobileBackendMapping.objects.create(
is_global=True,
backend_type=SQLMobileBackend.SMS,
prefix='256',
backend=self.backend5
)
self.backend_mapping6 = SQLMobileBackendMapping.objects.create(
is_global=True,
backend_type=SQLMobileBackend.SMS,
prefix='25670',
backend=self.backend6
)
self.backend_mapping7 = SQLMobileBackendMapping.objects.create(
is_global=True,
backend_type=SQLMobileBackend.SMS,
prefix='25675',
backend=self.backend7
)
self.case = CommCareCase(domain=self.domain)
self.case.set_case_property('contact_phone_number', '15551234567')
self.case.set_case_property('contact_phone_number_is_verified', '1')
self.case.save()
self.contact = CommConnectCase.wrap(self.case.to_json())