|
| 1 | +import json |
1 | 2 | from os.path import abspath |
2 | 3 |
|
3 | 4 | import responses |
|
8 | 9 | AudioStreamOptions, |
9 | 10 | CreateCallRequest, |
10 | 11 | ListCallsFilter, |
| 12 | + Sip, |
11 | 13 | TtsStreamOptions, |
12 | 14 | ) |
13 | 15 | from vonage_voice.errors import VoiceError |
@@ -35,9 +37,42 @@ def test_create_call_basic_ncco(): |
35 | 37 | ncco = [Talk(text='Hello world')] |
36 | 38 | call = CreateCallRequest( |
37 | 39 | ncco=ncco, |
38 | | - to=[{'type': 'sip', 'uri': 'sip:test@example.com'}], |
| 40 | + to=[ |
| 41 | + Sip( |
| 42 | + uri='sip:test@example.com', |
| 43 | + headers={'location': 'New York City'}, |
| 44 | + standard_headers={'User-to-User': '342342ef34;encoding=hex'}, |
| 45 | + ) |
| 46 | + ], |
39 | 47 | random_from_number=True, |
40 | 48 | ) |
| 49 | + |
| 50 | + response = voice.create_call(call) |
| 51 | + |
| 52 | + body = json.loads(voice.http_client.last_request.body) |
| 53 | + assert body['to'][0]['headers'] == {'location': 'New York City'} |
| 54 | + assert body['to'][0]['standard_headers'] == { |
| 55 | + 'User-to-User': '342342ef34;encoding=hex' |
| 56 | + } |
| 57 | + assert type(response) == CreateCallResponse |
| 58 | + assert response.uuid == '106a581a-34d0-432a-a625-220221fd434f' |
| 59 | + assert response.status == 'started' |
| 60 | + assert response.direction == 'outbound' |
| 61 | + assert response.conversation_uuid == 'CON-2be039b2-d0a4-4274-afc8-d7b241c7c044' |
| 62 | + |
| 63 | + |
| 64 | +@responses.activate |
| 65 | +def test_create_call_basic_ncco_from_sip(): |
| 66 | + build_response( |
| 67 | + path, 'POST', 'https://api.nexmo.com/v1/calls', 'create_call.json', 201 |
| 68 | + ) |
| 69 | + ncco = [Talk(text='Hello world')] |
| 70 | + call = CreateCallRequest( |
| 71 | + ncco=ncco, |
| 72 | + to=[Sip(uri='sip:test@example.com')], |
| 73 | + from_='sip:from_sip_uri@example.com', |
| 74 | + ) |
| 75 | + |
41 | 76 | response = voice.create_call(call) |
42 | 77 |
|
43 | 78 | assert type(response) == CreateCallResponse |
@@ -429,6 +464,15 @@ def test_download_recording(): |
429 | 464 | assert file_content.startswith(b'ID3') |
430 | 465 |
|
431 | 466 |
|
| 467 | +def test_download_recording_invalid_url(): |
| 468 | + with raises(VoiceError) as e: |
| 469 | + voice.download_recording( |
| 470 | + url='https://invalid.com/v1/files/aaaaaaaa-bbbb-cccc-dddd-0123456789ab', |
| 471 | + file_path='voice/tests/data/file_stream.mp3', |
| 472 | + ) |
| 473 | + assert e.match('The recording URL must be from a Vonage or Nexmo hostname.') |
| 474 | + |
| 475 | + |
432 | 476 | def test_verify_signature(): |
433 | 477 | token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2OTc2MzQ2ODAsImV4cCI6MzMyNTQ1NDA4MjgsImF1ZCI6IiIsInN1YiI6IiJ9.88vJc3I2HhuqEDixHXVhc9R30tA6U_HQHZTC29y6CGM' |
434 | 478 | valid_signature = "qwertyuiopasdfghjklzxcvbnm123456" |
|
0 commit comments