Merge branch 'master' of https://github.com/spulec/moto
This commit is contained in:
commit
631252dd50
19 changed files with 758 additions and 74 deletions
94
tests/test_cloudwatch/test_cloudwatch_boto3.py
Normal file
94
tests/test_cloudwatch/test_cloudwatch_boto3.py
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
import sure # noqa
|
||||
|
||||
from moto import mock_cloudwatch
|
||||
|
||||
|
||||
@mock_cloudwatch
|
||||
def test_put_list_dashboard():
|
||||
client = boto3.client('cloudwatch', region_name='eu-central-1')
|
||||
widget = '{"widgets": [{"type": "text", "x": 0, "y": 7, "width": 3, "height": 3, "properties": {"markdown": "Hello world"}}]}'
|
||||
|
||||
client.put_dashboard(DashboardName='test1', DashboardBody=widget)
|
||||
resp = client.list_dashboards()
|
||||
|
||||
len(resp['DashboardEntries']).should.equal(1)
|
||||
|
||||
|
||||
@mock_cloudwatch
|
||||
def test_put_list_prefix_nomatch_dashboard():
|
||||
client = boto3.client('cloudwatch', region_name='eu-central-1')
|
||||
widget = '{"widgets": [{"type": "text", "x": 0, "y": 7, "width": 3, "height": 3, "properties": {"markdown": "Hello world"}}]}'
|
||||
|
||||
client.put_dashboard(DashboardName='test1', DashboardBody=widget)
|
||||
resp = client.list_dashboards(DashboardNamePrefix='nomatch')
|
||||
|
||||
len(resp['DashboardEntries']).should.equal(0)
|
||||
|
||||
|
||||
@mock_cloudwatch
|
||||
def test_delete_dashboard():
|
||||
client = boto3.client('cloudwatch', region_name='eu-central-1')
|
||||
widget = '{"widgets": [{"type": "text", "x": 0, "y": 7, "width": 3, "height": 3, "properties": {"markdown": "Hello world"}}]}'
|
||||
|
||||
client.put_dashboard(DashboardName='test1', DashboardBody=widget)
|
||||
client.put_dashboard(DashboardName='test2', DashboardBody=widget)
|
||||
client.put_dashboard(DashboardName='test3', DashboardBody=widget)
|
||||
client.delete_dashboards(DashboardNames=['test2', 'test1'])
|
||||
|
||||
resp = client.list_dashboards(DashboardNamePrefix='test3')
|
||||
len(resp['DashboardEntries']).should.equal(1)
|
||||
|
||||
|
||||
@mock_cloudwatch
|
||||
def test_delete_dashboard_fail():
|
||||
client = boto3.client('cloudwatch', region_name='eu-central-1')
|
||||
widget = '{"widgets": [{"type": "text", "x": 0, "y": 7, "width": 3, "height": 3, "properties": {"markdown": "Hello world"}}]}'
|
||||
|
||||
client.put_dashboard(DashboardName='test1', DashboardBody=widget)
|
||||
client.put_dashboard(DashboardName='test2', DashboardBody=widget)
|
||||
client.put_dashboard(DashboardName='test3', DashboardBody=widget)
|
||||
# Doesnt delete anything if all dashboards to be deleted do not exist
|
||||
try:
|
||||
client.delete_dashboards(DashboardNames=['test2', 'test1', 'test_no_match'])
|
||||
except ClientError as err:
|
||||
err.response['Error']['Code'].should.equal('ResourceNotFound')
|
||||
else:
|
||||
raise RuntimeError('Should of raised error')
|
||||
|
||||
resp = client.list_dashboards()
|
||||
len(resp['DashboardEntries']).should.equal(3)
|
||||
|
||||
|
||||
@mock_cloudwatch
|
||||
def test_get_dashboard():
|
||||
client = boto3.client('cloudwatch', region_name='eu-central-1')
|
||||
widget = '{"widgets": [{"type": "text", "x": 0, "y": 7, "width": 3, "height": 3, "properties": {"markdown": "Hello world"}}]}'
|
||||
client.put_dashboard(DashboardName='test1', DashboardBody=widget)
|
||||
|
||||
resp = client.get_dashboard(DashboardName='test1')
|
||||
resp.should.contain('DashboardArn')
|
||||
resp.should.contain('DashboardBody')
|
||||
resp['DashboardName'].should.equal('test1')
|
||||
|
||||
|
||||
@mock_cloudwatch
|
||||
def test_get_dashboard_fail():
|
||||
client = boto3.client('cloudwatch', region_name='eu-central-1')
|
||||
|
||||
try:
|
||||
client.get_dashboard(DashboardName='test1')
|
||||
except ClientError as err:
|
||||
err.response['Error']['Code'].should.equal('ResourceNotFound')
|
||||
else:
|
||||
raise RuntimeError('Should of raised error')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -884,6 +884,10 @@ def test_s3_object_in_public_bucket():
|
|||
s3_anonymous.Object(key='file.txt', bucket_name='test-bucket').get()
|
||||
exc.exception.response['Error']['Code'].should.equal('403')
|
||||
|
||||
params = {'Bucket': 'test-bucket','Key': 'file.txt'}
|
||||
presigned_url = boto3.client('s3').generate_presigned_url('get_object', params, ExpiresIn=900)
|
||||
response = requests.get(presigned_url)
|
||||
assert response.status_code == 200
|
||||
|
||||
@mock_s3
|
||||
def test_s3_object_in_private_bucket():
|
||||
|
|
|
|||
|
|
@ -321,3 +321,30 @@ def test_publish_to_disabled_platform_endpoint():
|
|||
MessageStructure="json",
|
||||
TargetArn=endpoint_arn,
|
||||
).should.throw(ClientError)
|
||||
|
||||
|
||||
@mock_sns
|
||||
def test_set_sms_attributes():
|
||||
conn = boto3.client('sns', region_name='us-east-1')
|
||||
|
||||
conn.set_sms_attributes(attributes={'DefaultSMSType': 'Transactional', 'test': 'test'})
|
||||
|
||||
response = conn.get_sms_attributes()
|
||||
response.should.contain('attributes')
|
||||
response['attributes'].should.contain('DefaultSMSType')
|
||||
response['attributes'].should.contain('test')
|
||||
response['attributes']['DefaultSMSType'].should.equal('Transactional')
|
||||
response['attributes']['test'].should.equal('test')
|
||||
|
||||
|
||||
@mock_sns
|
||||
def test_get_sms_attributes_filtered():
|
||||
conn = boto3.client('sns', region_name='us-east-1')
|
||||
|
||||
conn.set_sms_attributes(attributes={'DefaultSMSType': 'Transactional', 'test': 'test'})
|
||||
|
||||
response = conn.get_sms_attributes(attributes=['DefaultSMSType'])
|
||||
response.should.contain('attributes')
|
||||
response['attributes'].should.contain('DefaultSMSType')
|
||||
response['attributes'].should_not.contain('test')
|
||||
response['attributes']['DefaultSMSType'].should.equal('Transactional')
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ def test_creating_subscription():
|
|||
"ListSubscriptionsResult"]["Subscriptions"]
|
||||
subscriptions.should.have.length_of(0)
|
||||
|
||||
|
||||
@mock_sns_deprecated
|
||||
def test_deleting_subscriptions_by_deleting_topic():
|
||||
conn = boto.connect_sns()
|
||||
|
|
@ -66,6 +67,7 @@ def test_deleting_subscriptions_by_deleting_topic():
|
|||
"ListSubscriptionsResult"]["Subscriptions"]
|
||||
subscriptions.should.have.length_of(0)
|
||||
|
||||
|
||||
@mock_sns_deprecated
|
||||
def test_getting_subscriptions_by_topic():
|
||||
conn = boto.connect_sns()
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ def test_creating_subscription():
|
|||
subscriptions = conn.list_subscriptions()["Subscriptions"]
|
||||
subscriptions.should.have.length_of(0)
|
||||
|
||||
|
||||
@mock_sns
|
||||
def test_deleting_subscriptions_by_deleting_topic():
|
||||
conn = boto3.client('sns', region_name='us-east-1')
|
||||
|
|
@ -68,6 +69,7 @@ def test_deleting_subscriptions_by_deleting_topic():
|
|||
subscriptions = conn.list_subscriptions()["Subscriptions"]
|
||||
subscriptions.should.have.length_of(0)
|
||||
|
||||
|
||||
@mock_sns
|
||||
def test_getting_subscriptions_by_topic():
|
||||
conn = boto3.client('sns', region_name='us-east-1')
|
||||
|
|
@ -197,3 +199,67 @@ def test_set_subscription_attributes():
|
|||
AttributeName='InvalidName',
|
||||
AttributeValue='true'
|
||||
)
|
||||
|
||||
|
||||
@mock_sns
|
||||
def test_check_not_opted_out():
|
||||
conn = boto3.client('sns', region_name='us-east-1')
|
||||
response = conn.check_if_phone_number_is_opted_out(phoneNumber='+447428545375')
|
||||
|
||||
response.should.contain('isOptedOut')
|
||||
response['isOptedOut'].should.be(False)
|
||||
|
||||
|
||||
@mock_sns
|
||||
def test_check_opted_out():
|
||||
# Phone number ends in 99 so is hardcoded in the endpoint to return opted
|
||||
# out status
|
||||
conn = boto3.client('sns', region_name='us-east-1')
|
||||
response = conn.check_if_phone_number_is_opted_out(phoneNumber='+447428545399')
|
||||
|
||||
response.should.contain('isOptedOut')
|
||||
response['isOptedOut'].should.be(True)
|
||||
|
||||
|
||||
@mock_sns
|
||||
def test_check_opted_out_invalid():
|
||||
conn = boto3.client('sns', region_name='us-east-1')
|
||||
|
||||
# Invalid phone number
|
||||
with assert_raises(ClientError):
|
||||
conn.check_if_phone_number_is_opted_out(phoneNumber='+44742LALALA')
|
||||
|
||||
|
||||
@mock_sns
|
||||
def test_list_opted_out():
|
||||
conn = boto3.client('sns', region_name='us-east-1')
|
||||
response = conn.list_phone_numbers_opted_out()
|
||||
|
||||
response.should.contain('phoneNumbers')
|
||||
len(response['phoneNumbers']).should.be.greater_than(0)
|
||||
|
||||
|
||||
@mock_sns
|
||||
def test_opt_in():
|
||||
conn = boto3.client('sns', region_name='us-east-1')
|
||||
response = conn.list_phone_numbers_opted_out()
|
||||
current_len = len(response['phoneNumbers'])
|
||||
assert current_len > 0
|
||||
|
||||
conn.opt_in_phone_number(phoneNumber=response['phoneNumbers'][0])
|
||||
|
||||
response = conn.list_phone_numbers_opted_out()
|
||||
len(response['phoneNumbers']).should.be.greater_than(0)
|
||||
len(response['phoneNumbers']).should.be.lower_than(current_len)
|
||||
|
||||
|
||||
@mock_sns
|
||||
def test_confirm_subscription():
|
||||
conn = boto3.client('sns', region_name='us-east-1')
|
||||
response = conn.create_topic(Name='testconfirm')
|
||||
|
||||
conn.confirm_subscription(
|
||||
TopicArn=response['TopicArn'],
|
||||
Token='2336412f37fb687f5d51e6e241d59b68c4e583a5cee0be6f95bbf97ab8d2441cf47b99e848408adaadf4c197e65f03473d53c4ba398f6abbf38ce2e8ebf7b4ceceb2cd817959bcde1357e58a2861b05288c535822eb88cac3db04f592285249971efc6484194fc4a4586147f16916692',
|
||||
AuthenticateOnUnsubscribe='true'
|
||||
)
|
||||
|
|
|
|||
|
|
@ -129,3 +129,20 @@ def test_topic_paging():
|
|||
response.shouldnt.have("NextToken")
|
||||
|
||||
topics_list.should.have.length_of(int(DEFAULT_PAGE_SIZE / 2))
|
||||
|
||||
|
||||
@mock_sns
|
||||
def test_add_remove_permissions():
|
||||
conn = boto3.client('sns', region_name='us-east-1')
|
||||
response = conn.create_topic(Name='testpermissions')
|
||||
|
||||
conn.add_permission(
|
||||
TopicArn=response['TopicArn'],
|
||||
Label='Test1234',
|
||||
AWSAccountId=['999999999999'],
|
||||
ActionName=['AddPermission']
|
||||
)
|
||||
conn.remove_permission(
|
||||
TopicArn=response['TopicArn'],
|
||||
Label='Test1234'
|
||||
)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ from boto.exception import SQSError
|
|||
from boto.sqs.message import RawMessage, Message
|
||||
|
||||
import base64
|
||||
import requests
|
||||
import sure # noqa
|
||||
import time
|
||||
|
||||
|
|
@ -18,6 +17,39 @@ import tests.backport_assert_raises # noqa
|
|||
from nose.tools import assert_raises
|
||||
|
||||
|
||||
@mock_sqs
|
||||
def test_create_fifo_queue_fail():
|
||||
sqs = boto3.client('sqs', region_name='us-east-1')
|
||||
|
||||
try:
|
||||
sqs.create_queue(
|
||||
QueueName='test-queue',
|
||||
Attributes={
|
||||
'FifoQueue': 'true',
|
||||
}
|
||||
)
|
||||
except botocore.exceptions.ClientError as err:
|
||||
err.response['Error']['Code'].should.equal('InvalidParameterValue')
|
||||
else:
|
||||
raise RuntimeError('Should of raised InvalidParameterValue Exception')
|
||||
|
||||
@mock_sqs
|
||||
def test_create_fifo_queue():
|
||||
sqs = boto3.client('sqs', region_name='us-east-1')
|
||||
resp = sqs.create_queue(
|
||||
QueueName='test-queue.fifo',
|
||||
Attributes={
|
||||
'FifoQueue': 'true',
|
||||
}
|
||||
)
|
||||
queue_url = resp['QueueUrl']
|
||||
|
||||
response = sqs.get_queue_attributes(QueueUrl=queue_url)
|
||||
response['Attributes'].should.contain('FifoQueue')
|
||||
response['Attributes']['FifoQueue'].should.equal('true')
|
||||
|
||||
|
||||
|
||||
@mock_sqs
|
||||
def test_create_queue():
|
||||
sqs = boto3.resource('sqs', region_name='us-east-1')
|
||||
|
|
@ -39,6 +71,7 @@ def test_get_inexistent_queue():
|
|||
sqs.get_queue_by_name.when.called_with(
|
||||
QueueName='nonexisting-queue').should.throw(botocore.exceptions.ClientError)
|
||||
|
||||
|
||||
@mock_sqs
|
||||
def test_message_send_without_attributes():
|
||||
sqs = boto3.resource('sqs', region_name='us-east-1')
|
||||
|
|
@ -56,6 +89,7 @@ def test_message_send_without_attributes():
|
|||
messages = queue.receive_messages()
|
||||
messages.should.have.length_of(1)
|
||||
|
||||
|
||||
@mock_sqs
|
||||
def test_message_send_with_attributes():
|
||||
sqs = boto3.resource('sqs', region_name='us-east-1')
|
||||
|
|
@ -229,6 +263,7 @@ def test_send_receive_message_without_attributes():
|
|||
message1.shouldnt.have.key('MD5OfMessageAttributes')
|
||||
message2.shouldnt.have.key('MD5OfMessageAttributes')
|
||||
|
||||
|
||||
@mock_sqs
|
||||
def test_send_receive_message_with_attributes():
|
||||
sqs = boto3.resource('sqs', region_name='us-east-1')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue