Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions bandwidth/model/bxml/verbs/forward.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""
forward.py

Bandwidth's Forward BXML verb

@copyright Bandwidth INC
"""
from ..terminal_verb import TerminalVerb


class Forward(TerminalVerb):

def __init__(
self, to: str=None, from_: str=None,
call_timeout: str=None, diversion_treatment: str=None,
diversion_reason: str=None, uui: str=None
):
"""Initialize a <Forward> verb

Args:
to (str): The phone number destination of the call.
from_ (str, optional): The phone number that the recipient will receive the call from.
call_timeout (str, optional): The number of seconds to wait before timing out the call.
diversion_treatment (str, optional): Can be any of the following:
none: No diversion headers are sent on the outbound leg of the transferred call.
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.
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.

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.
diversion_reason (str, optional): Can be any of the following values:
unknown
user-busy
no-answer
unavailable
unconditional
time-of-day
do-not-disturb
deflection
follow-me
out-of-service
away

This parameter is considered only when diversionTreatment is set to stack. Defaults is unknown.
Defaults to None.
uui (str, optional): The value of the User-To-User header to send within the outbound INVITE when forwarding to a SIP URI.
Must include the encoding parameter as specified in RFC 7433. Only base64 and jwt encoding are currently allowed.
This value, including the encoding specifier, may not exceed 256 characters.
"""
self.to = to
self.from_ = from_
self.call_timeout = call_timeout
self.diversion_treatment = diversion_treatment
self.diversion_reason = diversion_reason
self.uui = uui

super().__init__(tag="Forward", content=None)
@property
def _attributes(self):
return {
"to": self.to,
"from_": self.from_,
"callTimeout": self.call_timeout,
"diversionTreatment": self.diversion_treatment,
"diversionReason": self.diversion_reason,
"uui": self.uui,
}
38 changes: 38 additions & 0 deletions test/unit/bxml/test_forward.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
test_forward.py

Unit tests for the <Forward> BXML verb

@copyright Bandwidth Inc.
"""
import os
import pytest
import unittest

from bandwidth.model.bxml.verb import Verb
from bandwidth.model.bxml.verbs.forward import Forward

class TestForward(unittest.TestCase):

def setUp(self):
self.forward = Forward(
to="19195554321",
from_="19195554322",
call_timeout = "15",
diversion_treatment="propagate",
diversion_reason="away",
uui="93d6f3c0be5845960b744fa28015d8ede84bd1a4;encoding=base64,asdf;encoding=jwt"
)
self.test_verb = Verb(tag="test")


def test_to_bxml(self):
if os.environ['PYTHON_VERSION'] == '3.7':
expected = '<Forward callTimeout="15" diversionReason="away" diversionTreatment="propagate" from_="19195554322" to="19195554321" uui="93d6f3c0be5845960b744fa28015d8ede84bd1a4;encoding=base64,asdf;encoding=jwt" />'
else:
expected = '<Forward to="19195554321" from_="19195554322" callTimeout="15" diversionTreatment="propagate" diversionReason="away" uui="93d6f3c0be5845960b744fa28015d8ede84bd1a4;encoding=base64,asdf;encoding=jwt" />'
assert(expected == self.forward.to_bxml())

def test_add_verb(self):
with pytest.raises(AttributeError):
self.forward.add_verb(self.test_verb)