Skip to content

Commit 43e8260

Browse files
authored
Merge pull request #150 from plivo/VT-1863-mpc-changes-with-retry
Vt 1863 mpc changes with retry
2 parents 48ca383 + f15c36d commit 43e8260

10 files changed

Lines changed: 131 additions & 102 deletions

plivo/resources/multipartycall.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,16 @@ def list(self,
164164
offset=None
165165
):
166166
return self.client.request('GET', ('MultiPartyCall',), to_param_dict(self.list, locals()),
167-
response_type=ListResponseObject, objects_type=MultiPartyCall)
167+
response_type=ListResponseObject, objects_type=MultiPartyCall, is_voice_request=True)
168168

169169
@validate_args(
170170
friendly_name=[optional(of_type_exact(str))],
171171
uuid=[optional(of_type_exact(str))],
172172
)
173173
def get(self, uuid=None, friendly_name=None):
174174
mpc_id = self.__make_mpc_id(friendly_name, uuid)
175-
return self.client.request('GET', ('MultiPartyCall', mpc_id), response_type=MultiPartyCall)
175+
return self.client.request('GET', ('MultiPartyCall', mpc_id),
176+
is_voice_request=True, response_type=MultiPartyCall)
176177

177178
@validate_args(
178179
role=[of_type_exact(str), is_in(('agent', 'supervisor', 'customer'), case_sensitive=False, case_type='lower')],
@@ -295,7 +296,8 @@ def add_participant(self,
295296
if call_uuid is None and (not from_ or not to_):
296297
raise ValidationError('specify (from, to) when not adding an existing call_uuid to multi party participant')
297298
return self.client.request('POST', ('MultiPartyCall', mpc_id, 'Participant'),
298-
self.__clean_identifiers(to_param_dict(self.add_participant, locals())))
299+
self.__clean_identifiers(to_param_dict(self.add_participant, locals())),
300+
is_voice_request=True)
299301

300302
@validate_args(
301303
friendly_name=[optional(of_type_exact(str))],
@@ -311,7 +313,7 @@ def start(self, uuid=None, friendly_name=None):
311313
)
312314
def stop(self, uuid=None, friendly_name=None):
313315
mpc_id = self.__make_mpc_id(friendly_name, uuid)
314-
return self.client.request('DELETE', ('MultiPartyCall', mpc_id))
316+
return self.client.request('DELETE', ('MultiPartyCall', mpc_id), is_voice_request=True)
315317

316318
@validate_args(
317319
friendly_name=[optional(of_type_exact(str))],
@@ -329,31 +331,32 @@ def start_recording(self,
329331
status_callback_method='POST'):
330332
mpc_id = self.__make_mpc_id(friendly_name, uuid)
331333
return self.client.request('POST', ('MultiPartyCall', mpc_id, 'Record'),
332-
self.__clean_identifiers(to_param_dict(self.start_recording, locals())))
334+
self.__clean_identifiers(to_param_dict(self.start_recording, locals())),
335+
is_voice_request=True)
333336

334337
@validate_args(
335338
friendly_name=[optional(of_type_exact(str))],
336339
uuid=[optional(of_type_exact(str))],
337340
)
338341
def stop_recording(self, uuid=None, friendly_name=None):
339342
mpc_id = self.__make_mpc_id(friendly_name, uuid)
340-
return self.client.request('DELETE', ('MultiPartyCall', mpc_id, 'Record'))
343+
return self.client.request('DELETE', ('MultiPartyCall', mpc_id, 'Record'), is_voice_request=True)
341344

342345
@validate_args(
343346
friendly_name=[optional(of_type_exact(str))],
344347
uuid=[optional(of_type_exact(str))],
345348
)
346349
def pause_recording(self, uuid=None, friendly_name=None):
347350
mpc_id = self.__make_mpc_id(friendly_name, uuid)
348-
return self.client.request('POST', ('MultiPartyCall', mpc_id, 'Record', 'Pause'))
351+
return self.client.request('POST', ('MultiPartyCall', mpc_id, 'Record', 'Pause'), is_voice_request=True)
349352

350353
@validate_args(
351354
friendly_name=[optional(of_type_exact(str))],
352355
uuid=[optional(of_type_exact(str))],
353356
)
354357
def resume_recording(self, uuid=None, friendly_name=None):
355358
mpc_id = self.__make_mpc_id(friendly_name, uuid)
356-
return self.client.request('POST', ('MultiPartyCall', mpc_id, 'Record', 'Resume'))
359+
return self.client.request('POST', ('MultiPartyCall', mpc_id, 'Record', 'Resume'), is_voice_request=True)
357360

358361
@validate_args(
359362
friendly_name=[optional(of_type_exact(str))],
@@ -364,7 +367,8 @@ def list_participants(self, uuid=None, friendly_name=None, call_uuid=None):
364367
mpc_id = self.__make_mpc_id(friendly_name, uuid)
365368
return self.client.request('GET', ('MultiPartyCall', mpc_id, 'Participant'),
366369
self.__clean_identifiers(to_param_dict(self.list_participants, locals())),
367-
response_type=ListResponseObject, objects_type=MultiPartyCallParticipant)
370+
response_type=ListResponseObject, objects_type=MultiPartyCallParticipant,
371+
is_voice_request=True)
368372

369373
@validate_args(
370374
participant_id=[one_of(of_type_exact(str), of_type_exact(int))],
@@ -381,7 +385,8 @@ def update_participant(self, participant_id, uuid=None, friendly_name=None, coac
381385
if all(u is None for u in [coach_mode, mute, hold]):
382386
raise ValidationError('update at least one of coach_mode, mute or hold')
383387
return self.client.request('POST', ('MultiPartyCall', mpc_id, 'Participant', participant_id),
384-
self.__clean_identifiers(to_param_dict(self.update_participant, locals())))
388+
self.__clean_identifiers(to_param_dict(self.update_participant, locals())),
389+
is_voice_request=True)
385390

386391
@validate_args(
387392
participant_id=[one_of(of_type_exact(str), of_type_exact(int))],
@@ -390,7 +395,8 @@ def update_participant(self, participant_id, uuid=None, friendly_name=None, coac
390395
)
391396
def kick_participant(self, participant_id, uuid=None, friendly_name=None):
392397
mpc_id = self.__make_mpc_id(friendly_name, uuid)
393-
return self.client.request('DELETE', ('MultiPartyCall', mpc_id, 'Participant', participant_id))
398+
return self.client.request('DELETE', ('MultiPartyCall', mpc_id, 'Participant', participant_id),
399+
is_voice_request=True)
394400

395401
@validate_args(
396402
participant_id=[one_of(of_type_exact(str), of_type_exact(int))],
@@ -400,4 +406,4 @@ def kick_participant(self, participant_id, uuid=None, friendly_name=None):
400406
def get_participant(self, participant_id, uuid=None, friendly_name=None):
401407
mpc_id = self.__make_mpc_id(friendly_name, uuid)
402408
return self.client.request('GET', ('MultiPartyCall', mpc_id, 'Participant', participant_id),
403-
response_type=MultiPartyCallParticipant)
409+
response_type=MultiPartyCallParticipant, is_voice_request=True)

tests/base.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,24 @@ def get_url(self, *args, **kwargs):
7575
'/' + '/'.join([quote_plus(arg)
7676
for arg in args]) + '/?' + urlencode(kwargs)
7777

78+
def get_voice_url(self, *args, **kwargs):
79+
return 'https://voice.plivo.com/v1/Account/' + \
80+
self.client.session.auth[0] + \
81+
'/' + '/'.join([quote_plus(arg)
82+
for arg in args]) + '/?' + urlencode(kwargs)
83+
84+
def get_voice_fallback1_url(self, *args, **kwargs):
85+
return 'https://voice-usw1.plivo.com/v1/Account/' + \
86+
self.client.session.auth[0] + \
87+
'/' + '/'.join([quote_plus(arg)
88+
for arg in args]) + '/?' + urlencode(kwargs)
89+
90+
def get_voice_fallback2_url(self, *args, **kwargs):
91+
return 'https://voice-use1.plivo.com/v1/Account/' + \
92+
self.client.session.auth[0] + \
93+
'/' + '/'.join([quote_plus(arg)
94+
for arg in args]) + '/?' + urlencode(kwargs)
95+
7896

7997
class PlivoRequestTest(TestCase):
8098
def setUp(self):
Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
{
2-
"api_id": "4cef1272-9b03-11ea-bd46-1094bbeb5c2c",
3-
"billed_amount": 0.03,
4-
"billed_duration": 60,
5-
"call_uuid": "b5f23171-ea7f-40e5-9131-d68bf7867020",
6-
"coach_mode": null,
7-
"duration": 19800,
8-
"end_on_exit": false,
9-
"exit_time": "2020-05-19 03:32:51+05:30",
10-
"hold": null,
11-
"join_time": "2020-05-18 22:02:51+05:30",
12-
"member_id": "12",
13-
"mpc_uuid": "9aad6d16-ed2c-4433-9313-26f8cfc4d99c",
14-
"mute": null,
15-
"resource_uri": "/v1/Account/MAXXXXXXXXXXXXXXXXXX/MultiPartyCall/uuid_9aad6d16-ed2c-4433-9313-26f8cfc4d99c/Participant/12/",
16-
"role": "agent",
17-
"start_on_enter": false
2+
"api_id": "07a25e47-c1e3-11ea-ae24-0242ac110004",
3+
"billed_amount": 0.00500,
4+
"billed_duration": 60,
5+
"call_uuid": "90de6710-9404-40d1-ba31-f26d2f7c533f",
6+
"coach_mode": null,
7+
"duration": 30,
8+
"end_mpc_on_exit": false,
9+
"exit_cause": "Participant Call Hangup",
10+
"exit_time": "2020-07-09 07:25:07+00:00",
11+
"hold": null,
12+
"join_time": "2020-07-09 07:24:37+00:00",
13+
"member_id": "49",
14+
"mpc_uuid": "18905d56-79c8-41d4-a840-25feff71070e",
15+
"mute": null,
16+
"resource_uri": "/v1/Account/MA123456789012345678/MultiPartyCall/uuid_18905d56-79c8-41d4-a840-25feff71070e/Participant/49/",
17+
"role": "customer",
18+
"start_mpc_on_enter": true
1819
}

tests/resources/test_applications.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def test_application_create_with_subaccount_object(self):
7272

7373
# Verifying the endpoint hit
7474
self.assertEqual(
75-
'https://api.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Application/',
75+
'https://voice.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Application/',
7676
self.client.current_request.url)
7777

7878
# Verifying the method used
@@ -93,7 +93,7 @@ def test_create(self):
9393

9494
# Verifying the endpoint hit
9595
self.assertEqual(
96-
'https://api.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Application/',
96+
'https://voice.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Application/',
9797
self.client.current_request.url)
9898

9999
# Verifying the method used
@@ -112,7 +112,7 @@ def test_get(self):
112112

113113
# Verifying the endpoint hit
114114
self.assertEqual(
115-
'https://api.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Application/20468599130939380/',
115+
'https://voice.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Application/20468599130939380/',
116116
self.client.current_request.url)
117117

118118
# Verifying the method used
@@ -139,7 +139,7 @@ def test_application_delete(self):
139139

140140
# Verifying the endpoint hit
141141
self.assertEqual(
142-
'https://api.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Application/20372631212782780/',
142+
'https://voice.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Application/20372631212782780/',
143143
self.client.current_request.url)
144144

145145
# Verifying the method used
@@ -180,7 +180,7 @@ def test_application_update(self):
180180

181181
# Verifying the endpoint hit
182182
self.assertEqual(
183-
'https://api.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Application/20372631212782780/',
183+
'https://voice.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Application/20372631212782780/',
184184
self.client.current_request.url)
185185

186186
# Verifying the method used
@@ -233,7 +233,7 @@ def test_application_update_with_subaccount_object(self):
233233

234234
# Verifying the endpoint hit
235235
self.assertEqual(
236-
'https://api.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Application/20372631212782780/',
236+
'https://voice.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Application/20372631212782780/',
237237
self.client.current_request.url)
238238

239239
# Verifying the method used
@@ -299,7 +299,7 @@ def test_application_update_by_object(self):
299299

300300
# Verifying the endpoint hit
301301
self.assertEqual(
302-
'https://api.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Application/20372631212782780/',
302+
'https://voice.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Application/20372631212782780/',
303303
self.client.current_request.url)
304304

305305
# Verifying the method used
@@ -423,7 +423,7 @@ def test_application_list(self):
423423

424424
# Verifying the endpoint hit
425425
self.assertUrlEqual(
426-
'https://api.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Application/?limit=10&offset=10',
426+
'https://voice.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Application/?limit=10&offset=10',
427427
self.client.current_request.url)
428428

429429
# Verifying the method used
@@ -439,7 +439,7 @@ def test_application_list(self):
439439
offset=10, limit=10, subaccount='SAXXXXXXXXXXXXXXXXXX')
440440

441441
self.assertUrlEqual(
442-
'https://api.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Application/?limit=10&subaccount=SAXXXXXXXXXXXXXXXXXX&offset=10',
442+
'https://voice.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Application/?limit=10&subaccount=SAXXXXXXXXXXXXXXXXXX&offset=10',
443443
self.client.current_request.url)
444444

445445
# Verifying the method used
@@ -452,7 +452,7 @@ def test_application_list(self):
452452
offset=10, limit=10, subaccount=account_details)
453453

454454
self.assertUrlEqual(
455-
'https://api.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Application/?limit=10&subaccount=SAXXXXXXXXXXXXXXXXXX&offset=10',
455+
'https://voice.plivo.com/v1/Account/MAXXXXXXXXXXXXXXXXXX/Application/?limit=10&subaccount=SAXXXXXXXXXXXXXXXXXX&offset=10',
456456
self.client.current_request.url)
457457

458458
# Verifying the method used

tests/resources/test_calls.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,24 @@
77

88

99
class CallTest(PlivoResourceTestCase):
10-
@with_response(200)
10+
@with_response(503)
11+
@with_response(503)
12+
@with_response(201)
1113
def test_create(self):
1214
self.client.calls.create(
1315
from_='1231231230',
1416
to_='3213213210',
1517
answer_url='http://www.example.com')
1618
self.assertEqual(self.client.current_request.method, 'POST')
1719
self.assertUrlEqual(
18-
self.get_url('Call'), self.client.current_request.url)
20+
self.get_voice_url('Call'), self.client.current_request.url)
1921

