本文整理汇总了Python中temba.contacts.models.Contact.get_simulation方法的典型用法代码示例。如果您正苦于以下问题:Python Contact.get_simulation方法的具体用法?Python Contact.get_simulation怎么用?Python Contact.get_simulation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类temba.contacts.models.Contact
的用法示例。
在下文中一共展示了Contact.get_simulation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ivr_flow
# 需要导入模块: from temba.contacts.models import Contact [as 别名]
# 或者: from temba.contacts.models.Contact import get_simulation [as 别名]
#.........这里部分代码省略.........
msg = self.create_msg(direction='I', contact=eric, text="message during phone call")
self.assertFalse(Flow.find_and_handle(msg))
# updated our status and duration accordingly
call = IVRCall.objects.get(pk=call.pk)
self.assertEquals(20, call.duration)
self.assertEquals(IN_PROGRESS, call.status)
# press the number 4 (unexpected)
response = self.client.post(reverse('ivr.ivrcall_handle', args=[call.pk]), dict(Digits=4))
self.assertContains(response, '<Say>Press one, two, or three. Thanks.</Say>')
self.assertEquals(4, self.org.get_credits_used())
# two more messages, one inbound and it's response
self.assertEquals(3, Msg.all_messages.filter(msg_type=IVR).count())
# now let's have them press the number 3 (for maybe)
response = self.client.post(reverse('ivr.ivrcall_handle', args=[call.pk]), dict(Digits=3))
self.assertContains(response, '<Say>This might be crazy.</Say>')
messages = Msg.all_messages.filter(msg_type=IVR).order_by('pk')
self.assertEquals(5, messages.count())
self.assertEquals(6, self.org.get_credits_used())
for msg in messages:
self.assertEquals(1, msg.steps.all().count(), msg="Message '%s' not attached to step" % msg.text)
# twilio would then disconnect the user and notify us of a completed call
self.client.post(reverse('ivr.ivrcall_handle', args=[call.pk]), dict(CallStatus='completed'))
call = IVRCall.objects.get(pk=call.pk)
self.assertEquals(COMPLETED, call.status)
self.assertFalse(FlowRun.objects.filter(call=call).first().is_active)
# simulation gets flipped off by middleware, and this unhandled message doesn't flip it back on
self.assertFalse(Contact.get_simulation())
# also shouldn't have any ActionLogs for non-test users
self.assertEquals(0, ActionLog.objects.all().count())
self.assertEquals(1, flow.get_completed_runs())
# should still have no active runs
self.assertEquals(0, FlowRun.objects.filter(is_active=True).count())
# and we've exited the flow
step = FlowStep.objects.all().order_by('-pk').first()
self.assertTrue(step.left_on)
# test other our call status mappings with twilio
def test_status_update(call_to_update, twilio_status, temba_status):
call_to_update.update_status(twilio_status, 0)
call_to_update.save()
self.assertEquals(temba_status, IVRCall.objects.get(pk=call_to_update.pk).status)
test_status_update(call, 'queued', QUEUED)
test_status_update(call, 'ringing', RINGING)
test_status_update(call, 'canceled', CANCELED)
test_status_update(call, 'busy', BUSY)
test_status_update(call, 'failed', FAILED)
test_status_update(call, 'no-answer', NO_ANSWER)
FlowStep.objects.all().delete()
IVRCall.objects.all().delete()
# try sending callme trigger
from temba.msgs.models import INCOMING
msg = self.create_msg(direction=INCOMING, contact=eric, text="callme")
示例2: test_ivr_options
# 需要导入模块: from temba.contacts.models import Contact [as 别名]
# 或者: from temba.contacts.models.Contact import get_simulation [as 别名]
def test_ivr_options(self):
# should be able to create an ivr flow
self.assertTrue(self.org.supports_ivr())
self.assertTrue(self.admin.groups.filter(name="Beta"))
self.assertContains(self.client.get(reverse('flows.flow_create')), 'Phone Call')
# no twilio config yet
self.assertFalse(self.org.is_connected_to_twilio())
self.assertIsNone(self.org.get_twilio_client())
# connect it and check our client is configured
self.org.connect_twilio("TEST_SID", "TEST_TOKEN")
self.org.save()
self.assertTrue(self.org.is_connected_to_twilio())
self.assertIsNotNone(self.org.get_twilio_client())
# import an ivr flow
self.import_file('call-me-maybe')
# make sure our flow is there as expected
flow = Flow.objects.filter(name='Call me maybe').first()
self.assertEquals('callme', flow.triggers.all().first().keyword)
user_settings = self.admin.get_settings()
user_settings.tel = '+18005551212'
user_settings.save()
# start our flow`
eric = self.create_contact('Eric Newcomer', number='+13603621737')
eric.is_test = True
eric.save()
Contact.set_simulation(True)
flow.start([], [eric])
# should be using the usersettings number in test mode
self.assertEquals('Placing test call to +1 800-555-1212', ActionLog.objects.all().first().text)
# we should have an outbound ivr call now
call = IVRCall.objects.filter(direction=OUTGOING).first()
self.assertEquals(0, call.get_duration())
self.assertIsNotNone(call)
self.assertEquals('CallSid', call.external_id)
# after a call is picked up, twilio will call back to our server
post_data = dict(CallSid='CallSid', CallStatus='in-progress', CallDuration=20)
response = self.client.post(reverse('ivr.ivrcall_handle', args=[call.pk]), post_data)
self.assertContains(response, '<Say>Would you like me to call you? Press one for yes, two for no, or three for maybe.</Say>')
# updated our status and duration accordingly
call = IVRCall.objects.get(pk=call.pk)
self.assertEquals(20, call.duration)
self.assertEquals(IN_PROGRESS, call.status)
# should mention our our action log that we read a message to them
run = FlowRun.objects.all().first()
logs = ActionLog.objects.filter(run=run).order_by('-pk')
self.assertEquals(2, len(logs))
self.assertEquals('Read message "Would you like me to call you? Press one for yes, two for no, or three for maybe."', logs.first().text)
# press the number 4 (unexpected)
response = self.client.post(reverse('ivr.ivrcall_handle', args=[call.pk]), dict(Digits=4))
self.assertContains(response, '<Say>Press one, two, or three. Thanks.</Say>')
# now let's have them press the number 3 (for maybe)
response = self.client.post(reverse('ivr.ivrcall_handle', args=[call.pk]), dict(Digits=3))
self.assertContains(response, '<Say>This might be crazy.</Say>')
# twilio would then disconnect the user and notify us of a completed call
self.client.post(reverse('ivr.ivrcall_handle', args=[call.pk]), dict(CallStatus='completed'))
self.assertEquals(COMPLETED, IVRCall.objects.get(pk=call.pk).status)
# simulation gets flipped off by middleware, and this unhandled message doesn't flip it back on
self.assertFalse(Contact.get_simulation())
# test other our call status mappings with twilio
def test_status_update(call_to_update, twilio_status, temba_status):
call_to_update.update_status(twilio_status, 0)
call_to_update.save()
self.assertEquals(temba_status, IVRCall.objects.get(pk=call_to_update.pk).status)
test_status_update(call, 'queued', QUEUED)
test_status_update(call, 'ringing', RINGING)
test_status_update(call, 'canceled', CANCELED)
test_status_update(call, 'busy', BUSY)
test_status_update(call, 'failed', FAILED)
test_status_update(call, 'no-answer', NO_ANSWER)
# explicitly hanging up an in progress call should remove it
call.update_status('in-progress', 0)
call.save()
IVRCall.hangup_test_call(flow)
self.assertIsNone(IVRCall.objects.filter(pk=call.pk).first())