Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Stephan Huber 2019-12-23 08:38:53 +01:00
commit 0527e88d46
541 changed files with 75504 additions and 51429 deletions

View file

@ -7,7 +7,7 @@ from nose.tools import assert_raises
from moto import mock_polly
# Polly only available in a few regions
DEFAULT_REGION = 'eu-west-1'
DEFAULT_REGION = "eu-west-1"
LEXICON_XML = """<?xml version="1.0" encoding="UTF-8"?>
<lexicon version="1.0"
@ -26,250 +26,238 @@ LEXICON_XML = """<?xml version="1.0" encoding="UTF-8"?>
@mock_polly
def test_describe_voices():
client = boto3.client('polly', region_name=DEFAULT_REGION)
client = boto3.client("polly", region_name=DEFAULT_REGION)
resp = client.describe_voices()
len(resp['Voices']).should.be.greater_than(1)
len(resp["Voices"]).should.be.greater_than(1)
resp = client.describe_voices(LanguageCode='en-GB')
len(resp['Voices']).should.equal(3)
resp = client.describe_voices(LanguageCode="en-GB")
len(resp["Voices"]).should.equal(3)
try:
client.describe_voices(LanguageCode='SOME_LANGUAGE')
client.describe_voices(LanguageCode="SOME_LANGUAGE")
except ClientError as err:
err.response['Error']['Code'].should.equal('400')
err.response["Error"]["Code"].should.equal("400")
else:
raise RuntimeError('Should of raised an exception')
raise RuntimeError("Should of raised an exception")
@mock_polly
def test_put_list_lexicon():
client = boto3.client('polly', region_name=DEFAULT_REGION)
client = boto3.client("polly", region_name=DEFAULT_REGION)
# Return nothing
client.put_lexicon(
Name='test',
Content=LEXICON_XML
)
client.put_lexicon(Name="test", Content=LEXICON_XML)
resp = client.list_lexicons()
len(resp['Lexicons']).should.equal(1)
len(resp["Lexicons"]).should.equal(1)
@mock_polly
def test_put_get_lexicon():
client = boto3.client('polly', region_name=DEFAULT_REGION)
client = boto3.client("polly", region_name=DEFAULT_REGION)
# Return nothing
client.put_lexicon(
Name='test',
Content=LEXICON_XML
)
client.put_lexicon(Name="test", Content=LEXICON_XML)
resp = client.get_lexicon(Name='test')
resp.should.contain('Lexicon')
resp.should.contain('LexiconAttributes')
resp = client.get_lexicon(Name="test")
resp.should.contain("Lexicon")
resp.should.contain("LexiconAttributes")
@mock_polly
def test_put_lexicon_bad_name():
client = boto3.client('polly', region_name=DEFAULT_REGION)
client = boto3.client("polly", region_name=DEFAULT_REGION)
try:
client.put_lexicon(
Name='test-invalid',
Content=LEXICON_XML
)
client.put_lexicon(Name="test-invalid", Content=LEXICON_XML)
except ClientError as err:
err.response['Error']['Code'].should.equal('InvalidParameterValue')
err.response["Error"]["Code"].should.equal("InvalidParameterValue")
else:
raise RuntimeError('Should of raised an exception')
raise RuntimeError("Should of raised an exception")
@mock_polly
def test_synthesize_speech():
client = boto3.client('polly', region_name=DEFAULT_REGION)
client = boto3.client("polly", region_name=DEFAULT_REGION)
# Return nothing
client.put_lexicon(
Name='test',
Content=LEXICON_XML
)
client.put_lexicon(Name="test", Content=LEXICON_XML)
tests = (
('pcm', 'audio/pcm'),
('mp3', 'audio/mpeg'),
('ogg_vorbis', 'audio/ogg'),
)
tests = (("pcm", "audio/pcm"), ("mp3", "audio/mpeg"), ("ogg_vorbis", "audio/ogg"))
for output_format, content_type in tests:
resp = client.synthesize_speech(
LexiconNames=['test'],
LexiconNames=["test"],
OutputFormat=output_format,
SampleRate='16000',
Text='test1234',
TextType='text',
VoiceId='Astrid'
SampleRate="16000",
Text="test1234",
TextType="text",
VoiceId="Astrid",
)
resp['ContentType'].should.equal(content_type)
resp["ContentType"].should.equal(content_type)
@mock_polly
def test_synthesize_speech_bad_lexicon():
client = boto3.client('polly', region_name=DEFAULT_REGION)
client.put_lexicon(Name='test', Content=LEXICON_XML)
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'
LexiconNames=["test2"],
OutputFormat="pcm",
SampleRate="16000",
Text="test1234",
TextType="text",
VoiceId="Astrid",
)
except ClientError as err:
err.response['Error']['Code'].should.equal('LexiconNotFoundException')
err.response["Error"]["Code"].should.equal("LexiconNotFoundException")
else:
raise RuntimeError('Should of raised LexiconNotFoundException')
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)
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'
LexiconNames=["test"],
OutputFormat="invalid",
SampleRate="16000",
Text="test1234",
TextType="text",
VoiceId="Astrid",
)
except ClientError as err:
err.response['Error']['Code'].should.equal('InvalidParameterValue')
err.response["Error"]["Code"].should.equal("InvalidParameterValue")
else:
raise RuntimeError('Should of raised ')
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)
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'
LexiconNames=["test"],
OutputFormat="pcm",
SampleRate="18000",
Text="test1234",
TextType="text",
VoiceId="Astrid",
)
except ClientError as err:
err.response['Error']['Code'].should.equal('InvalidSampleRateException')
err.response["Error"]["Code"].should.equal("InvalidSampleRateException")
else:
raise RuntimeError('Should of raised ')
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)
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'
LexiconNames=["test"],
OutputFormat="pcm",
SampleRate="16000",
Text="test1234",
TextType="invalid",
VoiceId="Astrid",
)
except ClientError as err:
err.response['Error']['Code'].should.equal('InvalidParameterValue')
err.response["Error"]["Code"].should.equal("InvalidParameterValue")
else:
raise RuntimeError('Should of raised ')
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)
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'
LexiconNames=["test"],
OutputFormat="pcm",
SampleRate="16000",
Text="test1234",
TextType="text",
VoiceId="Luke",
)
except ClientError as err:
err.response['Error']['Code'].should.equal('InvalidParameterValue')
err.response["Error"]["Code"].should.equal("InvalidParameterValue")
else:
raise RuntimeError('Should of raised ')
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)
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'
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')
err.response["Error"]["Code"].should.equal("TextLengthExceededException")
else:
raise RuntimeError('Should of raised ')
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)
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'
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')
err.response["Error"]["Code"].should.equal(
"MarksNotSupportedForFormatException"
)
else:
raise RuntimeError('Should of raised ')
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)
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'
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')
err.response["Error"]["Code"].should.equal(
"MarksNotSupportedForFormatException"
)
else:
raise RuntimeError('Should of raised ')
raise RuntimeError("Should of raised ")

View file

@ -1,19 +1,19 @@
from __future__ import unicode_literals
import sure # noqa
import moto.server as server
from moto import mock_polly
'''
Test the different server responses
'''
@mock_polly
def test_polly_list():
backend = server.create_backend_app("polly")
test_client = backend.test_client()
res = test_client.get('/v1/lexicons')
res.status_code.should.equal(200)
from __future__ import unicode_literals
import sure # noqa
import moto.server as server
from moto import mock_polly
"""
Test the different server responses
"""
@mock_polly
def test_polly_list():
backend = server.create_backend_app("polly")
test_client = backend.test_client()
res = test_client.get("/v1/lexicons")
res.status_code.should.equal(200)