Skip to content

Commit dc47abb

Browse files
DX-2896 Refactor Forward Verb
1 parent ad0adaa commit dc47abb

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
"""
2+
forward.py
3+
4+
Bandwidth's Forward BXML verb
5+
6+
@copyright Bandwidth INC
7+
"""
8+
from ..verb import Verb
9+
10+
11+
class Forward(Verb):
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.attributes = {
50+
"to": to,
51+
"from_": from_,
52+
"callTimeout": call_timeout,
53+
"diversionTreatment": diversion_treatment,
54+
"diversionReason": diversion_reason,
55+
"uui": uui,
56+
}
57+
58+
super().__init__(tag="Forward", content=None, attributes=self.attributes, nested_verbs=None)
59+
60+
def add_verb(self, verb: Verb):
61+
"""Adding verbs is not allowed for <Forward>
62+
63+
Args:
64+
verb (Verb): BXML verb
65+
66+
Raises:
67+
AttributeError: This method is not allowed for <Forward>
68+
"""
69+
raise AttributeError('Adding verbs is not supported by <Forward>')

test/unit/bxml/test_forward.py

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

0 commit comments

Comments
 (0)