2022
@with_response(200)
2123
def test_list(self):
2224
self.client.calls.list()
2325
self.assertEqual(self.client.current_request.method, 'GET')
2426
self.assertUrlEqual(
25-
self.get_url('Call', limit=20, offset=0),
27+
self.get_voice_url('Call', limit=20, offset=0),
2628
self.client.current_request.url)
2729

2830
@with_response(200)
@@ -32,7 +34,7 @@ def test_get(self):
3234
self.assertResponseMatches(call)
3335
self.assertEqual(self.client.current_request.method, 'GET')
3436
self.assertUrlEqual(
35-
self.get_url('Call', uuid), self.client.current_request.url)
37+
self.get_voice_url('Call', uuid), self.client.current_request.url)
3638

3739
@with_response(202)
3840
def test_update(self):
@@ -41,7 +43,7 @@ def test_update(self):
4143
uuid, legs='aleg', aleg_url='http://www.example.com')
4244
self.assertEqual(self.client.current_request.method, 'POST')
4345
self.assertUrlEqual(
44-
self.get_url('Call', uuid), self.client.current_request.url)
46+
self.get_voice_url('Call', uuid), self.client.current_request.url)
4547

4648

4749
class LiveCallTest(PlivoResourceTestCase):
@@ -50,69 +52,69 @@ def test_play_create(self):
5052
self.client.calls.play(uuid, 'http://test.url')
5153
self.assertEqual(self.client.current_request.method, 'POST')
5254
self.assertUrlEqual(
53-
self.get_url('Call', uuid, 'Play'),
55+
self.get_voice_url('Call', uuid, 'Play'),
5456
self.client.current_request.url)
5557

5658
@with_response(204)
5759
def test_play_delete(self):
5860
self.client.calls.play_stop(uuid)
5961
self.assertEqual(self.client.current_request.method, 'DELETE')
6062
self.assertUrlEqual(
61-
self.get_url('Call', uuid, 'Play'),
63+
self.get_voice_url('Call', uuid, 'Play'),
6264
self.client.current_request.url)
6365

6466
@with_response(202)
6567
def test_record_create(self):
6668
self.client.calls.record(uuid, 'http://test.url')
6769
self.assertEqual(self.client.current_request.method, 'POST')
6870
self.assertUrlEqual(
69-
self.get_url('Call', uuid, 'Record'),
71+
self.get_voice_url('Call', uuid, 'Record'),
7072
self.client.current_request.url)
7173

7274
@with_response(204)
7375
def test_record_delete(self):
7476
self.client.calls.record_stop(uuid)
7577
self.assertEqual(self.client.current_request.method, 'DELETE')
7678
self.assertUrlEqual(
77-
self.get_url('Call', uuid, 'Record'),
79+
self.get_voice_url('Call', uuid, 'Record'),
7880
self.client.current_request.url)
7981

8082
@with_response(202)
8183
def test_dtmf_create(self):
8284
self.client.calls.send_digits(uuid, '123')
8385
self.assertEqual(self.client.current_request.method, 'POST')
8486
self.assertUrlEqual(
85-
self.get_url('Call', uuid, 'DTMF'),
87+
self.get_voice_url('Call', uuid, 'DTMF'),
8688
self.client.current_request.url)
8789

8890
@with_response(202)
8991
def test_play_create(self):
9092
self.client.calls.play(uuid, 'http://test.url')
9193
self.assertEqual(self.client.current_request.method, 'POST')
9294
self.assertUrlEqual(
93-
self.get_url('Call', uuid, 'Play'),
95+
self.get_voice_url('Call', uuid, 'Play'),
9496
self.client.current_request.url)
9597

9698
@with_response(204)
9799
def test_play_delete(self):
98100
self.client.calls.play_stop(uuid)
99101
self.assertEqual(self.client.current_request.method, 'DELETE')
100102
self.assertUrlEqual(
101-
self.get_url('Call', uuid, 'Play'),
103+
self.get_voice_url('Call', uuid, 'Play'),
102104
self.client.current_request.url)
103105

104106
@with_response(202)
105107
def test_speak_create(self):
106108
self.client.calls.speak(uuid, 'http://test.url')
107109
self.assertEqual(self.client.current_request.method, 'POST')
108110
self.assertUrlEqual(
109-
self.get_url('Call', uuid, 'Speak'),
111+
self.get_voice_url('Call', uuid, 'Speak'),
110112
self.client.current_request.url)
111113

112114
@with_response(204)
113115
def test_speak_delete(self):
114116
self.client.calls.speak_stop(uuid)
115117
self.assertEqual(self.client.current_request.method, 'DELETE')
116118
self.assertUrlEqual(
117-
self.get_url('Call', uuid, 'Speak'),
119+
self.get_voice_url('Call', uuid, 'Speak'),
118120
self.client.current_request.url)

0 commit comments

Comments
 (0)