Merge branch 'master' into batch
This commit is contained in:
commit
ea10c4dfb6
47 changed files with 2457 additions and 273 deletions
|
|
@ -12,11 +12,13 @@ import sure # noqa
|
|||
from freezegun import freeze_time
|
||||
from moto import mock_lambda, mock_s3, mock_ec2, settings
|
||||
|
||||
_lambda_region = 'us-east-1' if settings.TEST_SERVER_MODE else 'us-west-2'
|
||||
|
||||
def _process_lamda(pfunc):
|
||||
|
||||
def _process_lambda(func_str):
|
||||
zip_output = io.BytesIO()
|
||||
zip_file = zipfile.ZipFile(zip_output, 'w', zipfile.ZIP_DEFLATED)
|
||||
zip_file.writestr('lambda_function.zip', pfunc)
|
||||
zip_file.writestr('lambda_function.py', func_str)
|
||||
zip_file.close()
|
||||
zip_output.seek(0)
|
||||
return zip_output.read()
|
||||
|
|
@ -27,21 +29,23 @@ def get_test_zip_file1():
|
|||
def lambda_handler(event, context):
|
||||
return event
|
||||
"""
|
||||
return _process_lamda(pfunc)
|
||||
return _process_lambda(pfunc)
|
||||
|
||||
|
||||
def get_test_zip_file2():
|
||||
pfunc = """
|
||||
func_str = """
|
||||
import boto3
|
||||
|
||||
def lambda_handler(event, context):
|
||||
ec2 = boto3.resource('ec2', region_name='us-west-2', endpoint_url='http://{base_url}')
|
||||
|
||||
volume_id = event.get('volume_id')
|
||||
print('get volume details for %s' % volume_id)
|
||||
import boto3
|
||||
ec2 = boto3.resource('ec2', region_name='us-west-2', endpoint_url="http://{base_url}")
|
||||
vol = ec2.Volume(volume_id)
|
||||
print('Volume - %s state=%s, size=%s' % (volume_id, vol.state, vol.size))
|
||||
|
||||
print('get volume details for %s\\nVolume - %s state=%s, size=%s' % (volume_id, volume_id, vol.state, vol.size))
|
||||
return event
|
||||
""".format(base_url="localhost:5000" if settings.TEST_SERVER_MODE else "ec2.us-west-2.amazonaws.com")
|
||||
return _process_lamda(pfunc)
|
||||
""".format(base_url="motoserver:5000" if settings.TEST_SERVER_MODE else "ec2.us-west-2.amazonaws.com")
|
||||
return _process_lambda(func_str)
|
||||
|
||||
|
||||
@mock_lambda
|
||||
|
|
@ -58,7 +62,7 @@ def test_invoke_requestresponse_function():
|
|||
FunctionName='testFunction',
|
||||
Runtime='python2.7',
|
||||
Role='test-iam-role',
|
||||
Handler='lambda_function.handler',
|
||||
Handler='lambda_function.lambda_handler',
|
||||
Code={
|
||||
'ZipFile': get_test_zip_file1(),
|
||||
},
|
||||
|
|
@ -73,10 +77,13 @@ def test_invoke_requestresponse_function():
|
|||
Payload=json.dumps(in_data))
|
||||
|
||||
success_result["StatusCode"].should.equal(202)
|
||||
base64.b64decode(success_result["LogResult"]).decode(
|
||||
'utf-8').should.equal(json.dumps(in_data))
|
||||
json.loads(success_result["Payload"].read().decode(
|
||||
'utf-8')).should.equal(in_data)
|
||||
result_obj = json.loads(
|
||||
base64.b64decode(success_result["LogResult"]).decode('utf-8'))
|
||||
|
||||
result_obj.should.equal(in_data)
|
||||
|
||||
payload = success_result["Payload"].read().decode('utf-8')
|
||||
json.loads(payload).should.equal(in_data)
|
||||
|
||||
|
||||
@mock_lambda
|
||||
|
|
@ -86,7 +93,7 @@ def test_invoke_event_function():
|
|||
FunctionName='testFunction',
|
||||
Runtime='python2.7',
|
||||
Role='test-iam-role',
|
||||
Handler='lambda_function.handler',
|
||||
Handler='lambda_function.lambda_handler',
|
||||
Code={
|
||||
'ZipFile': get_test_zip_file1(),
|
||||
},
|
||||
|
|
@ -110,36 +117,47 @@ def test_invoke_event_function():
|
|||
'utf-8')).should.equal({})
|
||||
|
||||
|
||||
@mock_ec2
|
||||
@mock_lambda
|
||||
def test_invoke_function_get_ec2_volume():
|
||||
conn = boto3.resource("ec2", "us-west-2")
|
||||
vol = conn.create_volume(Size=99, AvailabilityZone='us-west-2')
|
||||
vol = conn.Volume(vol.id)
|
||||
if settings.TEST_SERVER_MODE:
|
||||
@mock_ec2
|
||||
@mock_lambda
|
||||
def test_invoke_function_get_ec2_volume():
|
||||
conn = boto3.resource("ec2", "us-west-2")
|
||||
vol = conn.create_volume(Size=99, AvailabilityZone='us-west-2')
|
||||
vol = conn.Volume(vol.id)
|
||||
|
||||
conn = boto3.client('lambda', 'us-west-2')
|
||||
conn.create_function(
|
||||
FunctionName='testFunction',
|
||||
Runtime='python2.7',
|
||||
Role='test-iam-role',
|
||||
Handler='lambda_function.handler',
|
||||
Code={
|
||||
'ZipFile': get_test_zip_file2(),
|
||||
},
|
||||
Description='test lambda function',
|
||||
Timeout=3,
|
||||
MemorySize=128,
|
||||
Publish=True,
|
||||
)
|
||||
conn = boto3.client('lambda', 'us-west-2')
|
||||
conn.create_function(
|
||||
FunctionName='testFunction',
|
||||
Runtime='python2.7',
|
||||
Role='test-iam-role',
|
||||
Handler='lambda_function.lambda_handler',
|
||||
Code={
|
||||
'ZipFile': get_test_zip_file2(),
|
||||
},
|
||||
Description='test lambda function',
|
||||
Timeout=3,
|
||||
MemorySize=128,
|
||||
Publish=True,
|
||||
)
|
||||
|
||||
in_data = {'volume_id': vol.id}
|
||||
result = conn.invoke(FunctionName='testFunction',
|
||||
InvocationType='RequestResponse', Payload=json.dumps(in_data))
|
||||
result["StatusCode"].should.equal(202)
|
||||
msg = 'get volume details for %s\nVolume - %s state=%s, size=%s\n%s' % (
|
||||
vol.id, vol.id, vol.state, vol.size, json.dumps(in_data))
|
||||
base64.b64decode(result["LogResult"]).decode('utf-8').should.equal(msg)
|
||||
result['Payload'].read().decode('utf-8').should.equal(msg)
|
||||
in_data = {'volume_id': vol.id}
|
||||
result = conn.invoke(FunctionName='testFunction',
|
||||
InvocationType='RequestResponse', Payload=json.dumps(in_data))
|
||||
result["StatusCode"].should.equal(202)
|
||||
msg = 'get volume details for %s\nVolume - %s state=%s, size=%s\n%s' % (
|
||||
vol.id, vol.id, vol.state, vol.size, json.dumps(in_data))
|
||||
|
||||
log_result = base64.b64decode(result["LogResult"]).decode('utf-8')
|
||||
|
||||
# fix for running under travis (TODO: investigate why it has an extra newline)
|
||||
log_result = log_result.replace('\n\n', '\n')
|
||||
log_result.should.equal(msg)
|
||||
|
||||
payload = result['Payload'].read().decode('utf-8')
|
||||
|
||||
# fix for running under travis (TODO: investigate why it has an extra newline)
|
||||
payload = payload.replace('\n\n', '\n')
|
||||
payload.should.equal(msg)
|
||||
|
||||
|
||||
@mock_lambda
|
||||
|
|
@ -150,7 +168,7 @@ def test_create_based_on_s3_with_missing_bucket():
|
|||
FunctionName='testFunction',
|
||||
Runtime='python2.7',
|
||||
Role='test-iam-role',
|
||||
Handler='lambda_function.handler',
|
||||
Handler='lambda_function.lambda_handler',
|
||||
Code={
|
||||
'S3Bucket': 'this-bucket-does-not-exist',
|
||||
'S3Key': 'test.zip',
|
||||
|
|
@ -181,7 +199,7 @@ def test_create_function_from_aws_bucket():
|
|||
FunctionName='testFunction',
|
||||
Runtime='python2.7',
|
||||
Role='test-iam-role',
|
||||
Handler='lambda_function.handler',
|
||||
Handler='lambda_function.lambda_handler',
|
||||
Code={
|
||||
'S3Bucket': 'test-bucket',
|
||||
'S3Key': 'test.zip',
|
||||
|
|
@ -202,10 +220,10 @@ def test_create_function_from_aws_bucket():
|
|||
result.pop('LastModified')
|
||||
result.should.equal({
|
||||
'FunctionName': 'testFunction',
|
||||
'FunctionArn': 'arn:aws:lambda:123456789012:function:testFunction',
|
||||
'FunctionArn': 'arn:aws:lambda:{}:123456789012:function:testFunction'.format(_lambda_region),
|
||||
'Runtime': 'python2.7',
|
||||
'Role': 'test-iam-role',
|
||||
'Handler': 'lambda_function.handler',
|
||||
'Handler': 'lambda_function.lambda_handler',
|
||||
"CodeSha256": hashlib.sha256(zip_content).hexdigest(),
|
||||
"CodeSize": len(zip_content),
|
||||
'Description': 'test lambda function',
|
||||
|
|
@ -230,7 +248,7 @@ def test_create_function_from_zipfile():
|
|||
FunctionName='testFunction',
|
||||
Runtime='python2.7',
|
||||
Role='test-iam-role',
|
||||
Handler='lambda_function.handler',
|
||||
Handler='lambda_function.lambda_handler',
|
||||
Code={
|
||||
'ZipFile': zip_content,
|
||||
},
|
||||
|
|
@ -247,10 +265,10 @@ def test_create_function_from_zipfile():
|
|||
|
||||
result.should.equal({
|
||||
'FunctionName': 'testFunction',
|
||||
'FunctionArn': 'arn:aws:lambda:123456789012:function:testFunction',
|
||||
'FunctionArn': 'arn:aws:lambda:{}:123456789012:function:testFunction'.format(_lambda_region),
|
||||
'Runtime': 'python2.7',
|
||||
'Role': 'test-iam-role',
|
||||
'Handler': 'lambda_function.handler',
|
||||
'Handler': 'lambda_function.lambda_handler',
|
||||
'CodeSize': len(zip_content),
|
||||
'Description': 'test lambda function',
|
||||
'Timeout': 3,
|
||||
|
|
@ -281,7 +299,7 @@ def test_get_function():
|
|||
FunctionName='testFunction',
|
||||
Runtime='python2.7',
|
||||
Role='test-iam-role',
|
||||
Handler='lambda_function.handler',
|
||||
Handler='lambda_function.lambda_handler',
|
||||
Code={
|
||||
'S3Bucket': 'test-bucket',
|
||||
'S3Key': 'test.zip',
|
||||
|
|
@ -301,16 +319,16 @@ def test_get_function():
|
|||
|
||||
result.should.equal({
|
||||
"Code": {
|
||||
"Location": "s3://lambda-functions.aws.amazon.com/test.zip",
|
||||
"Location": "s3://awslambda-{0}-tasks.s3-{0}.amazonaws.com/test.zip".format(_lambda_region),
|
||||
"RepositoryType": "S3"
|
||||
},
|
||||
"Configuration": {
|
||||
"CodeSha256": hashlib.sha256(zip_content).hexdigest(),
|
||||
"CodeSize": len(zip_content),
|
||||
"Description": "test lambda function",
|
||||
"FunctionArn": "arn:aws:lambda:123456789012:function:testFunction",
|
||||
"FunctionArn": 'arn:aws:lambda:{}:123456789012:function:testFunction'.format(_lambda_region),
|
||||
"FunctionName": "testFunction",
|
||||
"Handler": "lambda_function.handler",
|
||||
"Handler": "lambda_function.lambda_handler",
|
||||
"MemorySize": 128,
|
||||
"Role": "test-iam-role",
|
||||
"Runtime": "python2.7",
|
||||
|
|
@ -339,7 +357,7 @@ def test_delete_function():
|
|||
FunctionName='testFunction',
|
||||
Runtime='python2.7',
|
||||
Role='test-iam-role',
|
||||
Handler='lambda_function.handler',
|
||||
Handler='lambda_function.lambda_handler',
|
||||
Code={
|
||||
'S3Bucket': 'test-bucket',
|
||||
'S3Key': 'test.zip',
|
||||
|
|
@ -383,7 +401,7 @@ def test_list_create_list_get_delete_list():
|
|||
FunctionName='testFunction',
|
||||
Runtime='python2.7',
|
||||
Role='test-iam-role',
|
||||
Handler='lambda_function.handler',
|
||||
Handler='lambda_function.lambda_handler',
|
||||
Code={
|
||||
'S3Bucket': 'test-bucket',
|
||||
'S3Key': 'test.zip',
|
||||
|
|
@ -395,16 +413,16 @@ def test_list_create_list_get_delete_list():
|
|||
)
|
||||
expected_function_result = {
|
||||
"Code": {
|
||||
"Location": "s3://lambda-functions.aws.amazon.com/test.zip",
|
||||
"Location": "s3://awslambda-{0}-tasks.s3-{0}.amazonaws.com/test.zip".format(_lambda_region),
|
||||
"RepositoryType": "S3"
|
||||
},
|
||||
"Configuration": {
|
||||
"CodeSha256": hashlib.sha256(zip_content).hexdigest(),
|
||||
"CodeSize": len(zip_content),
|
||||
"Description": "test lambda function",
|
||||
"FunctionArn": "arn:aws:lambda:123456789012:function:testFunction",
|
||||
"FunctionArn": 'arn:aws:lambda:{}:123456789012:function:testFunction'.format(_lambda_region),
|
||||
"FunctionName": "testFunction",
|
||||
"Handler": "lambda_function.handler",
|
||||
"Handler": "lambda_function.lambda_handler",
|
||||
"MemorySize": 128,
|
||||
"Role": "test-iam-role",
|
||||
"Runtime": "python2.7",
|
||||
|
|
@ -437,12 +455,12 @@ def test_list_create_list_get_delete_list():
|
|||
@mock_lambda
|
||||
def test_invoke_lambda_error():
|
||||
lambda_fx = """
|
||||
def lambda_handler(event, context):
|
||||
raise Exception('failsauce')
|
||||
def lambda_handler(event, context):
|
||||
raise Exception('failsauce')
|
||||
"""
|
||||
zip_output = io.BytesIO()
|
||||
zip_file = zipfile.ZipFile(zip_output, 'w', zipfile.ZIP_DEFLATED)
|
||||
zip_file.writestr('lambda_function.zip', lambda_fx)
|
||||
zip_file.writestr('lambda_function.py', lambda_fx)
|
||||
zip_file.close()
|
||||
zip_output.seek(0)
|
||||
|
||||
|
|
@ -605,13 +623,15 @@ def test_get_function_created_with_zipfile():
|
|||
response['Configuration'].pop('LastModified')
|
||||
|
||||
response['ResponseMetadata']['HTTPStatusCode'].should.equal(200)
|
||||
assert 'Code' not in response
|
||||
assert len(response['Code']) == 2
|
||||
assert response['Code']['RepositoryType'] == 'S3'
|
||||
assert response['Code']['Location'].startswith('s3://awslambda-{0}-tasks.s3-{0}.amazonaws.com'.format(_lambda_region))
|
||||
response['Configuration'].should.equal(
|
||||
{
|
||||
"CodeSha256": hashlib.sha256(zip_content).hexdigest(),
|
||||
"CodeSize": len(zip_content),
|
||||
"Description": "test lambda function",
|
||||
"FunctionArn": "arn:aws:lambda:123456789012:function:testFunction",
|
||||
"FunctionArn":'arn:aws:lambda:{}:123456789012:function:testFunction'.format(_lambda_region),
|
||||
"FunctionName": "testFunction",
|
||||
"Handler": "lambda_function.handler",
|
||||
"MemorySize": 128,
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@ import tests.backport_assert_raises
|
|||
from nose.tools import assert_raises
|
||||
|
||||
import boto
|
||||
import boto3
|
||||
from boto.exception import EC2ResponseError
|
||||
import sure # noqa
|
||||
|
||||
from moto import mock_ec2_deprecated
|
||||
from moto import mock_ec2_deprecated, mock_ec2
|
||||
|
||||
|
||||
@mock_ec2_deprecated
|
||||
|
|
@ -15,7 +16,6 @@ def test_console_output():
|
|||
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||
reservation = conn.run_instances('ami-1234abcd')
|
||||
instance_id = reservation.instances[0].id
|
||||
|
||||
output = conn.get_console_output(instance_id)
|
||||
output.output.should_not.equal(None)
|
||||
|
||||
|
|
@ -29,3 +29,14 @@ def test_console_output_without_instance():
|
|||
cm.exception.code.should.equal('InvalidInstanceID.NotFound')
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_console_output_boto3():
|
||||
conn = boto3.resource('ec2', 'us-east-1')
|
||||
instances = conn.create_instances(ImageId='ami-1234abcd',
|
||||
MinCount=1,
|
||||
MaxCount=1)
|
||||
|
||||
output = instances[0].console_output()
|
||||
output.get('Output').should_not.equal(None)
|
||||
|
|
|
|||
14
tests/test_logs/test_logs.py
Normal file
14
tests/test_logs/test_logs.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import boto3
|
||||
import sure # noqa
|
||||
|
||||
from moto import mock_logs, settings
|
||||
|
||||
_logs_region = 'us-east-1' if settings.TEST_SERVER_MODE else 'us-west-2'
|
||||
|
||||
|
||||
@mock_logs
|
||||
def test_log_group_create():
|
||||
conn = boto3.client('logs', 'us-west-2')
|
||||
log_group_name = 'dummy'
|
||||
response = conn.create_log_group(logGroupName=log_group_name)
|
||||
response = conn.delete_log_group(logGroupName=log_group_name)
|
||||
275
tests/test_polly/test_polly.py
Normal file
275
tests/test_polly/test_polly.py
Normal file
|
|
@ -0,0 +1,275 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from botocore.exceptions import ClientError
|
||||
import boto3
|
||||
import sure # noqa
|
||||
from nose.tools import assert_raises
|
||||
from moto import mock_polly
|
||||
|
||||
# Polly only available in a few regions
|
||||
DEFAULT_REGION = 'eu-west-1'
|
||||
|
||||
LEXICON_XML = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<lexicon version="1.0"
|
||||
xmlns="http://www.w3.org/2005/01/pronunciation-lexicon"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.w3.org/2005/01/pronunciation-lexicon
|
||||
http://www.w3.org/TR/2007/CR-pronunciation-lexicon-20071212/pls.xsd"
|
||||
alphabet="ipa"
|
||||
xml:lang="en-US">
|
||||
<lexeme>
|
||||
<grapheme>W3C</grapheme>
|
||||
<alias>World Wide Web Consortium</alias>
|
||||
</lexeme>
|
||||
</lexicon>"""
|
||||
|
||||
|
||||
@mock_polly
|
||||
def test_describe_voices():
|
||||
client = boto3.client('polly', region_name=DEFAULT_REGION)
|
||||
|
||||
resp = client.describe_voices()
|
||||
len(resp['Voices']).should.be.greater_than(1)
|
||||
|
||||
resp = client.describe_voices(LanguageCode='en-GB')
|
||||
len(resp['Voices']).should.equal(3)
|
||||
|
||||
try:
|
||||
client.describe_voices(LanguageCode='SOME_LANGUAGE')
|
||||
except ClientError as err:
|
||||
err.response['Error']['Code'].should.equal('400')
|
||||
else:
|
||||
raise RuntimeError('Should of raised an exception')
|
||||
|
||||
|
||||
@mock_polly
|
||||
def test_put_list_lexicon():
|
||||
client = boto3.client('polly', region_name=DEFAULT_REGION)
|
||||
|
||||
# Return nothing
|
||||
client.put_lexicon(
|
||||
Name='test',
|
||||
Content=LEXICON_XML
|
||||
)
|
||||
|
||||
resp = client.list_lexicons()
|
||||
len(resp['Lexicons']).should.equal(1)
|
||||
|
||||
|
||||
@mock_polly
|
||||
def test_put_get_lexicon():
|
||||
client = boto3.client('polly', region_name=DEFAULT_REGION)
|
||||
|
||||
# Return nothing
|
||||
client.put_lexicon(
|
||||
Name='test',
|
||||
Content=LEXICON_XML
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
try:
|
||||
client.put_lexicon(
|
||||
Name='test-invalid',
|
||||
Content=LEXICON_XML
|
||||
)
|
||||
except ClientError as err:
|
||||
err.response['Error']['Code'].should.equal('InvalidParameterValue')
|
||||
else:
|
||||
raise RuntimeError('Should of raised an exception')
|
||||
|
||||
|
||||
@mock_polly
|
||||
def test_synthesize_speech():
|
||||
client = boto3.client('polly', region_name=DEFAULT_REGION)
|
||||
|
||||
# Return nothing
|
||||
client.put_lexicon(
|
||||
Name='test',
|
||||
Content=LEXICON_XML
|
||||
)
|
||||
|
||||
tests = (
|
||||
('pcm', 'audio/pcm'),
|
||||
('mp3', 'audio/mpeg'),
|
||||
('ogg_vorbis', 'audio/ogg'),
|
||||
)
|
||||
for output_format, content_type in tests:
|
||||
resp = client.synthesize_speech(
|
||||
LexiconNames=['test'],
|
||||
OutputFormat=output_format,
|
||||
SampleRate='16000',
|
||||
Text='test1234',
|
||||
TextType='text',
|
||||
VoiceId='Astrid'
|
||||
)
|
||||
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)
|
||||
|
||||
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 ')
|
||||
19
tests/test_polly/test_server.py
Normal file
19
tests/test_polly/test_server.py
Normal file
|
|
@ -0,0 +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)
|
||||
|
|
@ -106,7 +106,7 @@ def test_create_single_node_cluster():
|
|||
|
||||
|
||||
@mock_redshift_deprecated
|
||||
def test_default_cluster_attibutes():
|
||||
def test_default_cluster_attributes():
|
||||
conn = boto.redshift.connect_to_region("us-east-1")
|
||||
cluster_identifier = 'my_cluster'
|
||||
|
||||
|
|
@ -267,7 +267,7 @@ def test_create_cluster_with_parameter_group():
|
|||
|
||||
|
||||
@mock_redshift_deprecated
|
||||
def test_describe_non_existant_cluster():
|
||||
def test_describe_non_existent_cluster():
|
||||
conn = boto.redshift.connect_to_region("us-east-1")
|
||||
conn.describe_clusters.when.called_with(
|
||||
"not-a-cluster").should.throw(ClusterNotFound)
|
||||
|
|
@ -391,7 +391,7 @@ def test_create_invalid_cluster_subnet_group():
|
|||
|
||||
|
||||
@mock_redshift_deprecated
|
||||
def test_describe_non_existant_subnet_group():
|
||||
def test_describe_non_existent_subnet_group():
|
||||
conn = boto.redshift.connect_to_region("us-east-1")
|
||||
conn.describe_cluster_subnet_groups.when.called_with(
|
||||
"not-a-subnet-group").should.throw(ClusterSubnetGroupNotFound)
|
||||
|
|
@ -447,7 +447,7 @@ def test_create_cluster_security_group():
|
|||
|
||||
|
||||
@mock_redshift_deprecated
|
||||
def test_describe_non_existant_security_group():
|
||||
def test_describe_non_existent_security_group():
|
||||
conn = boto.redshift.connect_to_region("us-east-1")
|
||||
conn.describe_cluster_security_groups.when.called_with(
|
||||
"not-a-security-group").should.throw(ClusterSecurityGroupNotFound)
|
||||
|
|
@ -498,7 +498,7 @@ def test_create_cluster_parameter_group():
|
|||
|
||||
|
||||
@mock_redshift_deprecated
|
||||
def test_describe_non_existant_parameter_group():
|
||||
def test_describe_non_existent_parameter_group():
|
||||
conn = boto.redshift.connect_to_region("us-east-1")
|
||||
conn.describe_cluster_parameter_groups.when.called_with(
|
||||
"not-a-parameter-group").should.throw(ClusterParameterGroupNotFound)
|
||||
|
|
@ -530,6 +530,17 @@ def test_delete_cluster_parameter_group():
|
|||
"not-a-parameter-group").should.throw(ClusterParameterGroupNotFound)
|
||||
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_create_cluster_snapshot_of_non_existent_cluster():
|
||||
client = boto3.client('redshift', region_name='us-east-1')
|
||||
cluster_identifier = 'non-existent-cluster-id'
|
||||
client.create_cluster_snapshot.when.called_with(
|
||||
SnapshotIdentifier='snapshot-id',
|
||||
ClusterIdentifier=cluster_identifier,
|
||||
).should.throw(ClientError, 'Cluster {} not found.'.format(cluster_identifier))
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_create_cluster_snapshot():
|
||||
client = boto3.client('redshift', region_name='us-east-1')
|
||||
|
|
@ -560,6 +571,52 @@ def test_create_cluster_snapshot():
|
|||
snapshot['MasterUsername'].should.equal('username')
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_describe_cluster_snapshots():
|
||||
client = boto3.client('redshift', region_name='us-east-1')
|
||||
cluster_identifier = 'my_cluster'
|
||||
snapshot_identifier = 'my_snapshot'
|
||||
|
||||
client.create_cluster(
|
||||
DBName='test-db',
|
||||
ClusterIdentifier=cluster_identifier,
|
||||
ClusterType='single-node',
|
||||
NodeType='ds2.xlarge',
|
||||
MasterUsername='username',
|
||||
MasterUserPassword='password',
|
||||
)
|
||||
|
||||
client.create_cluster_snapshot(
|
||||
SnapshotIdentifier=snapshot_identifier,
|
||||
ClusterIdentifier=cluster_identifier,
|
||||
)
|
||||
|
||||
resp_clust = client.describe_cluster_snapshots(ClusterIdentifier=cluster_identifier)
|
||||
resp_snap = client.describe_cluster_snapshots(SnapshotIdentifier=snapshot_identifier)
|
||||
resp_clust['Snapshots'][0].should.equal(resp_snap['Snapshots'][0])
|
||||
snapshot = resp_snap['Snapshots'][0]
|
||||
snapshot['SnapshotIdentifier'].should.equal(snapshot_identifier)
|
||||
snapshot['ClusterIdentifier'].should.equal(cluster_identifier)
|
||||
snapshot['NumberOfNodes'].should.equal(1)
|
||||
snapshot['NodeType'].should.equal('ds2.xlarge')
|
||||
snapshot['MasterUsername'].should.equal('username')
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_describe_cluster_snapshots_not_found_error():
|
||||
client = boto3.client('redshift', region_name='us-east-1')
|
||||
cluster_identifier = 'my_cluster'
|
||||
snapshot_identifier = 'my_snapshot'
|
||||
|
||||
client.describe_cluster_snapshots.when.called_with(
|
||||
ClusterIdentifier=cluster_identifier,
|
||||
).should.throw(ClientError, 'Cluster {} not found.'.format(cluster_identifier))
|
||||
|
||||
client.describe_cluster_snapshots.when.called_with(
|
||||
SnapshotIdentifier=snapshot_identifier
|
||||
).should.throw(ClientError, 'Snapshot {} not found.'.format(snapshot_identifier))
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_delete_cluster_snapshot():
|
||||
client = boto3.client('redshift', region_name='us-east-1')
|
||||
|
|
@ -652,6 +709,15 @@ def test_create_cluster_from_snapshot():
|
|||
new_cluster['Endpoint']['Port'].should.equal(1234)
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_create_cluster_from_non_existent_snapshot():
|
||||
client = boto3.client('redshift', region_name='us-east-1')
|
||||
client.restore_from_cluster_snapshot.when.called_with(
|
||||
ClusterIdentifier='cluster-id',
|
||||
SnapshotIdentifier='non-existent-snapshot',
|
||||
).should.throw(ClientError, 'Snapshot non-existent-snapshot not found.')
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_create_cluster_status_update():
|
||||
client = boto3.client('redshift', region_name='us-east-1')
|
||||
|
|
@ -673,12 +739,126 @@ def test_create_cluster_status_update():
|
|||
|
||||
|
||||
@mock_redshift
|
||||
def test_describe_snapshot_tags():
|
||||
def test_describe_tags_with_resource_type():
|
||||
client = boto3.client('redshift', region_name='us-east-1')
|
||||
cluster_identifier = 'my_cluster'
|
||||
cluster_arn = 'arn:aws:redshift:us-east-1:123456789012:' \
|
||||
'cluster:{}'.format(cluster_identifier)
|
||||
snapshot_identifier = 'my_snapshot'
|
||||
snapshot_arn = 'arn:aws:redshift:us-east-1:123456789012:' \
|
||||
'snapshot:{}/{}'.format(cluster_identifier,
|
||||
snapshot_identifier)
|
||||
tag_key = 'test-tag-key'
|
||||
tag_value = 'teat-tag-value'
|
||||
tag_value = 'test-tag-value'
|
||||
|
||||
client.create_cluster(
|
||||
DBName='test-db',
|
||||
ClusterIdentifier=cluster_identifier,
|
||||
ClusterType='single-node',
|
||||
NodeType='ds2.xlarge',
|
||||
MasterUsername='username',
|
||||
MasterUserPassword='password',
|
||||
Tags=[{'Key': tag_key,
|
||||
'Value': tag_value}]
|
||||
)
|
||||
tags_response = client.describe_tags(ResourceType='cluster')
|
||||
tagged_resources = tags_response['TaggedResources']
|
||||
list(tagged_resources).should.have.length_of(1)
|
||||
tagged_resources[0]['ResourceType'].should.equal('cluster')
|
||||
tagged_resources[0]['ResourceName'].should.equal(cluster_arn)
|
||||
tag = tagged_resources[0]['Tag']
|
||||
tag['Key'].should.equal(tag_key)
|
||||
tag['Value'].should.equal(tag_value)
|
||||
|
||||
client.create_cluster_snapshot(
|
||||
SnapshotIdentifier=snapshot_identifier,
|
||||
ClusterIdentifier=cluster_identifier,
|
||||
Tags=[{'Key': tag_key,
|
||||
'Value': tag_value}]
|
||||
)
|
||||
tags_response = client.describe_tags(ResourceType='snapshot')
|
||||
tagged_resources = tags_response['TaggedResources']
|
||||
list(tagged_resources).should.have.length_of(1)
|
||||
tagged_resources[0]['ResourceType'].should.equal('snapshot')
|
||||
tagged_resources[0]['ResourceName'].should.equal(snapshot_arn)
|
||||
tag = tagged_resources[0]['Tag']
|
||||
tag['Key'].should.equal(tag_key)
|
||||
tag['Value'].should.equal(tag_value)
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_describe_tags_cannot_specify_resource_type_and_resource_name():
|
||||
client = boto3.client('redshift', region_name='us-east-1')
|
||||
resource_name = 'arn:aws:redshift:us-east-1:123456789012:cluster:cluster-id'
|
||||
resource_type = 'cluster'
|
||||
client.describe_tags.when.called_with(
|
||||
ResourceName=resource_name,
|
||||
ResourceType=resource_type
|
||||
).should.throw(ClientError, 'using either an ARN or a resource type')
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_describe_tags_with_resource_name():
|
||||
client = boto3.client('redshift', region_name='us-east-1')
|
||||
cluster_identifier = 'cluster-id'
|
||||
cluster_arn = 'arn:aws:redshift:us-east-1:123456789012:' \
|
||||
'cluster:{}'.format(cluster_identifier)
|
||||
snapshot_identifier = 'snapshot-id'
|
||||
snapshot_arn = 'arn:aws:redshift:us-east-1:123456789012:' \
|
||||
'snapshot:{}/{}'.format(cluster_identifier,
|
||||
snapshot_identifier)
|
||||
tag_key = 'test-tag-key'
|
||||
tag_value = 'test-tag-value'
|
||||
|
||||
client.create_cluster(
|
||||
DBName='test-db',
|
||||
ClusterIdentifier=cluster_identifier,
|
||||
ClusterType='single-node',
|
||||
NodeType='ds2.xlarge',
|
||||
MasterUsername='username',
|
||||
MasterUserPassword='password',
|
||||
Tags=[{'Key': tag_key,
|
||||
'Value': tag_value}]
|
||||
)
|
||||
tags_response = client.describe_tags(ResourceName=cluster_arn)
|
||||
tagged_resources = tags_response['TaggedResources']
|
||||
list(tagged_resources).should.have.length_of(1)
|
||||
tagged_resources[0]['ResourceType'].should.equal('cluster')
|
||||
tagged_resources[0]['ResourceName'].should.equal(cluster_arn)
|
||||
tag = tagged_resources[0]['Tag']
|
||||
tag['Key'].should.equal(tag_key)
|
||||
tag['Value'].should.equal(tag_value)
|
||||
|
||||
client.create_cluster_snapshot(
|
||||
SnapshotIdentifier=snapshot_identifier,
|
||||
ClusterIdentifier=cluster_identifier,
|
||||
Tags=[{'Key': tag_key,
|
||||
'Value': tag_value}]
|
||||
)
|
||||
tags_response = client.describe_tags(ResourceName=snapshot_arn)
|
||||
tagged_resources = tags_response['TaggedResources']
|
||||
list(tagged_resources).should.have.length_of(1)
|
||||
tagged_resources[0]['ResourceType'].should.equal('snapshot')
|
||||
tagged_resources[0]['ResourceName'].should.equal(snapshot_arn)
|
||||
tag = tagged_resources[0]['Tag']
|
||||
tag['Key'].should.equal(tag_key)
|
||||
tag['Value'].should.equal(tag_value)
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_create_tags():
|
||||
client = boto3.client('redshift', region_name='us-east-1')
|
||||
cluster_identifier = 'cluster-id'
|
||||
cluster_arn = 'arn:aws:redshift:us-east-1:123456789012:' \
|
||||
'cluster:{}'.format(cluster_identifier)
|
||||
tag_key = 'test-tag-key'
|
||||
tag_value = 'test-tag-value'
|
||||
num_tags = 5
|
||||
tags = []
|
||||
for i in range(0, num_tags):
|
||||
tag = {'Key': '{}-{}'.format(tag_key, i),
|
||||
'Value': '{}-{}'.format(tag_value, i)}
|
||||
tags.append(tag)
|
||||
|
||||
client.create_cluster(
|
||||
DBName='test-db',
|
||||
|
|
@ -688,17 +868,125 @@ def test_describe_snapshot_tags():
|
|||
MasterUsername='username',
|
||||
MasterUserPassword='password',
|
||||
)
|
||||
|
||||
client.create_cluster_snapshot(
|
||||
SnapshotIdentifier=snapshot_identifier,
|
||||
ClusterIdentifier=cluster_identifier,
|
||||
Tags=[{'Key': tag_key,
|
||||
'Value': tag_value}]
|
||||
client.create_tags(
|
||||
ResourceName=cluster_arn,
|
||||
Tags=tags
|
||||
)
|
||||
response = client.describe_clusters(ClusterIdentifier=cluster_identifier)
|
||||
cluster = response['Clusters'][0]
|
||||
list(cluster['Tags']).should.have.length_of(num_tags)
|
||||
response = client.describe_tags(ResourceName=cluster_arn)
|
||||
list(response['TaggedResources']).should.have.length_of(num_tags)
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_delete_tags():
|
||||
client = boto3.client('redshift', region_name='us-east-1')
|
||||
cluster_identifier = 'cluster-id'
|
||||
cluster_arn = 'arn:aws:redshift:us-east-1:123456789012:' \
|
||||
'cluster:{}'.format(cluster_identifier)
|
||||
tag_key = 'test-tag-key'
|
||||
tag_value = 'test-tag-value'
|
||||
tags = []
|
||||
for i in range(1, 2):
|
||||
tag = {'Key': '{}-{}'.format(tag_key, i),
|
||||
'Value': '{}-{}'.format(tag_value, i)}
|
||||
tags.append(tag)
|
||||
|
||||
client.create_cluster(
|
||||
DBName='test-db',
|
||||
ClusterIdentifier=cluster_identifier,
|
||||
ClusterType='single-node',
|
||||
NodeType='ds2.xlarge',
|
||||
MasterUsername='username',
|
||||
MasterUserPassword='password',
|
||||
Tags=tags
|
||||
)
|
||||
client.delete_tags(
|
||||
ResourceName=cluster_arn,
|
||||
TagKeys=[tag['Key'] for tag in tags
|
||||
if tag['Key'] != '{}-1'.format(tag_key)]
|
||||
)
|
||||
response = client.describe_clusters(ClusterIdentifier=cluster_identifier)
|
||||
cluster = response['Clusters'][0]
|
||||
list(cluster['Tags']).should.have.length_of(1)
|
||||
response = client.describe_tags(ResourceName=cluster_arn)
|
||||
list(response['TaggedResources']).should.have.length_of(1)
|
||||
|
||||
|
||||
@mock_ec2
|
||||
@mock_redshift
|
||||
def test_describe_tags_all_resource_types():
|
||||
ec2 = boto3.resource('ec2', region_name='us-east-1')
|
||||
vpc = ec2.create_vpc(CidrBlock='10.0.0.0/16')
|
||||
subnet = ec2.create_subnet(VpcId=vpc.id, CidrBlock='10.0.0.0/24')
|
||||
client = boto3.client('redshift', region_name='us-east-1')
|
||||
response = client.describe_tags()
|
||||
list(response['TaggedResources']).should.have.length_of(0)
|
||||
client.create_cluster_subnet_group(
|
||||
ClusterSubnetGroupName='my_subnet_group',
|
||||
Description='This is my subnet group',
|
||||
SubnetIds=[subnet.id],
|
||||
Tags=[{'Key': 'tag_key',
|
||||
'Value': 'tag_value'}]
|
||||
)
|
||||
client.create_cluster_security_group(
|
||||
ClusterSecurityGroupName="security_group1",
|
||||
Description="This is my security group",
|
||||
Tags=[{'Key': 'tag_key',
|
||||
'Value': 'tag_value'}]
|
||||
)
|
||||
client.create_cluster(
|
||||
DBName='test',
|
||||
ClusterIdentifier='my_cluster',
|
||||
ClusterType='single-node',
|
||||
NodeType='ds2.xlarge',
|
||||
MasterUsername='user',
|
||||
MasterUserPassword='password',
|
||||
Tags=[{'Key': 'tag_key',
|
||||
'Value': 'tag_value'}]
|
||||
)
|
||||
client.create_cluster_snapshot(
|
||||
SnapshotIdentifier='my_snapshot',
|
||||
ClusterIdentifier='my_cluster',
|
||||
Tags=[{'Key': 'tag_key',
|
||||
'Value': 'tag_value'}]
|
||||
)
|
||||
client.create_cluster_parameter_group(
|
||||
ParameterGroupName="my_parameter_group",
|
||||
ParameterGroupFamily="redshift-1.0",
|
||||
Description="This is my parameter group",
|
||||
Tags=[{'Key': 'tag_key',
|
||||
'Value': 'tag_value'}]
|
||||
)
|
||||
response = client.describe_tags()
|
||||
expected_types = ['cluster', 'parametergroup', 'securitygroup', 'snapshot', 'subnetgroup']
|
||||
tagged_resources = response['TaggedResources']
|
||||
returned_types = [resource['ResourceType'] for resource in tagged_resources]
|
||||
list(tagged_resources).should.have.length_of(len(expected_types))
|
||||
set(returned_types).should.equal(set(expected_types))
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_tagged_resource_not_found_error():
|
||||
client = boto3.client('redshift', region_name='us-east-1')
|
||||
|
||||
cluster_arn = 'arn:aws:redshift:us-east-1::cluster:fake'
|
||||
client.describe_tags.when.called_with(
|
||||
ResourceName=cluster_arn
|
||||
).should.throw(ClientError, 'cluster (fake) not found.')
|
||||
|
||||
snapshot_arn = 'arn:aws:redshift:us-east-1::snapshot:cluster-id/snap-id'
|
||||
client.delete_tags.when.called_with(
|
||||
ResourceName=snapshot_arn,
|
||||
TagKeys=['test']
|
||||
).should.throw(ClientError, 'snapshot (snap-id) not found.')
|
||||
|
||||
client.describe_tags.when.called_with(
|
||||
ResourceType='cluster'
|
||||
).should.throw(ClientError, "resource of type 'cluster' not found.")
|
||||
|
||||
client.describe_tags.when.called_with(
|
||||
ResourceName='bad:arn'
|
||||
).should.throw(ClientError, "Tagging is not supported for this type of resource")
|
||||
|
||||
tags_response = client.describe_tags(ResourceType='Snapshot')
|
||||
tagged_resources = tags_response['TaggedResources']
|
||||
list(tagged_resources).should.have.length_of(1)
|
||||
tag = tagged_resources[0]['Tag']
|
||||
tag['Key'].should.equal(tag_key)
|
||||
tag['Value'].should.equal(tag_value)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ from freezegun import freeze_time
|
|||
import sure # noqa
|
||||
|
||||
from moto.packages.responses import responses
|
||||
from botocore.exceptions import ClientError
|
||||
from moto import mock_sns, mock_sqs
|
||||
from freezegun import freeze_time
|
||||
|
||||
|
|
@ -43,6 +44,49 @@ def test_publish_to_sqs():
|
|||
acquired_message.should.equal(expected)
|
||||
|
||||
|
||||
@mock_sns
|
||||
def test_publish_sms():
|
||||
client = boto3.client('sns', region_name='us-east-1')
|
||||
client.create_topic(Name="some-topic")
|
||||
resp = client.create_topic(Name="some-topic")
|
||||
arn = resp['TopicArn']
|
||||
|
||||
client.subscribe(
|
||||
TopicArn=arn,
|
||||
Protocol='sms',
|
||||
Endpoint='+15551234567'
|
||||
)
|
||||
|
||||
result = client.publish(PhoneNumber="+15551234567", Message="my message")
|
||||
result.should.contain('MessageId')
|
||||
|
||||
|
||||
@mock_sns
|
||||
def test_publish_bad_sms():
|
||||
client = boto3.client('sns', region_name='us-east-1')
|
||||
client.create_topic(Name="some-topic")
|
||||
resp = client.create_topic(Name="some-topic")
|
||||
arn = resp['TopicArn']
|
||||
|
||||
client.subscribe(
|
||||
TopicArn=arn,
|
||||
Protocol='sms',
|
||||
Endpoint='+15551234567'
|
||||
)
|
||||
|
||||
try:
|
||||
# Test invalid number
|
||||
client.publish(PhoneNumber="NAA+15551234567", Message="my message")
|
||||
except ClientError as err:
|
||||
err.response['Error']['Code'].should.equal('InvalidParameter')
|
||||
|
||||
try:
|
||||
# Test not found number
|
||||
client.publish(PhoneNumber="+44001234567", Message="my message")
|
||||
except ClientError as err:
|
||||
err.response['Error']['Code'].should.equal('ParameterValueInvalid')
|
||||
|
||||
|
||||
@mock_sqs
|
||||
@mock_sns
|
||||
def test_publish_to_sqs_dump_json():
|
||||
|
|
|
|||
|
|
@ -11,6 +11,39 @@ from moto import mock_sns
|
|||
from moto.sns.models import DEFAULT_PAGE_SIZE
|
||||
|
||||
|
||||
@mock_sns
|
||||
def test_subscribe_sms():
|
||||
client = boto3.client('sns', region_name='us-east-1')
|
||||
client.create_topic(Name="some-topic")
|
||||
resp = client.create_topic(Name="some-topic")
|
||||
arn = resp['TopicArn']
|
||||
|
||||
resp = client.subscribe(
|
||||
TopicArn=arn,
|
||||
Protocol='sms',
|
||||
Endpoint='+15551234567'
|
||||
)
|
||||
resp.should.contain('SubscriptionArn')
|
||||
|
||||
|
||||
@mock_sns
|
||||
def test_subscribe_bad_sms():
|
||||
client = boto3.client('sns', region_name='us-east-1')
|
||||
client.create_topic(Name="some-topic")
|
||||
resp = client.create_topic(Name="some-topic")
|
||||
arn = resp['TopicArn']
|
||||
|
||||
try:
|
||||
# Test invalid number
|
||||
client.subscribe(
|
||||
TopicArn=arn,
|
||||
Protocol='sms',
|
||||
Endpoint='NAA+15551234567'
|
||||
)
|
||||
except ClientError as err:
|
||||
err.response['Error']['Code'].should.equal('InvalidParameter')
|
||||
|
||||
|
||||
@mock_sns
|
||||
def test_creating_subscription():
|
||||
conn = boto3.client('sns', region_name='us-east-1')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue