Skip to content

Commit 1d808d4

Browse files
Merge remote-tracking branch 'origin/DX-2887' into DX-2898
2 parents d9ca505 + 72ceb80 commit 1d808d4

File tree

9 files changed

+155
-51
lines changed

9 files changed

+155
-51
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
verb.py
3+
4+
Defines the base verb class for all BXML verbs
5+
6+
@copyright Bandwidth INC
7+
"""
8+
from typing import List
9+
10+
from .verb import Verb
11+
12+
13+
class TerminalVerb(Verb):
14+
"""Base class for BXML verbs
15+
"""
16+
17+
def __init__(self, tag: str, content: str = None, attributes: dict = None, nested_verbs: List[Verb] = None):
18+
"""Initialize the verb model
19+
20+
Args:
21+
tag (str): Name of the XML element
22+
content (str, optional): XML element content. Defaults to None.
23+
attributes (dict, optional): XML element attributes. Defaults to None.
24+
nested_verbs (list[BxmlVerb], optional): XML element children. Defaults to None.
25+
"""
26+
super().__init__(tag=tag, content=content, attributes=attributes, nested_verbs=nested_verbs)
27+
28+
def add_verb(self, verb: Verb):
29+
"""Adding verbs is not allowed for this class
30+
31+
Args:
32+
verb (Verb): BXML verb
33+
34+
Raises:
35+
AttributeError: This method is not allowed for <SipUri>
36+
"""
37+
raise AttributeError('Adding verbs is not supported by this verb')

bandwidth/model/bxml/verb.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Verb:
1313
"""Base class for BXML verbs
1414
"""
1515

16-
def __init__(self, tag: str, content: str = None, attributes: dict = None, nested_verbs: list[BxmlVerb] = None):
16+
def __init__(self, tag: str, content: str = None, attributes: dict = None, nested_verbs: list[Verb] = None):
1717
"""Initialize the verb model
1818
1919
Args:
@@ -36,18 +36,18 @@ def __len__(self) -> int:
3636
int: Length of self._nested_verbs
3737
"""
3838
return len(self._nested_verbs)
39-
39+
4040
def __getitem__(self, position) -> Verb:
4141
"""Override default getitem method. Makes the object iterable.
4242
4343
Args:
4444
position (int): Desired self._nested_verbs list position
4545
4646
Returns:
47-
BxmlVerb: Desired BXML verb
47+
BxmlVerb: Desired BXML verb
4848
"""
4949
return self._nested_verbs[position]
50-
50+
5151
def _set_attributes(self, root: ET.Element):
5252
"""Set XML attributes on an Element
5353

bandwidth/model/bxml/verbs/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from .bridge import Bridge
12
from .phone_number import PhoneNumber
23
from .sip_uri import SipUri
34
from .tag import Tag
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""
2+
bridge.py
3+
4+
Bandwidth's Bridge BXML verb
5+
6+
@copyright Bandwidth INC
7+
"""
8+
from ..terminal_verb import TerminalVerb
9+
10+
11+
class Bridge(TerminalVerb):
12+
13+
def __init__(
14+
self, target_call: str, bridge_complete_url: str=None,
15+
bridge_complete_method: str=None,
16+
bridge_complete_fallback_url: str=None,
17+
bridge_complete_fallback_method: str=None,
18+
bridge_target_complete_url: str=None,
19+
bridge_target_complete_method: str=None,
20+
bridge_target_complete_fallback_url: str=None,
21+
bridge_target_complete_fallback_method: str=None,
22+
username: str=None, password: str=None,
23+
fallback_username: str=None, fallback_password: str=None,
24+
tag: str=None
25+
):
26+
"""Initialize a <Bridge> verb
27+
28+
Args:
29+
target_call (str): _description_
30+
bridge_complete_url (str, optional): _description_. Defaults to None.
31+
bridge_complete_method (str, optional): _description_. Defaults to None.
32+
bridge_complete_fallback_url (str, optional): _description_. Defaults to None.
33+
bridge_complete_fallback_method (str, optional): _description_. Defaults to None.
34+
bridge_target_complete_url (str, optional): _description_. Defaults to None.
35+
bridge_target_complete_method (str, optional): _description_. Defaults to None.
36+
bridge_target_complete_fallback_url (str, optional): _description_. Defaults to None.
37+
bridge_target_complete_fallback_method (str, optional): _description_. Defaults to None.
38+
username (str, optional): _description_. Defaults to None.
39+
password (str, optional): _description_. Defaults to None.
40+
fallback_username (str, optional): _description_. Defaults to None.
41+
fallback_password (str, optional): _description_. Defaults to None.
42+
tag (str, optional): _description_. Defaults to None.
43+
"""
44+
self.attributes = {
45+
"bridgeCompleteUrl": bridge_complete_url,
46+
"bridgeCompleteMethod": bridge_complete_method,
47+
"bridgeCompleteFallbackUrl": bridge_complete_fallback_url,
48+
"bridgeCompleteFallbackMethod": bridge_complete_fallback_method,
49+
"bridgeTargetCompleteUrl": bridge_target_complete_url,
50+
"bridgeTargetCompleteMethod": bridge_target_complete_method,
51+
"bridgeTargetCompleteFallback_url": bridge_target_complete_fallback_url,
52+
"bridgeTargetCompleteFallbackMethod": bridge_target_complete_fallback_method,
53+
"username": username,
54+
"password": password,
55+
"fallbackUsername": fallback_username,
56+
"fallbackUassword": fallback_password,
57+
"tag": tag
58+
}
59+
super().__init__(
60+
tag="Bridge",
61+
content=target_call,
62+
attributes=self.attributes,
63+
nested_verbs=None
64+
)

bandwidth/model/bxml/verbs/phone_number.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
66
@copyright Bandwidth INC
77
"""
8-
from ..verb import Verb
8+
from ..terminal_verb import TerminalVerb
99

1010

11-
class PhoneNumber(Verb):
11+
class PhoneNumber(TerminalVerb):
1212

1313
def __init__(
1414
self, number: str, transfer_answer_url: str=None, transfer_answer_method: str=None,
@@ -48,17 +48,6 @@ def __init__(
4848
super().__init__(
4949
tag="PhoneNumber",
5050
content=number,
51-
attributes=self.attributes,
51+
attributes=self.attributes,
5252
nested_verbs=None
5353
)
54-
55-
def add_verb(self, verb: Verb):
56-
"""Adding verbs is not allowed for <PhoneNumber>
57-
58-
Args:
59-
verb (Verb): BXML verb
60-
61-
Raises:
62-
AttributeError: This method is not allowed for <PhoneNumber>
63-
"""
64-
raise AttributeError('Adding verbs is not supported by <PhoneNumber>')

bandwidth/model/bxml/verbs/sip_uri.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
66
@copyright Bandwidth INC
77
"""
8-
from ..verb import Verb
8+
from ..terminal_verb import TerminalVerb
99

1010

11-
class SipUri(Verb):
11+
class SipUri(TerminalVerb):
1212

1313
def __init__(
1414
self, uri: str, uui: str=None, transfer_answer_url: str=None, transfer_answer_method: str=None,
@@ -50,17 +50,6 @@ def __init__(
5050
super().__init__(
5151
tag="SipUri",
5252
content=uri,
53-
attributes=self.attributes,
53+
attributes=self.attributes,
5454
nested_verbs=None
5555
)
56-
57-
def add_verb(self, verb: Verb):
58-
"""Adding verbs is not allowed for <SipUri>
59-
60-
Args:
61-
verb (Verb): BXML verb
62-
63-
Raises:
64-
AttributeError: This method is not allowed for <SipUri>
65-
"""
66-
raise AttributeError('Adding verbs is not supported by <SipUri>')

bandwidth/model/bxml/verbs/tag.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
66
@copyright Bandwidth INC
77
"""
8-
from ..verb import Verb
8+
from ..terminal_verb import TerminalVerb
99

1010

11-
class Tag(Verb):
11+
class Tag(TerminalVerb):
1212

1313
def __init__(self, content=""):
1414
"""Initialize a <Tag> verb
@@ -17,14 +17,3 @@ def __init__(self, content=""):
1717
content (str, optional): Custom tag value. Defaults to "".
1818
"""
1919
super().__init__(tag="Tag", content=content, attributes=None, nested_verbs=None)
20-
21-
def add_verb(self, verb: Verb):
22-
"""Adding verbs is not allowed for <Tag>
23-
24-
Args:
25-
verb (Verb): BXML verb
26-
27-
Raises:
28-
AttributeError: This method is not allowed for <Tag>
29-
"""
30-
raise AttributeError('Adding verbs is not supported by <Tag>')

test/unit/bxml/test_bridge.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
test_bridge.py
3+
4+
Unit tests for the <Bridge> 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.bridge import Bridge
14+
15+
16+
class TestSipUri(unittest.TestCase):
17+
18+
def setUp(self):
19+
self.bridge = Bridge(
20+
target_call="+19198675309",
21+
bridge_complete_url="https://example.com",
22+
tag="test"
23+
)
24+
self.test_verb = Verb(tag="test")
25+
26+
def test_to_bxml(self):
27+
if os.environ['PYTHON_VERSION'] == '3.7':
28+
expected = '<Bridge bridgeCompleteUrl="https://example.com" tag="test">+19198675309</Bridge>'
29+
else:
30+
expected = '<Bridge bridgeCompleteUrl="https://example.com" tag="test">+19198675309</Bridge>'
31+
assert(expected == self.bridge.to_bxml())
32+
33+
def test_add_verb(self):
34+
with pytest.raises(AttributeError):
35+
self.bridge.add_verb(self.test_verb)

test/unit/bxml/test_sip_uri.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@
1414

1515

1616
class TestSipUri(unittest.TestCase):
17-
17+
1818
def setUp(self):
19-
self.phone_number = SipUri(
19+
self.sip_uri = SipUri(
2020
uri="sip:[email protected]",
2121
uui="abc123",
2222
transfer_answer_url="https://example.com/webhooks/transfer_answer",
2323
transfer_answer_method="POST",
2424
tag="test"
2525
)
2626
self.test_verb = Verb(tag="test")
27-
27+
2828
def test_to_bxml(self):
2929
if os.environ['PYTHON_VERSION'] == '3.7':
3030
expected = '<SipUri tag="test" transferAnswerMethod="POST" transferAnswerUrl="https://example.com/webhooks/transfer_answer" uui="abc123">sip:[email protected]</SipUri>'
3131
else:
3232
expected = '<SipUri uui="abc123" transferAnswerUrl="https://example.com/webhooks/transfer_answer" transferAnswerMethod="POST" tag="test">sip:[email protected]</SipUri>'
33-
assert(expected == self.phone_number.to_bxml())
34-
33+
assert(expected == self.sip_uri.to_bxml())
34+
3535
def test_add_verb(self):
3636
with pytest.raises(AttributeError):
37-
self.phone_number.add_verb(self.test_verb)
37+
self.sip_uri.add_verb(self.test_verb)

0 commit comments

Comments
 (0)