Skip to content

Commit 06e1b26

Browse files
authored
SWI-5041 (#193)
* 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 * SWI-5041 Remove Notify action on release workflow * SWI-5041 Apply Regex to Root Verb as well * Fix gather test and re-enable slack notifications
1 parent dcde426 commit 06e1b26

File tree

8 files changed

+38
-28
lines changed

8 files changed

+38
-28
lines changed

Diff for: .github/workflows/deploy.yml

+13-13
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ jobs:
6868
env:
6969
PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }}
7070
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
71-
72-
# - uses: Bandwidth/build-notify-slack-action@v1.0.0
73-
# if: always()
74-
# with:
75-
# job-status: ${{ job.status }}
76-
# slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
77-
# slack-channel: ${{ secrets.SLACK_CHANNEL }}
71+
72+
- uses: Bandwidth/build-notify-slack-action@v2.0.0
73+
if: always()
74+
with:
75+
job-status: ${{ job.status }}
76+
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
77+
slack-channel: ${{ secrets.SLACK_CHANNEL }}
7878

7979
deploy:
8080
name: Deploy `main` to PYPI
@@ -136,9 +136,9 @@ jobs:
136136
env:
137137
PYPI_API_KEY: ${{ secrets.PYPI_API_KEY }}
138138

139-
# - uses: Bandwidth/build-notify-slack-action@v1.0.0
140-
# if: always()
141-
# with:
142-
# job-status: ${{ job.status }}
143-
# slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
144-
# slack-channel: ${{ secrets.SLACK_CHANNEL }}
139+
- uses: Bandwidth/build-notify-slack-action@v2.0.0
140+
if: always()
141+
with:
142+
job-status: ${{ job.status }}
143+
slack-bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
144+
slack-channel: ${{ secrets.SLACK_CHANNEL }}

Diff for: .github/workflows/test.yml

+7-7
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/[email protected]
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/[email protected]
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 }}

Diff for: bandwidth/models/bxml/root.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
@copyright Bandwidth INC
77
"""
8+
import re
89
from typing import List
910
import xml.etree.ElementTree as ET
1011

@@ -14,6 +15,7 @@
1415
class Root:
1516
"""Base class for BXML roots
1617
"""
18+
ssml_regex = r"<([a-zA-Z//].*?)>"
1719

1820
def __init__(self, tag: str, nested_verbs: List[Verb] = None):
1921
"""Initialize instance of class
@@ -74,4 +76,4 @@ def to_bxml(self) -> str:
7476
str: Serialized BXML string
7577
"""
7678
xml_document = self._generate_xml()
77-
return ET.tostring(xml_document._root, encoding='UTF-8', method='xml', xml_declaration=True).decode("utf8")
79+
return re.sub(self.ssml_regex, r"<\1>", ET.tostring(xml_document._root, encoding='UTF-8', method='xml', xml_declaration=True).decode("utf8"))

Diff for: bandwidth/models/bxml/terminal_verb.py

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
class TerminalVerb(Verb):
1212
"""Base class for BXML verbs
1313
"""
14+
ssml_regex = r"&lt;([a-zA-Z//].*?)&gt;"
1415

1516
def __init__(self, tag: str, content: str = None):
1617
"""Initialize the verb model

Diff for: bandwidth/models/bxml/verb.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
@copyright Bandwidth INC
77
"""
88
from __future__ import annotations
9+
import re
910
from typing import Union
1011
import xml.etree.ElementTree as ET
1112

@@ -107,6 +108,8 @@ def to_bxml(self) -> str:
107108
Returns:
108109
str: Serialized BXML string
109110
"""
111+
ssml_regex = r"&lt;([a-zA-Z//].*?)&gt;"
110112

111113
xml_document = self._generate_xml()
112-
return ET.tostring(xml_document._root).decode('utf8')
114+
# if the root name is speakSentence, replace content with the SSML regex
115+
return re.sub(ssml_regex, r"<\1>", ET.tostring(xml_document._root).decode('utf8'))

Diff for: bandwidth/models/bxml/verbs/speak_sentence.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ def _attributes(self):
4343
"voice": self.voice,
4444
"gender": self.gender,
4545
"locale": self.locale,
46-
}
46+
}
4747

4848
def to_bxml(self) -> str:
49-
SSML_REGEX = r"&lt;([a-zA-Z//].*?)&gt;"
50-
5149
xml_document = self._generate_xml()
52-
return re.sub(SSML_REGEX, r"<\1>", ET.tostring(xml_document._root).decode('utf8'))
50+
return re.sub(self.ssml_regex, r"<\1>", ET.tostring(xml_document._root).decode('utf8'))

Diff for: test/unit/bxml/test_gather.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ def test_to_bxml(self):
5353
assert(expected == self.gather.to_bxml())
5454

5555
def test_add_verb(self):
56-
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><SpeakSentence>Hello. Your number is &lt;say-as interpret-as="telephone"&gt;asdf&lt;/say-as&gt;, lets play a game. What is 10 + 3. Press the pound key when finished.</SpeakSentence></Gather>'
56+
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><SpeakSentence>Hello. Your number is <say-as interpret-as="telephone">asdf</say-as>, lets play a game. What is 10 + 3. Press the pound key when finished.</SpeakSentence></Gather>'
5757
self.gather.add_verb(self.speak_sentence)
5858
assert(expected == self.gather.to_bxml())

Diff for: test/unit/bxml/test_speak_sentence.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import unittest
99

1010
from bandwidth.models.bxml import Verb
11-
from bandwidth.models.bxml import SpeakSentence
11+
from bandwidth.models.bxml import SpeakSentence, Response
1212

1313

1414
class TestSpeakSentence(unittest.TestCase):
@@ -24,3 +24,9 @@ def setUp(self):
2424
def test_to_bxml(self):
2525
expected = '<SpeakSentence voice="julie">Hello. Your number is <say-as interpret-as="telephone">asdf</say-as>, lets play a game. What is 10 + 3. Press the pound key when finished.</SpeakSentence>'
2626
assert(expected == self.speak_sentence.to_bxml())
27+
28+
def test_to_bxml_within_response(self):
29+
expected = '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<Response><SpeakSentence voice="julie">Hello. Your number is <say-as interpret-as="telephone">asdf</say-as>, lets play a game. What is 10 + 3. Press the pound key when finished.</SpeakSentence></Response>'
30+
response = Response()
31+
response.add_verb(self.speak_sentence)
32+
assert(expected == response.to_bxml())

0 commit comments

Comments
 (0)