Skip to content

Commit 18a50a9

Browse files
Merge pull request #119 from Bandwidth/DX-2896
DX-2896 Refactor Forward Verb
2 parents 4ae106a + 6f9f49d commit 18a50a9

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""
2+
forward.py
3+
4+
Bandwidth's Forward BXML verb
5+
6+
@copyright Bandwidth INC
7+
"""
8+
from ..terminal_verb import TerminalVerb
9+
10+
11+
class Forward(TerminalVerb):
12+
13+
def __init__(
14+
self, to: str=None, from_: str=None,
15+
call_timeout: str=None, diversion_treatment: str=None,
16+
diversion_reason: str=None, uui: str=None
17+
):
18+
"""Initialize a <Forward> verb
19+
20+
Args:
21+
to (str): The phone number destination of the call.
22+
from_ (str, optional): The phone number that the recipient will receive the call from.
23+
call_timeout (str, optional): The number of seconds to wait before timing out the call.
24+
diversion_treatment (str, optional): Can be any of the following:
25+
none: No diversion headers are sent on the outbound leg of the transferred call.
26+
propagate: Copy the Diversion header from the inbound leg to the outbound leg. Ignored if there is no Diversion header present on the inbound leg.
27+
stack: After propagating any Diversion header from the inbound leg to the outbound leg, stack on top another Diversion header based on the Request-URI of the inbound call.
28+
29+
Defaults to none. If diversionTreatment is not specified, no diversion header will be included for the transfer even if one came with the inbound call. Defaults to None.
30+
diversion_reason (str, optional): Can be any of the following values:
31+
unknown
32+
user-busy
33+
no-answer
34+
unavailable
35+
unconditional
36+
time-of-day
37+
do-not-disturb
38+
deflection
39+
follow-me
40+
out-of-service
41+
away
42+
43+
This parameter is considered only when diversionTreatment is set to stack. Defaults is unknown.
44+
Defaults to None.
45+
uui (str, optional): The value of the User-To-User header to send within the outbound INVITE when forwarding to a SIP URI.
46+
Must include the encoding parameter as specified in RFC 7433. Only base64 and jwt encoding are currently allowed.
47+
This value, including the encoding specifier, may not exceed 256 characters.
48+
"""
49+
self.to = to
50+
self.from_ = from_
51+
self.call_timeout = call_timeout
52+
self.diversion_treatment = diversion_treatment
53+
self.diversion_reason = diversion_reason
54+
self.uui = uui
55+
56+
super().__init__(tag="Forward", content=None)
57+
@property
58+
def _attributes(self):
59+
return {
60+
"to": self.to,
61+
"from_": self.from_,
62+
"callTimeout": self.call_timeout,
63+
"diversionTreatment": self.diversion_treatment,
64+
"diversionReason": self.diversion_reason,
65+
"uui": self.uui,
66+
}

test/unit/bxml/test_forward.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
test_forward.py
3+
4+
Unit tests for the <Forward> 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.forward import Forward
14+
15+
class TestForward(unittest.TestCase):
16+
17+
def setUp(self):
18+
self.forward = Forward(
19+
to="19195554321",
20+
from_="19195554322",
21+
call_timeout = "15",
22+
diversion_treatment="propagate",
23+
diversion_reason="away",
24+
uui="93d6f3c0be5845960b744fa28015d8ede84bd1a4;encoding=base64,asdf;encoding=jwt"
25+
)
26+
self.test_verb = Verb(tag="test")
27+
28+
29+
def test_to_bxml(self):
30+
if os.environ['PYTHON_VERSION'] == '3.7':
31+
expected = '<Forward callTimeout="15" diversionReason="away" diversionTreatment="propagate" from_="19195554322" to="19195554321" uui="93d6f3c0be5845960b744fa28015d8ede84bd1a4;encoding=base64,asdf;encoding=jwt" />'
32+
else:
33+
expected = '<Forward to="19195554321" from_="19195554322" callTimeout="15" diversionTreatment="propagate" diversionReason="away" uui="93d6f3c0be5845960b744fa28015d8ede84bd1a4;encoding=base64,asdf;encoding=jwt" />'
34+
assert(expected == self.forward.to_bxml())
35+
36+
def test_add_verb(self):
37+
with pytest.raises(AttributeError):
38+
self.forward.add_verb(self.test_verb)

0 commit comments

Comments
 (0)