diff --git a/bandwidth/models/bxml/__init__.py b/bandwidth/models/bxml/__init__.py index 32a84c4c..6ee36b26 100644 --- a/bandwidth/models/bxml/__init__.py +++ b/bandwidth/models/bxml/__init__.py @@ -1,6 +1,6 @@ from .bxml import Bxml +from .nestable_verb import NestableVerb from .response import Response from .root import Root -from .terminal_verb import TerminalVerb from .verb import Verb from .verbs import * diff --git a/bandwidth/models/bxml/nestable_verb.py b/bandwidth/models/bxml/nestable_verb.py new file mode 100644 index 00000000..6dd0aa03 --- /dev/null +++ b/bandwidth/models/bxml/nestable_verb.py @@ -0,0 +1,72 @@ +""" +nestable_verb.py + +Defines the base nestable_verb class for all BXML verbs that can have nested verbs + +@copyright Bandwidth INC +""" +from __future__ import annotations +import re +from typing import Union +import xml.etree.ElementTree as ET + +from .verb import Verb + + +class NestableVerb(Verb): + """Base class for nestable BXML verbs + """ + ssml_regex = r"<([a-zA-Z//].*?)>" + + def __init__(self, tag: str, content: str = None, nested_verbs: list[Verb] = None): + """Initialize the verb model + + Args: + tag (str): Name of the XML element + content (str, optional): XML element content. Defaults to None. + nested_verbs (list[Verb], optional): XML element children. Defaults to None. + """ + self._tag = tag + self._content = content + self._nested_verbs = nested_verbs + if not self._nested_verbs: + self._nested_verbs = [] + + def _to_etree_element(self) -> ET.Element: + """Generate an ET.Element object from a NestableVerb Object + + Returns: + ET.Element: ET.Element representation of NestableVerb + """ + root = ET.Element(self._tag) + if self._content: + root.text = self._content + self._set_attributes(root) + if self._nested_verbs: + for verb in self._nested_verbs: + root.append(verb._to_etree_element()) + return root + + def _generate_xml(self) -> ET.ElementTree: + """Generates an XML dom + + Returns: + ET.Element: The XML dom for the verb and its nested verbs + """ + root = ET.Element(self._tag) + if self._content: + root.text = self._content + self._set_attributes(root) + if self._nested_verbs: + for verb in self._nested_verbs: + root.append(verb._to_etree_element()) + dom = ET.ElementTree(root) + return dom + + def add_verb(self, verb) -> None: + """Add a verb to the object's nested_verbs array + + Args: + verb (Verb): BXML verb to nest within the parent. Becomes a child xml element. + """ + self._nested_verbs.append(verb) diff --git a/bandwidth/models/bxml/terminal_verb.py b/bandwidth/models/bxml/terminal_verb.py deleted file mode 100644 index ddcf75b2..00000000 --- a/bandwidth/models/bxml/terminal_verb.py +++ /dev/null @@ -1,34 +0,0 @@ -""" -terminal_verb.py - -Defines the terminal_verb class BXML verbs that cant have nested_verbs - -@copyright Bandwidth INC -""" -from .verb import Verb - - -class TerminalVerb(Verb): - """Base class for BXML verbs - """ - ssml_regex = r"<([a-zA-Z//].*?)>" - - def __init__(self, tag: str, content: str = None): - """Initialize the verb model - - Args: - tag (str): Name of the XML element - content (str, optional): XML element content. Defaults to None. - """ - super().__init__(tag=tag, content=content, nested_verbs=None) - - def add_verb(self, verb: Verb): - """Adding verbs is not allowed for this class - - Args: - verb (Verb): BXML verb - - Raises: - AttributeError: This method is not allowed for this verb - """ - raise AttributeError('Adding verbs is not supported by this verb') diff --git a/bandwidth/models/bxml/verb.py b/bandwidth/models/bxml/verb.py index 54de09b1..128dcc0b 100644 --- a/bandwidth/models/bxml/verb.py +++ b/bandwidth/models/bxml/verb.py @@ -15,7 +15,7 @@ class Verb: """Base class for BXML verbs """ - def __init__(self, tag: str, content: str = None, nested_verbs: list[Verb] = None): + def __init__(self, tag: str, content: str = None): """Initialize the verb model Args: @@ -25,9 +25,6 @@ def __init__(self, tag: str, content: str = None, nested_verbs: list[Verb] = Non """ self._tag = tag self._content = content - self._nested_verbs = nested_verbs - if not self._nested_verbs: - self._nested_verbs = [] @property def _attributes(self) -> Union[None, dict]: @@ -73,9 +70,6 @@ def _to_etree_element(self) -> ET.Element: if self._content: root.text = self._content self._set_attributes(root) - if self._nested_verbs: - for verb in self._nested_verbs: - root.append(verb._to_etree_element()) return root def _generate_xml(self) -> ET.ElementTree: @@ -88,20 +82,9 @@ def _generate_xml(self) -> ET.ElementTree: if self._content: root.text = self._content self._set_attributes(root) - if self._nested_verbs: - for verb in self._nested_verbs: - root.append(verb._to_etree_element()) dom = ET.ElementTree(root) return dom - def add_verb(self, verb) -> None: - """Add a verb to the object's nested_verbs array - - Args: - verb (BxmlVerb): BXML verb to nest within the parent. Becomes a child xml element. - """ - self._nested_verbs.append(verb) - def to_bxml(self) -> str: """Return the serialized BXML string diff --git a/bandwidth/models/bxml/verbs/__init__.py b/bandwidth/models/bxml/verbs/__init__.py index fc6ce38b..986c3972 100644 --- a/bandwidth/models/bxml/verbs/__init__.py +++ b/bandwidth/models/bxml/verbs/__init__.py @@ -1,10 +1,11 @@ from .bridge import Bridge from .conference import Conference from .custom_param import CustomParam -from .hangup import Hangup +from .forward import Forward from .gather import Gather -from .pause import Pause +from .hangup import Hangup from .pause_recording import PauseRecording +from .pause import Pause from .phone_number import PhoneNumber from .play_audio import PlayAudio from .record import Record @@ -19,8 +20,8 @@ from .start_stream import StartStream from .start_transcription import StartTranscription from .stop_gather import StopGather -from .stop_stream import StopStream from .stop_recording import StopRecording +from .stop_stream import StopStream from .stop_transcription import StopTranscription from .stream_param import StreamParam from .tag import Tag diff --git a/bandwidth/models/bxml/verbs/bridge.py b/bandwidth/models/bxml/verbs/bridge.py index 1c3b52c0..515232e4 100644 --- a/bandwidth/models/bxml/verbs/bridge.py +++ b/bandwidth/models/bxml/verbs/bridge.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class Bridge(TerminalVerb): +class Bridge(Verb): def __init__( self, target_call: str, bridge_complete_url: str=None, diff --git a/bandwidth/models/bxml/verbs/conference.py b/bandwidth/models/bxml/verbs/conference.py index 9fbac54c..5baba3f6 100644 --- a/bandwidth/models/bxml/verbs/conference.py +++ b/bandwidth/models/bxml/verbs/conference.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class Conference(TerminalVerb): +class Conference(Verb): def __init__( self, name: str, mute: str=None, diff --git a/bandwidth/models/bxml/verbs/custom_param.py b/bandwidth/models/bxml/verbs/custom_param.py index b50c464f..65a63f52 100644 --- a/bandwidth/models/bxml/verbs/custom_param.py +++ b/bandwidth/models/bxml/verbs/custom_param.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class CustomParam(TerminalVerb): +class CustomParam(Verb): def __init__(self, name: str = None, value: str = None): """ Initialize a verb diff --git a/bandwidth/models/bxml/verbs/forward.py b/bandwidth/models/bxml/verbs/forward.py index fb624b85..99cd6207 100644 --- a/bandwidth/models/bxml/verbs/forward.py +++ b/bandwidth/models/bxml/verbs/forward.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class Forward(TerminalVerb): +class Forward(Verb): def __init__( self, to: str=None, _from: str=None, diff --git a/bandwidth/models/bxml/verbs/gather.py b/bandwidth/models/bxml/verbs/gather.py index b3ffebb3..d0a18a63 100644 --- a/bandwidth/models/bxml/verbs/gather.py +++ b/bandwidth/models/bxml/verbs/gather.py @@ -6,12 +6,12 @@ @copyright Bandwidth INC """ from typing import Union, List -from ..verb import Verb +from ..nestable_verb import NestableVerb from .play_audio import PlayAudio from .speak_sentence import SpeakSentence -class Gather(Verb): +class Gather(NestableVerb): def __init__( self, audio_verbs: List[Union[PlayAudio, SpeakSentence]] = [], diff --git a/bandwidth/models/bxml/verbs/hangup.py b/bandwidth/models/bxml/verbs/hangup.py index f6603efa..3d3e8778 100644 --- a/bandwidth/models/bxml/verbs/hangup.py +++ b/bandwidth/models/bxml/verbs/hangup.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class Hangup(TerminalVerb): +class Hangup(Verb): def __init__(self): """Initialize a verb diff --git a/bandwidth/models/bxml/verbs/pause.py b/bandwidth/models/bxml/verbs/pause.py index 67e82f68..59709133 100644 --- a/bandwidth/models/bxml/verbs/pause.py +++ b/bandwidth/models/bxml/verbs/pause.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class Pause(TerminalVerb): +class Pause(Verb): def __init__(self, duration:int=1): """Initialize a verb Args: diff --git a/bandwidth/models/bxml/verbs/pause_recording.py b/bandwidth/models/bxml/verbs/pause_recording.py index b7a7de5e..23f23998 100644 --- a/bandwidth/models/bxml/verbs/pause_recording.py +++ b/bandwidth/models/bxml/verbs/pause_recording.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class PauseRecording(TerminalVerb): +class PauseRecording(Verb): def __init__(self): """Initialize a verb diff --git a/bandwidth/models/bxml/verbs/phone_number.py b/bandwidth/models/bxml/verbs/phone_number.py index 381bebe5..ac209166 100644 --- a/bandwidth/models/bxml/verbs/phone_number.py +++ b/bandwidth/models/bxml/verbs/phone_number.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class PhoneNumber(TerminalVerb): +class PhoneNumber(Verb): def __init__( self, number: str, transfer_answer_url: str=None, transfer_answer_method: str=None, diff --git a/bandwidth/models/bxml/verbs/play_audio.py b/bandwidth/models/bxml/verbs/play_audio.py index 727d1256..92db0ba3 100644 --- a/bandwidth/models/bxml/verbs/play_audio.py +++ b/bandwidth/models/bxml/verbs/play_audio.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class PlayAudio(TerminalVerb): +class PlayAudio(Verb): def __init__( self, audio_uri: str, diff --git a/bandwidth/models/bxml/verbs/record.py b/bandwidth/models/bxml/verbs/record.py index d20be380..55ebd871 100644 --- a/bandwidth/models/bxml/verbs/record.py +++ b/bandwidth/models/bxml/verbs/record.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class Record(TerminalVerb): +class Record(Verb): def __init__( self, record_complete_url: str=None, diff --git a/bandwidth/models/bxml/verbs/redirect.py b/bandwidth/models/bxml/verbs/redirect.py index 1b49a742..4d25db0c 100644 --- a/bandwidth/models/bxml/verbs/redirect.py +++ b/bandwidth/models/bxml/verbs/redirect.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class Redirect(TerminalVerb): +class Redirect(Verb): def __init__( self, redirect_url: str, redirect_method: str = None, diff --git a/bandwidth/models/bxml/verbs/resume_recording.py b/bandwidth/models/bxml/verbs/resume_recording.py index 45fdf166..94913297 100644 --- a/bandwidth/models/bxml/verbs/resume_recording.py +++ b/bandwidth/models/bxml/verbs/resume_recording.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class ResumeRecording(TerminalVerb): +class ResumeRecording(Verb): def __init__( self diff --git a/bandwidth/models/bxml/verbs/ring.py b/bandwidth/models/bxml/verbs/ring.py index 28a32137..02234230 100644 --- a/bandwidth/models/bxml/verbs/ring.py +++ b/bandwidth/models/bxml/verbs/ring.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class Ring(TerminalVerb): +class Ring(Verb): def __init__( self, duration: int=None, diff --git a/bandwidth/models/bxml/verbs/send_dtmf.py b/bandwidth/models/bxml/verbs/send_dtmf.py index 2900befd..ace83b65 100644 --- a/bandwidth/models/bxml/verbs/send_dtmf.py +++ b/bandwidth/models/bxml/verbs/send_dtmf.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class SendDtmf(TerminalVerb): +class SendDtmf(Verb): def __init__( self, digits: str, diff --git a/bandwidth/models/bxml/verbs/sip_uri.py b/bandwidth/models/bxml/verbs/sip_uri.py index 16452248..e52dbcc5 100644 --- a/bandwidth/models/bxml/verbs/sip_uri.py +++ b/bandwidth/models/bxml/verbs/sip_uri.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class SipUri(TerminalVerb): +class SipUri(Verb): def __init__( self, uri: str, uui: str=None, transfer_answer_url: str=None, transfer_answer_method: str=None, diff --git a/bandwidth/models/bxml/verbs/speak_sentence.py b/bandwidth/models/bxml/verbs/speak_sentence.py index f76fe513..f255c95f 100644 --- a/bandwidth/models/bxml/verbs/speak_sentence.py +++ b/bandwidth/models/bxml/verbs/speak_sentence.py @@ -9,10 +9,10 @@ import xml.etree.ElementTree as ET -from ..terminal_verb import TerminalVerb +from ..nestable_verb import NestableVerb -class SpeakSentence(TerminalVerb): +class SpeakSentence(NestableVerb): def __init__( self, text: str, voice: str=None, diff --git a/bandwidth/models/bxml/verbs/start_gather.py b/bandwidth/models/bxml/verbs/start_gather.py index 560e4c78..a88dedc0 100644 --- a/bandwidth/models/bxml/verbs/start_gather.py +++ b/bandwidth/models/bxml/verbs/start_gather.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class StartGather(TerminalVerb): +class StartGather(Verb): def __init__( self, dtmf_url: str, dtmf_method: str=None, username: str=None, diff --git a/bandwidth/models/bxml/verbs/start_recording.py b/bandwidth/models/bxml/verbs/start_recording.py index 406d6705..422c903d 100644 --- a/bandwidth/models/bxml/verbs/start_recording.py +++ b/bandwidth/models/bxml/verbs/start_recording.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class StartRecording(TerminalVerb): +class StartRecording(Verb): def __init__( self, recording_available_url: str = None, diff --git a/bandwidth/models/bxml/verbs/start_stream.py b/bandwidth/models/bxml/verbs/start_stream.py index d44d678b..a4fd274b 100644 --- a/bandwidth/models/bxml/verbs/start_stream.py +++ b/bandwidth/models/bxml/verbs/start_stream.py @@ -7,11 +7,11 @@ """ from typing import List -from ..verb import Verb +from ..nestable_verb import NestableVerb from ..verbs.stream_param import StreamParam -class StartStream(Verb): +class StartStream(NestableVerb): def __init__( self, destination: str, stream_params: List[StreamParam] = [], diff --git a/bandwidth/models/bxml/verbs/start_transcription.py b/bandwidth/models/bxml/verbs/start_transcription.py index 78a4af7d..bd1b9df6 100644 --- a/bandwidth/models/bxml/verbs/start_transcription.py +++ b/bandwidth/models/bxml/verbs/start_transcription.py @@ -7,11 +7,11 @@ """ from typing import List -from ..verb import Verb +from ..nestable_verb import NestableVerb from ..verbs.custom_param import CustomParam -class StartTranscription(Verb): +class StartTranscription(NestableVerb): def __init__( self, name: str = None, tracks: str = None, diff --git a/bandwidth/models/bxml/verbs/stop_gather.py b/bandwidth/models/bxml/verbs/stop_gather.py index 73b6b8a3..c06a23f5 100644 --- a/bandwidth/models/bxml/verbs/stop_gather.py +++ b/bandwidth/models/bxml/verbs/stop_gather.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class StopGather(TerminalVerb): +class StopGather(Verb): def __init__(self): """Initialize a verb diff --git a/bandwidth/models/bxml/verbs/stop_recording.py b/bandwidth/models/bxml/verbs/stop_recording.py index 651f9caa..87cf8467 100644 --- a/bandwidth/models/bxml/verbs/stop_recording.py +++ b/bandwidth/models/bxml/verbs/stop_recording.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class StopRecording(TerminalVerb): +class StopRecording(Verb): def __init__(self): """Initialize a verb diff --git a/bandwidth/models/bxml/verbs/stop_stream.py b/bandwidth/models/bxml/verbs/stop_stream.py index 87f7f596..8fb18109 100644 --- a/bandwidth/models/bxml/verbs/stop_stream.py +++ b/bandwidth/models/bxml/verbs/stop_stream.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class StopStream(TerminalVerb): +class StopStream(Verb): def __init__( self, name: str diff --git a/bandwidth/models/bxml/verbs/stop_transcription.py b/bandwidth/models/bxml/verbs/stop_transcription.py index 5b9828ad..62e2cf4c 100644 --- a/bandwidth/models/bxml/verbs/stop_transcription.py +++ b/bandwidth/models/bxml/verbs/stop_transcription.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class StopTranscription(TerminalVerb): +class StopTranscription(Verb): def __init__( self, name: str = None, diff --git a/bandwidth/models/bxml/verbs/stream_param.py b/bandwidth/models/bxml/verbs/stream_param.py index dbd4516d..2466dc21 100644 --- a/bandwidth/models/bxml/verbs/stream_param.py +++ b/bandwidth/models/bxml/verbs/stream_param.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class StreamParam(TerminalVerb): +class StreamParam(Verb): def __init__( self, name: str, value: str diff --git a/bandwidth/models/bxml/verbs/tag.py b/bandwidth/models/bxml/verbs/tag.py index d2d9b55b..0a89d18d 100644 --- a/bandwidth/models/bxml/verbs/tag.py +++ b/bandwidth/models/bxml/verbs/tag.py @@ -5,10 +5,10 @@ @copyright Bandwidth INC """ -from ..terminal_verb import TerminalVerb +from ..verb import Verb -class Tag(TerminalVerb): +class Tag(Verb): def __init__(self, content=""): """Initialize a verb diff --git a/bandwidth/models/bxml/verbs/transfer.py b/bandwidth/models/bxml/verbs/transfer.py index c9fe94e5..984ad5b5 100644 --- a/bandwidth/models/bxml/verbs/transfer.py +++ b/bandwidth/models/bxml/verbs/transfer.py @@ -7,12 +7,12 @@ """ from typing import Union, List -from ..verb import Verb +from ..nestable_verb import NestableVerb from ..verbs.phone_number import PhoneNumber from ..verbs.sip_uri import SipUri -class Transfer(Verb): +class Transfer(NestableVerb): def __init__( self, transfer_to: List[Union[PhoneNumber, SipUri]] = [], diff --git a/test/unit/models/bxml/test_base_classes.py b/test/unit/models/bxml/test_base_classes.py index 101cc267..65d774ae 100644 --- a/test/unit/models/bxml/test_base_classes.py +++ b/test/unit/models/bxml/test_base_classes.py @@ -9,9 +9,7 @@ import pytest import unittest -from bandwidth.models.bxml import Root -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml import TerminalVerb +from bandwidth.models.bxml import Root, Verb, NestableVerb class TestBaseClasses(unittest.TestCase): @@ -20,8 +18,7 @@ def setUp(self): self.root = Root(tag="TestRoot") self.verb1 = Verb(tag="TestVerb1", content="test") self.verb2 = Verb(tag="TestVerb2") - self.verb3 = Verb(tag="TestVerb3") - self.terminal_verb = TerminalVerb(tag="TestTerminalVerb") + self.nestable_verb = NestableVerb(tag="TestNestableVerb") def test_root(self): self.root.add_verb(self.verb1) @@ -32,13 +29,13 @@ def test_root(self): assert len(self.root) == 2 assert expected_bxml == self.root.to_bxml() - def test_verb(self): - self.verb3.add_verb(self.verb1) + def test_nestable_verb(self): + self.nestable_verb.add_verb(self.verb1) - expected_bxml = "test" - assert type(self.verb3[0]) == Verb - assert len(self.verb3) == 1 - assert expected_bxml == self.verb3.to_bxml() + expected_bxml = "test" + assert type(self.nestable_verb[0]) == Verb + assert len(self.nestable_verb) == 1 + assert expected_bxml == self.nestable_verb.to_bxml() def test_adding_verbs_to_root_during_creation(self): self.root2 = Root(tag="TestRoot2", nested_verbs=[self.verb1, self.verb2]) diff --git a/test/unit/models/bxml/test_bridge.py b/test/unit/models/bxml/test_bridge.py index 4c4c9db0..2435c2e7 100644 --- a/test/unit/models/bxml/test_bridge.py +++ b/test/unit/models/bxml/test_bridge.py @@ -7,8 +7,7 @@ """ import unittest -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml import Bridge +from bandwidth.models.bxml import Bridge, Verb class TestBridge(unittest.TestCase): @@ -19,7 +18,10 @@ def setUp(self): bridge_complete_url="https://example.com", tag="test" ) - self.test_verb = Verb(tag="test") + + def test_instance(self): + assert isinstance(self.bridge, Bridge) + assert isinstance(self.bridge, Verb) def test_to_bxml(self): expected = '+19198675309' diff --git a/test/unit/models/bxml/test_bxml.py b/test/unit/models/bxml/test_bxml.py index 77d1a577..f0a6f0e0 100644 --- a/test/unit/models/bxml/test_bxml.py +++ b/test/unit/models/bxml/test_bxml.py @@ -13,10 +13,13 @@ class TestBxml(unittest.TestCase): def setUp(self): - self.response = Bxml() + self.bxml = Bxml() + + def test_instance(self): + assert isinstance(self.bxml, Bxml) def test_bxml_init(self): """Test initializing the root """ expected_bxml = "\n" - assert self.response.to_bxml() == expected_bxml + assert self.bxml.to_bxml() == expected_bxml diff --git a/test/unit/models/bxml/test_conference.py b/test/unit/models/bxml/test_conference.py index 8d0541d1..059b4a4f 100644 --- a/test/unit/models/bxml/test_conference.py +++ b/test/unit/models/bxml/test_conference.py @@ -7,8 +7,7 @@ """ import unittest -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml import Conference +from bandwidth.models.bxml import Conference, Verb class TestConference(unittest.TestCase): @@ -30,7 +29,10 @@ def setUp(self): tag = "tag", callback_timeout = "5", ) - self.test_verb = Verb(tag="test") + + def test_instance(self): + assert isinstance(self.conference, Conference) + assert isinstance(self.conference, Verb) def test_to_bxml(self): expected = '' diff --git a/test/unit/models/bxml/test_forward.py b/test/unit/models/bxml/test_forward.py index ec42aaa1..66e9ec96 100644 --- a/test/unit/models/bxml/test_forward.py +++ b/test/unit/models/bxml/test_forward.py @@ -7,8 +7,7 @@ """ import unittest -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml.verbs.forward import Forward +from bandwidth.models.bxml import Forward, Verb class TestForward(unittest.TestCase): @@ -21,7 +20,10 @@ def setUp(self): diversion_reason="away", uui="93d6f3c0be5845960b744fa28015d8ede84bd1a4;encoding=base64,asdf;encoding=jwt" ) - self.test_verb = Verb(tag="test") + + def test_instance(self): + assert isinstance(self.forward, Forward) + assert isinstance(self.forward, Verb) def test_to_bxml(self): expected = '' diff --git a/test/unit/models/bxml/test_gather.py b/test/unit/models/bxml/test_gather.py index 08b2e7dc..3993ec6b 100644 --- a/test/unit/models/bxml/test_gather.py +++ b/test/unit/models/bxml/test_gather.py @@ -7,7 +7,7 @@ """ import unittest -from bandwidth.models.bxml import PlayAudio,SpeakSentence,Gather +from bandwidth.models.bxml import PlayAudio, SpeakSentence, Gather, Verb, NestableVerb class TestGather(unittest.TestCase): @@ -41,6 +41,11 @@ def setUp(self): audio_verbs=[self.play_audio] ) + def test_instance(self): + assert isinstance(self.gather, Gather) + assert isinstance(self.gather, NestableVerb) + assert isinstance(self.gather, Verb) + def test_defaults(self): gather = Gather( audio_verbs=[self.play_audio] diff --git a/test/unit/models/bxml/test_hangup.py b/test/unit/models/bxml/test_hangup.py index 6d761eb7..66a86ba3 100644 --- a/test/unit/models/bxml/test_hangup.py +++ b/test/unit/models/bxml/test_hangup.py @@ -7,15 +7,17 @@ """ import unittest -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml.verbs.hangup import Hangup +from bandwidth.models.bxml import Hangup, Verb class TestHangup(unittest.TestCase): def setUp(self): self.hangup = Hangup() - self.test_verb = Verb(tag="test") + + def test_instance(self): + assert isinstance(self.hangup, Hangup) + assert isinstance(self.hangup, Verb) def test_to_bxml(self): expected = '' diff --git a/test/unit/models/bxml/test_pause.py b/test/unit/models/bxml/test_pause.py index 01cd84b4..f20df5e3 100644 --- a/test/unit/models/bxml/test_pause.py +++ b/test/unit/models/bxml/test_pause.py @@ -7,15 +7,17 @@ """ import unittest -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml import Pause +from bandwidth.models.bxml import Pause, Verb class TestPause(unittest.TestCase): def setUp(self): self.pause = Pause(duration=30) - self.test_verb = Verb(tag="test") + + def test_instance(self): + assert isinstance(self.pause, Pause) + assert isinstance(self.pause, Verb) def test_to_bxml(self): expected = '' diff --git a/test/unit/models/bxml/test_pause_recording.py b/test/unit/models/bxml/test_pause_recording.py index 2b6689dd..ee411d79 100644 --- a/test/unit/models/bxml/test_pause_recording.py +++ b/test/unit/models/bxml/test_pause_recording.py @@ -7,15 +7,17 @@ """ import unittest -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml import PauseRecording +from bandwidth.models.bxml import PauseRecording, Verb class TestPauseRecording(unittest.TestCase): def setUp(self): self.pause_recording = PauseRecording() - self.test_verb = Verb(tag="test") + + def test_instance(self): + assert isinstance(self.pause_recording, PauseRecording) + assert isinstance(self.pause_recording, Verb) def test_to_bxml(self): expected = '' diff --git a/test/unit/models/bxml/test_phone_number.py b/test/unit/models/bxml/test_phone_number.py index 85775069..aee3442a 100644 --- a/test/unit/models/bxml/test_phone_number.py +++ b/test/unit/models/bxml/test_phone_number.py @@ -7,8 +7,7 @@ """ import unittest -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml import PhoneNumber +from bandwidth.models.bxml import PhoneNumber, Verb class TestPhoneNumber(unittest.TestCase): @@ -20,7 +19,10 @@ def setUp(self): transfer_answer_method="POST", tag="" ) - self.test_verb = Verb(tag="test") + + def test_instance(self): + assert isinstance(self.phone_number, PhoneNumber) + assert isinstance(self.phone_number, Verb) def test_to_bxml(self): expected = '+19195551234' diff --git a/test/unit/models/bxml/test_play_audio.py b/test/unit/models/bxml/test_play_audio.py index e79d5713..22e48eb6 100644 --- a/test/unit/models/bxml/test_play_audio.py +++ b/test/unit/models/bxml/test_play_audio.py @@ -7,8 +7,7 @@ """ import unittest -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml import PlayAudio +from bandwidth.models.bxml import PlayAudio, Verb class TestPlayAudio(unittest.TestCase): @@ -18,8 +17,10 @@ def setUp(self): username="user", password="pass" ) - self.test_verb = Verb(tag="test") + def test_instance(self): + assert isinstance(self.play_audio, PlayAudio) + assert isinstance(self.play_audio, Verb) def test_to_bxml(self): expected = 'https://audio.url/audio1.wav' diff --git a/test/unit/models/bxml/test_record.py b/test/unit/models/bxml/test_record.py index a0e191fd..d7b350ea 100644 --- a/test/unit/models/bxml/test_record.py +++ b/test/unit/models/bxml/test_record.py @@ -7,8 +7,7 @@ """ import unittest -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml import Record +from bandwidth.models.bxml import Record, Verb class TestRecord(unittest.TestCase): @@ -16,7 +15,10 @@ class TestRecord(unittest.TestCase): def setUp(self): self.record = Record() self.record.max_duration = 10 - self.test_verb = Verb(tag="test") + + def test_instance(self): + assert isinstance(self.record, Record) + assert isinstance(self.record, Verb) def test_to_bxml(self): expected = '' diff --git a/test/unit/models/bxml/test_redirect.py b/test/unit/models/bxml/test_redirect.py index 7d612e27..c836c3f7 100644 --- a/test/unit/models/bxml/test_redirect.py +++ b/test/unit/models/bxml/test_redirect.py @@ -7,15 +7,17 @@ """ import unittest -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml import Redirect +from bandwidth.models.bxml import Redirect, Verb class TestRedirect(unittest.TestCase): def setUp(self): self.redirect = Redirect("https://example.com/redirect") - self.test_verb = Verb(tag="test") + + def test_instance(self): + assert isinstance(self.redirect, Redirect) + assert isinstance(self.redirect, Verb) def test_to_bxml(self): expected = '' diff --git a/test/unit/models/bxml/test_response.py b/test/unit/models/bxml/test_response.py index b90b9b41..5d8a1320 100644 --- a/test/unit/models/bxml/test_response.py +++ b/test/unit/models/bxml/test_response.py @@ -15,6 +15,9 @@ class TestResponse(unittest.TestCase): def setUp(self): self.response = Response() + def test_instance(self): + assert isinstance(self.response, Response) + def test_response_init(self): """Test initializing the root """ diff --git a/test/unit/models/bxml/test_resume_recording.py b/test/unit/models/bxml/test_resume_recording.py index 3698b0db..3ea13b60 100644 --- a/test/unit/models/bxml/test_resume_recording.py +++ b/test/unit/models/bxml/test_resume_recording.py @@ -7,15 +7,17 @@ """ import unittest -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml import ResumeRecording +from bandwidth.models.bxml import ResumeRecording, Verb class TestResumeRecording(unittest.TestCase): def setUp(self): self.resume_recording = ResumeRecording() - self.test_verb = Verb(tag="test") + + def test_instance(self): + assert isinstance(self.resume_recording, ResumeRecording) + assert isinstance(self.resume_recording, Verb) def test_to_bxml(self): expected = '' diff --git a/test/unit/models/bxml/test_ring.py b/test/unit/models/bxml/test_ring.py index 39adfdd9..14df46eb 100644 --- a/test/unit/models/bxml/test_ring.py +++ b/test/unit/models/bxml/test_ring.py @@ -7,8 +7,7 @@ """ import unittest -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml.verbs.ring import Ring +from bandwidth.models.bxml.verbs.ring import Ring, Verb class TestRing(unittest.TestCase): @@ -18,7 +17,10 @@ def setUp(self): duration=30, answer_call=True, ) - self.test_verb = Verb(tag="test") + + def test_instance(self): + assert isinstance(self.ring, Ring) + assert isinstance(self.ring, Verb) def test_to_bxml(self): expected = '' diff --git a/test/unit/models/bxml/test_send_dtmf.py b/test/unit/models/bxml/test_send_dtmf.py index fde3dee4..5536cb8b 100644 --- a/test/unit/models/bxml/test_send_dtmf.py +++ b/test/unit/models/bxml/test_send_dtmf.py @@ -7,8 +7,7 @@ """ import unittest -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml.verbs.send_dtmf import SendDtmf +from bandwidth.models.bxml.verbs.send_dtmf import SendDtmf, Verb class TestSendDtmf(unittest.TestCase): @@ -19,7 +18,10 @@ def setUp(self): tone_duration=3, tone_interval=5 ) - self.test_verb = Verb(tag="test") + + def test_instance(self): + assert isinstance(self.send_dtmf, SendDtmf) + assert isinstance(self.send_dtmf, Verb) def test_to_bxml(self): expected = '1234' diff --git a/test/unit/models/bxml/test_sip_uri.py b/test/unit/models/bxml/test_sip_uri.py index 3d98bccb..c8abb464 100644 --- a/test/unit/models/bxml/test_sip_uri.py +++ b/test/unit/models/bxml/test_sip_uri.py @@ -7,8 +7,7 @@ """ import unittest -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml import SipUri +from bandwidth.models.bxml import SipUri, Verb class TestSipUri(unittest.TestCase): @@ -21,7 +20,10 @@ def setUp(self): transfer_answer_method="POST", tag="test" ) - self.test_verb = Verb(tag="test") + + def test_instance(self): + assert isinstance(self.sip_uri, SipUri) + assert isinstance(self.sip_uri, Verb) def test_to_bxml(self): expected = 'sip:1-999-123-4567@voip-provider.example.net' diff --git a/test/unit/models/bxml/test_speak_sentence.py b/test/unit/models/bxml/test_speak_sentence.py index 45f43ca0..6d9b1d8f 100644 --- a/test/unit/models/bxml/test_speak_sentence.py +++ b/test/unit/models/bxml/test_speak_sentence.py @@ -7,8 +7,7 @@ """ import unittest -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml import SpeakSentence, Response +from bandwidth.models.bxml import SpeakSentence, Response, Verb class TestSpeakSentence(unittest.TestCase): @@ -19,7 +18,9 @@ def setUp(self): voice="julie" ) - self.test_verb = Verb(tag="test") + def test_instance(self): + assert isinstance(self.speak_sentence, SpeakSentence) + assert isinstance(self.speak_sentence, Verb) def test_to_bxml(self): expected = 'Hello. Your number is asdf, lets play a game. What is 10 + 3. Press the pound key when finished.' diff --git a/test/unit/models/bxml/test_start_gather.py b/test/unit/models/bxml/test_start_gather.py index 2a17019a..b490f547 100644 --- a/test/unit/models/bxml/test_start_gather.py +++ b/test/unit/models/bxml/test_start_gather.py @@ -7,8 +7,7 @@ """ import unittest -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml import StartGather +from bandwidth.models.bxml import StartGather, Verb class TestStartGather(unittest.TestCase): @@ -21,7 +20,10 @@ def setUp(self): password="pass", tag="tag" ) - self.test_verb = Verb(tag="test") + + def test_instance(self): + assert isinstance(self.start_gather, StartGather) + assert isinstance(self.start_gather, Verb) def test_to_bxml(self): expected = '' diff --git a/test/unit/models/bxml/test_start_recording.py b/test/unit/models/bxml/test_start_recording.py index eb0fb0db..bb459701 100644 --- a/test/unit/models/bxml/test_start_recording.py +++ b/test/unit/models/bxml/test_start_recording.py @@ -7,8 +7,7 @@ """ import unittest -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml import StartRecording +from bandwidth.models.bxml import StartRecording, Verb class TestStartRecording(unittest.TestCase): @@ -26,8 +25,10 @@ def setUp(self): file_format = "wav", multi_channel = True ) - self.test_verb = Verb(tag="test") + def test_instance(self): + assert isinstance(self.start_recording, StartRecording) + assert isinstance(self.start_recording, Verb) def test_to_bxml(self): expected = '' diff --git a/test/unit/models/bxml/test_start_stream.py b/test/unit/models/bxml/test_start_stream.py index b2bd3853..8013e916 100644 --- a/test/unit/models/bxml/test_start_stream.py +++ b/test/unit/models/bxml/test_start_stream.py @@ -7,7 +7,7 @@ """ import unittest -from bandwidth.models.bxml import StartStream, StreamParam +from bandwidth.models.bxml import StartStream, StreamParam, Verb, NestableVerb class TestStartStream(unittest.TestCase): @@ -34,6 +34,11 @@ def setUp(self): password = "pass" ) + def test_instance(self): + assert isinstance(self.start_stream, StartStream) + assert isinstance(self.start_stream, NestableVerb) + assert isinstance(self.start_stream, Verb) + def test_to_bxml(self): expected = '' assert expected == self.start_stream.to_bxml() diff --git a/test/unit/models/bxml/test_start_transcription.py b/test/unit/models/bxml/test_start_transcription.py index 69949b93..61861c52 100644 --- a/test/unit/models/bxml/test_start_transcription.py +++ b/test/unit/models/bxml/test_start_transcription.py @@ -7,7 +7,7 @@ """ import unittest -from bandwidth.models.bxml import StartTranscription, CustomParam +from bandwidth.models.bxml import StartTranscription, CustomParam, Verb, NestableVerb class TestStartTranscription(unittest.TestCase): @@ -34,6 +34,11 @@ def setUp(self) -> None: custom_params=[self.custom_param1] ) + def test_instance(self): + assert isinstance(self.start_transcription, StartTranscription) + assert isinstance(self.start_transcription, NestableVerb) + assert isinstance(self.start_transcription, Verb) + def test_to_bxml(self): expected = '' assert expected == self.start_transcription.to_bxml() diff --git a/test/unit/models/bxml/test_stop_gather.py b/test/unit/models/bxml/test_stop_gather.py index 2a0e5f5b..47f4c487 100644 --- a/test/unit/models/bxml/test_stop_gather.py +++ b/test/unit/models/bxml/test_stop_gather.py @@ -7,15 +7,17 @@ """ import unittest -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml import StopGather +from bandwidth.models.bxml import StopGather, Verb class TestStopGather(unittest.TestCase): def setUp(self): self.stop_gather = StopGather() - self.test_verb = Verb(tag="test") + + def test_instance(self): + assert isinstance(self.stop_gather, StopGather) + assert isinstance(self.stop_gather, Verb) def test_to_bxml(self): expected = '' diff --git a/test/unit/models/bxml/test_stop_recording.py b/test/unit/models/bxml/test_stop_recording.py index 0aac44c9..0cc4989e 100644 --- a/test/unit/models/bxml/test_stop_recording.py +++ b/test/unit/models/bxml/test_stop_recording.py @@ -7,15 +7,17 @@ """ import unittest -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml.verbs.stop_recording import StopRecording +from bandwidth.models.bxml.verbs.stop_recording import StopRecording, Verb class TestStopRecording(unittest.TestCase): def setUp(self): self.stop_recording = StopRecording() - self.test_verb = Verb(tag="test") + + def test_instance(self): + assert isinstance(self.stop_recording, StopRecording) + assert isinstance(self.stop_recording, Verb) def test_to_bxml(self): expected = '' diff --git a/test/unit/models/bxml/test_stop_stream.py b/test/unit/models/bxml/test_stop_stream.py index 5cecfbd2..055ab3d2 100644 --- a/test/unit/models/bxml/test_stop_stream.py +++ b/test/unit/models/bxml/test_stop_stream.py @@ -7,15 +7,17 @@ """ import unittest -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml import StopStream +from bandwidth.models.bxml import StopStream, Verb class TestStopStream(unittest.TestCase): def setUp(self): self.stop_stream = StopStream(name="conf") - self.test_verb = Verb(tag="test") + + def test_instance(self): + assert isinstance(self.stop_stream, StopStream) + assert isinstance(self.stop_stream, Verb) def test_to_bxml(self): expected = '' diff --git a/test/unit/models/bxml/test_stop_transcription.py b/test/unit/models/bxml/test_stop_transcription.py index 63d1be69..814882a4 100644 --- a/test/unit/models/bxml/test_stop_transcription.py +++ b/test/unit/models/bxml/test_stop_transcription.py @@ -7,7 +7,7 @@ """ import unittest -from bandwidth.models.bxml import StopTranscription +from bandwidth.models.bxml import StopTranscription, Verb class TestStopTranscription(unittest.TestCase): @@ -16,6 +16,10 @@ def setUp(self) -> None: name="transcription1" ) + def test_instance(self): + assert isinstance(self.stop_transcription, StopTranscription) + assert isinstance(self.stop_transcription, Verb) + def test_to_bxml(self): expected = '' assert expected == self.stop_transcription.to_bxml() diff --git a/test/unit/models/bxml/test_stream_param.py b/test/unit/models/bxml/test_stream_param.py index e87b3459..96ce2776 100644 --- a/test/unit/models/bxml/test_stream_param.py +++ b/test/unit/models/bxml/test_stream_param.py @@ -7,9 +7,7 @@ """ import unittest - -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml import StreamParam +from bandwidth.models.bxml import StreamParam, Verb class TestStreamParam(unittest.TestCase): @@ -19,8 +17,10 @@ def setUp(self): name="name1", value="value1" ) - self.test_verb = Verb(tag="test") + def test_instance(self): + assert isinstance(self.stream_param, StreamParam) + assert isinstance(self.stream_param, Verb) def test_to_bxml(self): expected = '' diff --git a/test/unit/models/bxml/test_tag.py b/test/unit/models/bxml/test_tag.py index 78280cfb..c34c6e8f 100644 --- a/test/unit/models/bxml/test_tag.py +++ b/test/unit/models/bxml/test_tag.py @@ -7,15 +7,17 @@ """ import unittest -from bandwidth.models.bxml import Verb -from bandwidth.models.bxml import Tag +from bandwidth.models.bxml import Tag, Verb class TestTag(unittest.TestCase): def setUp(self): self.tag = Tag(content="Test") - self.test_verb = Verb(tag="test") + + def test_instance(self): + assert isinstance(self.tag, Tag) + assert isinstance(self.tag, Verb) def test_to_bxml(self): expected = 'Test' diff --git a/test/unit/models/bxml/test_transfer.py b/test/unit/models/bxml/test_transfer.py index 1ddc1f39..6e667835 100644 --- a/test/unit/models/bxml/test_transfer.py +++ b/test/unit/models/bxml/test_transfer.py @@ -7,9 +7,7 @@ """ import unittest -from bandwidth.models.bxml.verbs.transfer import Transfer -from bandwidth.models.bxml import PhoneNumber -from bandwidth.models.bxml import SipUri +from bandwidth.models.bxml import Transfer, PhoneNumber, SipUri, Verb, NestableVerb class TestTransfer(unittest.TestCase): @@ -31,6 +29,11 @@ def setUp(self): tag = "test" ) + def test_instance(self): + assert isinstance(self.transfer, Transfer) + assert isinstance(self.transfer, NestableVerb) + assert isinstance(self.transfer, Verb) + def test_to_bxml(self): expected = 'sip@bw.com' assert expected == self.transfer.to_bxml()