Added tests
This commit is contained in:
parent
fcacecbef0
commit
993e74dc77
@ -134,9 +134,9 @@ class PollyResponse(BaseResponse):
|
|||||||
args['lexicon_names'] = self.json['LexiconNames']
|
args['lexicon_names'] = self.json['LexiconNames']
|
||||||
|
|
||||||
if 'OutputFormat' not in self.json:
|
if 'OutputFormat' not in self.json:
|
||||||
return self._error('LexiconNotFoundException', 'Lexicon not found')
|
return self._error('MissingParameter', 'Missing parameter OutputFormat')
|
||||||
if self.json['OutputFormat'] not in ('json', 'mp3', 'ogg_vorbis', 'pcm'):
|
if self.json['OutputFormat'] not in ('json', 'mp3', 'ogg_vorbis', 'pcm'):
|
||||||
return self._error('LexiconNotFoundException', 'Lexicon not found')
|
return self._error('InvalidParameterValue', 'Not one of json, mp3, ogg_vorbis, pcm')
|
||||||
args['output_format'] = self.json['OutputFormat']
|
args['output_format'] = self.json['OutputFormat']
|
||||||
|
|
||||||
if 'SampleRate' in self.json:
|
if 'SampleRate' in self.json:
|
||||||
@ -148,22 +148,22 @@ class PollyResponse(BaseResponse):
|
|||||||
if 'SpeechMarkTypes' in self.json:
|
if 'SpeechMarkTypes' in self.json:
|
||||||
for value in self.json['SpeechMarkTypes']:
|
for value in self.json['SpeechMarkTypes']:
|
||||||
if value not in ('sentance', 'ssml', 'viseme', 'word'):
|
if value not in ('sentance', 'ssml', 'viseme', 'word'):
|
||||||
return self._error('LexiconNotFoundException', 'Lexicon not found')
|
return self._error('InvalidParameterValue', 'Not one of sentance, ssml, viseme, word')
|
||||||
args['speech_marks'] = self.json['SpeechMarkTypes']
|
args['speech_marks'] = self.json['SpeechMarkTypes']
|
||||||
|
|
||||||
if 'Text' not in self.json:
|
if 'Text' not in self.json:
|
||||||
return self._error('LexiconNotFoundException', 'Lexicon not found')
|
return self._error('MissingParameter', 'Missing parameter Text')
|
||||||
args['text'] = self.json['Text']
|
args['text'] = self.json['Text']
|
||||||
|
|
||||||
if 'TextType' in self.json:
|
if 'TextType' in self.json:
|
||||||
if self.json['TextType'] not in ('ssml', 'text'):
|
if self.json['TextType'] not in ('ssml', 'text'):
|
||||||
return self._error('LexiconNotFoundException', 'Lexicon not found')
|
return self._error('InvalidParameterValue', 'Not one of ssml, text')
|
||||||
args['text_type'] = self.json['TextType']
|
args['text_type'] = self.json['TextType']
|
||||||
|
|
||||||
if 'VoiceId' not in self.json:
|
if 'VoiceId' not in self.json:
|
||||||
return self._error('LexiconNotFoundException', 'Lexicon not found')
|
return self._error('MissingParameter', 'Missing parameter VoiceId')
|
||||||
if self.json['VoiceId'] not in VOICE_IDS:
|
if self.json['VoiceId'] not in VOICE_IDS:
|
||||||
return self._error('LexiconNotFoundException', 'Lexicon not found')
|
return self._error('InvalidParameterValue', 'Not one of {0}'.format(', '.join(VOICE_IDS)))
|
||||||
args['voice_id'] = self.json['VoiceId']
|
args['voice_id'] = self.json['VoiceId']
|
||||||
|
|
||||||
# More validation
|
# More validation
|
||||||
|
@ -3,6 +3,7 @@ from __future__ import unicode_literals
|
|||||||
from botocore.exceptions import ClientError
|
from botocore.exceptions import ClientError
|
||||||
import boto3
|
import boto3
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
|
from nose.tools import assert_raises
|
||||||
from moto import mock_polly
|
from moto import mock_polly
|
||||||
|
|
||||||
# Polly only available in a few regions
|
# Polly only available in a few regions
|
||||||
@ -95,15 +96,180 @@ def test_synthesize_speech():
|
|||||||
Content=LEXICON_XML
|
Content=LEXICON_XML
|
||||||
)
|
)
|
||||||
|
|
||||||
a = client.synthesize_speech(
|
tests = (
|
||||||
LexiconNames=['test'],
|
('pcm', 'audio/pcm'),
|
||||||
OutputFormat='pcm',
|
('mp3', 'audio/mpeg'),
|
||||||
SampleRate='16000',
|
('ogg_vorbis', 'audio/ogg'),
|
||||||
Text='test1234',
|
|
||||||
TextType='text',
|
|
||||||
VoiceId='Astrid'
|
|
||||||
)
|
)
|
||||||
# TODO check content type
|
for output_format, content_type in tests:
|
||||||
print()
|
resp = client.synthesize_speech(
|
||||||
|
LexiconNames=['test'],
|
||||||
|
OutputFormat=output_format,
|
||||||
|
SampleRate='16000',
|
||||||
|
Text='test1234',
|
||||||
|
TextType='text',
|
||||||
|
VoiceId='Astrid'
|
||||||
|
)
|
||||||
|
resp['ContentType'].should.equal(content_type)
|
||||||
|
|
||||||
# Todo expand synthesize speech tests for bad config
|
|
||||||
|
@mock_polly
|
||||||
|
def test_synthesize_speech_bad_lexicon():
|
||||||
|
client = boto3.client('polly', region_name=DEFAULT_REGION)
|
||||||
|
client.put_lexicon(Name='test', Content=LEXICON_XML)
|
||||||
|
|
||||||
|
try:
|
||||||
|
client.synthesize_speech(
|
||||||
|
LexiconNames=['test2'],
|
||||||
|
OutputFormat='pcm',
|
||||||
|
SampleRate='16000',
|
||||||
|
Text='test1234',
|
||||||
|
TextType='text',
|
||||||
|
VoiceId='Astrid'
|
||||||
|
)
|
||||||
|
except ClientError as err:
|
||||||
|
err.response['Error']['Code'].should.equal('LexiconNotFoundException')
|
||||||
|
else:
|
||||||
|
raise RuntimeError('Should of raised LexiconNotFoundException')
|
||||||
|
|
||||||
|
|
||||||
|
@mock_polly
|
||||||
|
def test_synthesize_speech_bad_output_format():
|
||||||
|
client = boto3.client('polly', region_name=DEFAULT_REGION)
|
||||||
|
client.put_lexicon(Name='test', Content=LEXICON_XML)
|
||||||
|
|
||||||
|
try:
|
||||||
|
client.synthesize_speech(
|
||||||
|
LexiconNames=['test'],
|
||||||
|
OutputFormat='invalid',
|
||||||
|
SampleRate='16000',
|
||||||
|
Text='test1234',
|
||||||
|
TextType='text',
|
||||||
|
VoiceId='Astrid'
|
||||||
|
)
|
||||||
|
except ClientError as err:
|
||||||
|
err.response['Error']['Code'].should.equal('InvalidParameterValue')
|
||||||
|
else:
|
||||||
|
raise RuntimeError('Should of raised ')
|
||||||
|
|
||||||
|
|
||||||
|
@mock_polly
|
||||||
|
def test_synthesize_speech_bad_sample_rate():
|
||||||
|
client = boto3.client('polly', region_name=DEFAULT_REGION)
|
||||||
|
client.put_lexicon(Name='test', Content=LEXICON_XML)
|
||||||
|
|
||||||
|
try:
|
||||||
|
client.synthesize_speech(
|
||||||
|
LexiconNames=['test'],
|
||||||
|
OutputFormat='pcm',
|
||||||
|
SampleRate='18000',
|
||||||
|
Text='test1234',
|
||||||
|
TextType='text',
|
||||||
|
VoiceId='Astrid'
|
||||||
|
)
|
||||||
|
except ClientError as err:
|
||||||
|
err.response['Error']['Code'].should.equal('InvalidSampleRateException')
|
||||||
|
else:
|
||||||
|
raise RuntimeError('Should of raised ')
|
||||||
|
|
||||||
|
|
||||||
|
@mock_polly
|
||||||
|
def test_synthesize_speech_bad_text_type():
|
||||||
|
client = boto3.client('polly', region_name=DEFAULT_REGION)
|
||||||
|
client.put_lexicon(Name='test', Content=LEXICON_XML)
|
||||||
|
|
||||||
|
try:
|
||||||
|
client.synthesize_speech(
|
||||||
|
LexiconNames=['test'],
|
||||||
|
OutputFormat='pcm',
|
||||||
|
SampleRate='16000',
|
||||||
|
Text='test1234',
|
||||||
|
TextType='invalid',
|
||||||
|
VoiceId='Astrid'
|
||||||
|
)
|
||||||
|
except ClientError as err:
|
||||||
|
err.response['Error']['Code'].should.equal('InvalidParameterValue')
|
||||||
|
else:
|
||||||
|
raise RuntimeError('Should of raised ')
|
||||||
|
|
||||||
|
|
||||||
|
@mock_polly
|
||||||
|
def test_synthesize_speech_bad_voice_id():
|
||||||
|
client = boto3.client('polly', region_name=DEFAULT_REGION)
|
||||||
|
client.put_lexicon(Name='test', Content=LEXICON_XML)
|
||||||
|
|
||||||
|
try:
|
||||||
|
client.synthesize_speech(
|
||||||
|
LexiconNames=['test'],
|
||||||
|
OutputFormat='pcm',
|
||||||
|
SampleRate='16000',
|
||||||
|
Text='test1234',
|
||||||
|
TextType='text',
|
||||||
|
VoiceId='Luke'
|
||||||
|
)
|
||||||
|
except ClientError as err:
|
||||||
|
err.response['Error']['Code'].should.equal('InvalidParameterValue')
|
||||||
|
else:
|
||||||
|
raise RuntimeError('Should of raised ')
|
||||||
|
|
||||||
|
|
||||||
|
@mock_polly
|
||||||
|
def test_synthesize_speech_text_too_long():
|
||||||
|
client = boto3.client('polly', region_name=DEFAULT_REGION)
|
||||||
|
client.put_lexicon(Name='test', Content=LEXICON_XML)
|
||||||
|
|
||||||
|
try:
|
||||||
|
client.synthesize_speech(
|
||||||
|
LexiconNames=['test'],
|
||||||
|
OutputFormat='pcm',
|
||||||
|
SampleRate='16000',
|
||||||
|
Text='test1234'*376, # = 3008 characters
|
||||||
|
TextType='text',
|
||||||
|
VoiceId='Astrid'
|
||||||
|
)
|
||||||
|
except ClientError as err:
|
||||||
|
err.response['Error']['Code'].should.equal('TextLengthExceededException')
|
||||||
|
else:
|
||||||
|
raise RuntimeError('Should of raised ')
|
||||||
|
|
||||||
|
|
||||||
|
@mock_polly
|
||||||
|
def test_synthesize_speech_bad_speech_marks1():
|
||||||
|
client = boto3.client('polly', region_name=DEFAULT_REGION)
|
||||||
|
client.put_lexicon(Name='test', Content=LEXICON_XML)
|
||||||
|
|
||||||
|
try:
|
||||||
|
client.synthesize_speech(
|
||||||
|
LexiconNames=['test'],
|
||||||
|
OutputFormat='pcm',
|
||||||
|
SampleRate='16000',
|
||||||
|
Text='test1234',
|
||||||
|
TextType='text',
|
||||||
|
SpeechMarkTypes=['word'],
|
||||||
|
VoiceId='Astrid'
|
||||||
|
)
|
||||||
|
except ClientError as err:
|
||||||
|
err.response['Error']['Code'].should.equal('MarksNotSupportedForFormatException')
|
||||||
|
else:
|
||||||
|
raise RuntimeError('Should of raised ')
|
||||||
|
|
||||||
|
|
||||||
|
@mock_polly
|
||||||
|
def test_synthesize_speech_bad_speech_marks2():
|
||||||
|
client = boto3.client('polly', region_name=DEFAULT_REGION)
|
||||||
|
client.put_lexicon(Name='test', Content=LEXICON_XML)
|
||||||
|
|
||||||
|
try:
|
||||||
|
client.synthesize_speech(
|
||||||
|
LexiconNames=['test'],
|
||||||
|
OutputFormat='pcm',
|
||||||
|
SampleRate='16000',
|
||||||
|
Text='test1234',
|
||||||
|
TextType='ssml',
|
||||||
|
SpeechMarkTypes=['word'],
|
||||||
|
VoiceId='Astrid'
|
||||||
|
)
|
||||||
|
except ClientError as err:
|
||||||
|
err.response['Error']['Code'].should.equal('MarksNotSupportedForFormatException')
|
||||||
|
else:
|
||||||
|
raise RuntimeError('Should of raised ')
|
||||||
|
Loading…
Reference in New Issue
Block a user