Skip to content

Commit fb39a29

Browse files
authored
added random_from_number to voice.py and added new test (#198)
* added random_from_number to voice.py and added new test * Adding changes to the test * added dictionary in voice.py and fixed test * Remove Python version 3.4
1 parent 4cfa8ab commit fb39a29

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
strategy:
88
fail-fast: false
99
matrix:
10-
python: ["3.4", "3.5", "3.6", "3.7", "3.8"]
10+
python: ["3.5", "3.6", "3.7", "3.8"]
1111
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
1212
exclude:
1313
- os: "windows-latest"

src/vonage/voice.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,24 @@ def __init__(
1818
print('Error: {error_message}'.format(error_message=str(e)))
1919

2020
# Creates a new call session
21-
def create_call(self, params=None, **kwargs):
21+
def create_call(self, params, **kwargs):
22+
"""
23+
Adding Random From Number Feature for the Voice API,
24+
if set to `True`, the from number will be randomly selected
25+
from the pool of numbers available to the application making
26+
the call.
27+
28+
:param params is a dictionry that holds the 'from' and 'random_from_number'
29+
30+
"""
31+
if not params:
32+
params = kwargs
33+
34+
key = 'from'
35+
if key not in params:
36+
params['random_from_number'] = True
37+
38+
2239
return self._jwt_signed_post("/v1/calls", params or kwargs)
2340

2441
# Get call history paginated. Pass start and end dates to filter the retrieved information

tests/test_voice.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import time
33

44
import jwt
5+
import requests
56

67
import vonage
78
from util import *
@@ -14,7 +15,21 @@ def test_create_call(voice, dummy_data):
1415
params = {
1516
"to": [{"type": "phone", "number": "14843331234"}],
1617
"from": {"type": "phone", "number": "14843335555"},
17-
"answer_url": ["https://example.com/answer"],
18+
"answer_url": ["https://example.com/answer"]
19+
}
20+
21+
assert isinstance(voice.create_call(params), dict)
22+
assert request_user_agent() == dummy_data.user_agent
23+
assert request_content_type() == "application/json"
24+
25+
@responses.activate
26+
def test_params_with_random_number(voice, dummy_data):
27+
stub(responses.POST, "https://api.nexmo.com/v1/calls")
28+
29+
params = {
30+
"to": [{"type": "phone", "number": "14843331234"}],
31+
"random_from_number":True,
32+
"answer_url": ["https://example.com/answer"]
1833
}
1934

2035
assert isinstance(voice.create_call(params), dict)

0 commit comments

Comments
 (0)