Skip to content

Commit 126ea36

Browse files
Merge pull request #129 from Bandwidth/DX-2910
DX-2910 `<StartGather>` verb refactored
2 parents 2b48892 + 72100ab commit 126ea36

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

bandwidth/model/bxml/verbs/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .send_dtmf import SendDtmf
1010
from .sip_uri import SipUri
1111
from .speak_sentence import SpeakSentence
12+
from .start_gather import StartGather
1213
from .start_recording import StartRecording
1314
from .start_stream import StartStream
1415
from .stop_gather import StopGather
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
start_gather.py
3+
4+
Bandwidth's StartGather BXML verb
5+
6+
@copyright Bandwidth INC
7+
"""
8+
from ..terminal_verb import TerminalVerb
9+
10+
11+
class StartGather(TerminalVerb):
12+
13+
def __init__(
14+
self, dtmf_url: str, dtmf_method: str=None, username: str=None,
15+
password: str=None, tag: str=None,
16+
):
17+
"""Initialize a <StartGather> verb
18+
19+
Args:
20+
dtmf_url (str): URL to send the DTMF event to. May be a relative URL..
21+
dtmf_method (str, optional): The HTTP method to use for the request to dtmfUrl. GET or POST. Default value is POST. Defaults to None.
22+
username (str, optional): The username to send in the HTTP request to dtmfUrl. Defaults to None.
23+
password (str, optional): The password to send in the HTTP request to dtmfUrl. Defaults to None.
24+
tag (str, optional): A custom string that will be sent with these and all future callbacks unless overwritten by a future tag attribute or cleared. May be cleared by setting tag="" Max length 256 characters. Defaults to None.
25+
"""
26+
self.dtmf_url = dtmf_url
27+
self.dtmf_method = dtmf_method
28+
self.username = username
29+
self.password = password
30+
self.tag = tag
31+
super().__init__(
32+
tag="StartGather"
33+
)
34+
35+
@property
36+
def _attributes(self):
37+
return {
38+
"dtmfUrl": self.dtmf_url,
39+
"dtmfMethod": self.dtmf_method,
40+
"username": self.username,
41+
"password": self.password,
42+
"tag": self.tag
43+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
test_start_gather.py
3+
4+
Unit tests for the <StartGather> BXML verb
5+
6+
@copyright Bandwidth Inc.
7+
"""
8+
import os
9+
import pytest
10+
import unittest
11+
12+
from bandwidth.model.bxml.verb import Verb
13+
from bandwidth.model.bxml.verbs.start_gather import StartGather
14+
15+
16+
class TestPhoneNumber(unittest.TestCase):
17+
18+
def setUp(self):
19+
self.start_gather = StartGather(
20+
dtmf_url="https://example.com/startgather",
21+
dtmf_method="POST",
22+
username="user",
23+
password="pass",
24+
tag="tag"
25+
)
26+
self.test_verb = Verb(tag="test")
27+
28+
def test_to_bxml(self):
29+
if os.environ['PYTHON_VERSION'] == '3.7':
30+
expected = '<StartGather dtmfMethod="POST" dtmfUrl="https://example.com/startgather" password="pass" tag="tag" username="user" />'
31+
else:
32+
expected = '<StartGather dtmfUrl="https://example.com/startgather" dtmfMethod="POST" username="user" password="pass" tag="tag" />'
33+
34+
assert(expected == self.start_gather.to_bxml())
35+
36+
def test_add_verb(self):
37+
with pytest.raises(AttributeError):
38+
self.start_gather.add_verb(self.test_verb)

0 commit comments

Comments
 (0)