Skip to content

Commit 215cb4b

Browse files
authored
SWI-5041 (#191)
* Rename `test.yaml` -> 'test.yml` * Update test.yml * Remove notify action for now * Remove all BXML default values * One too many `=None`'s * Revert "Remove all BXML default values" This reverts commit 464fc82. * Dont make non-strings strings * Do the string conversion later * Add gather tests back * Replace %lt; and > in the xml * Only do regex replacement on SpeakSentence
1 parent 302b686 commit 215cb4b

File tree

11 files changed

+39
-21
lines changed

11 files changed

+39
-21
lines changed

.github/workflows/test.yaml renamed to .github/workflows/test.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ jobs:
7878
echo "Log level: WARNING"
7979
pytest -v --log-cli-level=WARNING
8080
81-
- name: Notify Slack of Failures
82-
uses: Bandwidth/build-notify-slack-action@v1.0.0
83-
if: failure() && !github.event.pull_request.draft
84-
with:
85-
job-status: ${{ job.status }}
86-
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
87-
slack-channel: ${{ secrets.SLACK_CHANNEL }}
81+
# - name: Notify Slack of Failures
82+
# uses: Bandwidth/build-notify-slack-action@v2.0.0
83+
# if: failure() && !github.event.pull_request.draft
84+
# with:
85+
# job-status: ${{ job.status }}
86+
# slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
87+
# slack-channel: ${{ secrets.SLACK_CHANNEL }}

bandwidth/models/bxml/verb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _set_attributes(self, root: ET.Element):
6060
if self._attributes is not None:
6161
for key, value in self._attributes.items():
6262
if value is not None:
63-
root.set(key.strip("_"), value)
63+
root.set(key.strip("_"), str(value))
6464

6565
def _to_etree_element(self) -> ET.Element:
6666
"""Generate an ET.Element object from a Verb Object
@@ -107,5 +107,6 @@ def to_bxml(self) -> str:
107107
Returns:
108108
str: Serialized BXML string
109109
"""
110+
110111
xml_document = self._generate_xml()
111112
return ET.tostring(xml_document._root).decode('utf8')

bandwidth/models/bxml/verbs/gather.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ def _attributes(self):
8080
"fallbackPassword": self.fallback_password,
8181
"tag": self.tag,
8282
"terminatingDigits": self.terminating_digits,
83-
"maxDigits": str(self.max_digits),
84-
"interDigitTimeout": str(self.inter_digit_timeout),
85-
"firstDigitTimeout": str(self.first_digit_timeout),
86-
"repeatCount": str(self.repeat_count),
83+
"maxDigits": self.max_digits,
84+
"interDigitTimeout": self.inter_digit_timeout,
85+
"firstDigitTimeout": self.first_digit_timeout,
86+
"repeatCount": self.repeat_count,
8787
}

bandwidth/models/bxml/verbs/record.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def _attributes(self):
8585
"fallbackPassword": self.fallback_password,
8686
"tag": self.tag,
8787
"terminatingDigits": self.terminating_digits,
88-
"maxDuration": str(self.max_duration),
88+
"maxDuration": self.max_duration,
8989
"silenceTimeout": self.silence_timeout,
9090
"fileFormat": self.file_format
9191
}

bandwidth/models/bxml/verbs/ring.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ def __init__(
2727
@property
2828
def _attributes(self):
2929
return {
30-
"duration": str(self.duration),
31-
"answerCall": str(self.answer_call),
30+
"duration": self.duration,
31+
"answerCall": self.answer_call,
3232
}

bandwidth/models/bxml/verbs/send_dtmf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ def __init__(
3333
@property
3434
def _attributes(self):
3535
return {
36-
"toneDuration": str(self.tone_duration),
37-
"toneInterval": str(self.tone_interval)
36+
"toneDuration": self.tone_duration,
37+
"toneInterval": self.tone_interval
3838
}

bandwidth/models/bxml/verbs/speak_sentence.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
66
@copyright Bandwidth INC
77
"""
8+
import re
9+
10+
import xml.etree.ElementTree as ET
11+
812
from ..terminal_verb import TerminalVerb
913

1014

@@ -40,3 +44,9 @@ def _attributes(self):
4044
"gender": self.gender,
4145
"locale": self.locale,
4246
}
47+
48+
def to_bxml(self) -> str:
49+
SSML_REGEX = r"<([a-zA-Z//].*?)>"
50+
51+
xml_document = self._generate_xml()
52+
return re.sub(SSML_REGEX, r"<\1>", ET.tostring(xml_document._root).decode('utf8'))

bandwidth/models/bxml/verbs/start_recording.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ def _attributes(self):
5050
return {
5151
"recordingAvailableUrl": self.recording_available_url,
5252
"recordingAvailableMethod": self.recording_available_method,
53-
"transcribe": str(self.transcribe),
53+
"transcribe": self.transcribe,
5454
"transcriptionAvailableUrl": self.transcription_available_url,
5555
"transcriptionAvailableMethod": self.transcription_available_method,
5656
"username": self.username,
5757
"password": self.password,
5858
"tag": self.tag,
5959
"fileFormat": self.file_format,
60-
"multiChannel": str(self.multi_channel)
60+
"multiChannel": self.multi_channel
6161
}

bandwidth/models/bxml/verbs/start_transcription.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ def _attributes(self):
6060
"username": self.username,
6161
"password": self.password,
6262
"destination": self.destination,
63-
"stabilized": str(self.stabilized),
63+
"stabilized": self.stabilized,
6464
}

test/unit/bxml/test_gather.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ def setUp(self):
4141
audio_verbs=[self.play_audio]
4242
)
4343

44+
def test_defaults(self):
45+
gather = Gather(
46+
audio_verbs=[self.play_audio]
47+
)
48+
expected = '<Gather><PlayAudio username="user" password="pass">https://audio.url/audio1.wav</PlayAudio></Gather>'
49+
assert(expected == gather.to_bxml())
50+
4451
def test_to_bxml(self):
4552
expected = '<Gather gatherUrl="test.com" gatherMethod="POST" gatherFallbackUrl="fallback-test.com" gatherFallbackMethod="GET" username="user" password="pass" fallbackUsername="user" fallbackPassword="pass" tag="tag" terminatingDigits="2" maxDigits="5" interDigitTimeout="1" firstDigitTimeout="3" repeatCount="2"><PlayAudio username="user" password="pass">https://audio.url/audio1.wav</PlayAudio></Gather>'
4653
assert(expected == self.gather.to_bxml())

0 commit comments

Comments
 (0)