Update upstream branch 'master' into instance_modify_security_groups
This commit is contained in:
commit
7476c63119
29 changed files with 1837 additions and 99 deletions
|
|
@ -1,6 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
import boto
|
||||
import six
|
||||
from nose.plugins.skip import SkipTest
|
||||
|
||||
|
||||
|
|
@ -24,19 +23,3 @@ class requires_boto_gte(object):
|
|||
if boto_version >= required:
|
||||
return test
|
||||
return skip_test
|
||||
|
||||
|
||||
class py3_requires_boto_gte(object):
|
||||
"""Decorator for requiring boto version greater than or equal to 'version'
|
||||
when running on Python 3. (Not all of boto is Python 3 compatible.)"""
|
||||
def __init__(self, version):
|
||||
self.version = version
|
||||
|
||||
def __call__(self, test):
|
||||
if not six.PY3:
|
||||
return test
|
||||
boto_version = version_tuple(boto.__version__)
|
||||
required = version_tuple(self.version)
|
||||
if boto_version >= required:
|
||||
return test
|
||||
return skip_test
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
from __future__ import unicode_literals
|
||||
import six
|
||||
|
||||
import boto
|
||||
import sure # noqa
|
||||
from freezegun import freeze_time
|
||||
|
||||
from moto import mock_dynamodb
|
||||
from tests.helpers import py3_requires_boto_gte
|
||||
|
||||
from boto.dynamodb import condition
|
||||
from boto.dynamodb.exceptions import DynamoDBKeyNotFoundError, DynamoDBValidationError
|
||||
|
|
@ -29,7 +28,6 @@ def create_table(conn):
|
|||
return table
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@freeze_time("2012-01-14")
|
||||
@mock_dynamodb
|
||||
def test_create_table():
|
||||
|
|
@ -62,7 +60,6 @@ def test_create_table():
|
|||
conn.describe_table('messages').should.equal(expected)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_delete_table():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -75,7 +72,6 @@ def test_delete_table():
|
|||
conn.layer1.delete_table.when.called_with('messages').should.throw(DynamoDBResponseError)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_update_table_throughput():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -90,7 +86,6 @@ def test_update_table_throughput():
|
|||
table.write_units.should.equal(6)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_item_add_and_describe_and_update():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -138,7 +133,6 @@ def test_item_add_and_describe_and_update():
|
|||
})
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_item_put_without_table():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -152,7 +146,6 @@ def test_item_put_without_table():
|
|||
).should.throw(DynamoDBResponseError)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_get_missing_item():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -165,7 +158,6 @@ def test_get_missing_item():
|
|||
table.has_item("foobar", "more").should.equal(False)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_get_item_with_undeclared_table():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -179,7 +171,6 @@ def test_get_item_with_undeclared_table():
|
|||
).should.throw(DynamoDBKeyNotFoundError)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_get_item_without_range_key():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -204,7 +195,6 @@ def test_get_item_without_range_key():
|
|||
table.get_item.when.called_with(hash_key=hash_key).should.throw(DynamoDBValidationError)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_delete_item():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -233,7 +223,6 @@ def test_delete_item():
|
|||
item.delete.when.called_with().should.throw(DynamoDBResponseError)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_delete_item_with_attribute_response():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -271,7 +260,6 @@ def test_delete_item_with_attribute_response():
|
|||
item.delete.when.called_with().should.throw(DynamoDBResponseError)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_delete_item_with_undeclared_table():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -285,7 +273,6 @@ def test_delete_item_with_undeclared_table():
|
|||
).should.throw(DynamoDBResponseError)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_query():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -336,7 +323,6 @@ def test_query():
|
|||
results.response['Items'].should.have.length_of(1)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_query_with_undeclared_table():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -353,7 +339,6 @@ def test_query_with_undeclared_table():
|
|||
).should.throw(DynamoDBResponseError)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_scan():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -417,7 +402,6 @@ def test_scan():
|
|||
results.response['Items'].should.have.length_of(1)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_scan_with_undeclared_table():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -435,7 +419,6 @@ def test_scan_with_undeclared_table():
|
|||
).should.throw(DynamoDBResponseError)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_write_batch():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -480,7 +463,6 @@ def test_write_batch():
|
|||
table.item_count.should.equal(1)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_batch_read():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
from __future__ import unicode_literals
|
||||
import six
|
||||
|
||||
import boto
|
||||
import sure # noqa
|
||||
from freezegun import freeze_time
|
||||
|
||||
from moto import mock_dynamodb
|
||||
from tests.helpers import py3_requires_boto_gte
|
||||
|
||||
from boto.dynamodb import condition
|
||||
from boto.dynamodb.exceptions import DynamoDBKeyNotFoundError
|
||||
|
|
@ -27,7 +26,6 @@ def create_table(conn):
|
|||
return table
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@freeze_time("2012-01-14")
|
||||
@mock_dynamodb
|
||||
def test_create_table():
|
||||
|
|
@ -56,7 +54,6 @@ def test_create_table():
|
|||
conn.describe_table('messages').should.equal(expected)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_delete_table():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -69,7 +66,6 @@ def test_delete_table():
|
|||
conn.layer1.delete_table.when.called_with('messages').should.throw(DynamoDBResponseError)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_update_table_throughput():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -84,7 +80,6 @@ def test_update_table_throughput():
|
|||
table.write_units.should.equal(6)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_item_add_and_describe_and_update():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -125,7 +120,6 @@ def test_item_add_and_describe_and_update():
|
|||
})
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_item_put_without_table():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -138,7 +132,6 @@ def test_item_put_without_table():
|
|||
).should.throw(DynamoDBResponseError)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_get_missing_item():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -149,7 +142,6 @@ def test_get_missing_item():
|
|||
).should.throw(DynamoDBKeyNotFoundError)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_get_item_with_undeclared_table():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -162,7 +154,6 @@ def test_get_item_with_undeclared_table():
|
|||
).should.throw(DynamoDBKeyNotFoundError)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_delete_item():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -190,7 +181,6 @@ def test_delete_item():
|
|||
item.delete.when.called_with().should.throw(DynamoDBResponseError)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_delete_item_with_attribute_response():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -226,7 +216,6 @@ def test_delete_item_with_attribute_response():
|
|||
item.delete.when.called_with().should.throw(DynamoDBResponseError)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_delete_item_with_undeclared_table():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -239,7 +228,6 @@ def test_delete_item_with_undeclared_table():
|
|||
).should.throw(DynamoDBResponseError)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_query():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -260,7 +248,6 @@ def test_query():
|
|||
results.response['Items'].should.have.length_of(1)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_query_with_undeclared_table():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -271,7 +258,6 @@ def test_query_with_undeclared_table():
|
|||
).should.throw(DynamoDBResponseError)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_scan():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -332,7 +318,6 @@ def test_scan():
|
|||
results.response['Items'].should.have.length_of(1)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_scan_with_undeclared_table():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -350,7 +335,6 @@ def test_scan_with_undeclared_table():
|
|||
).should.throw(DynamoDBResponseError)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_write_batch():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
@ -393,7 +377,6 @@ def test_write_batch():
|
|||
table.item_count.should.equal(1)
|
||||
|
||||
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb
|
||||
def test_batch_read():
|
||||
conn = boto.connect_dynamodb()
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
from __future__ import unicode_literals
|
||||
import six
|
||||
|
||||
import boto
|
||||
import sure # noqa
|
||||
from freezegun import freeze_time
|
||||
from moto import mock_dynamodb2
|
||||
from boto.exception import JSONResponseError
|
||||
from tests.helpers import requires_boto_gte, py3_requires_boto_gte
|
||||
from tests.helpers import requires_boto_gte
|
||||
try:
|
||||
from boto.dynamodb2.fields import HashKey
|
||||
from boto.dynamodb2.fields import RangeKey
|
||||
|
|
@ -33,7 +33,6 @@ def iterate_results(res):
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
@freeze_time("2012-01-14")
|
||||
def test_create_table():
|
||||
|
|
@ -61,7 +60,6 @@ def test_create_table():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_delete_table():
|
||||
conn = boto.dynamodb2.layer1.DynamoDBConnection()
|
||||
|
|
@ -74,7 +72,6 @@ def test_delete_table():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_update_table_throughput():
|
||||
table = create_table()
|
||||
|
|
@ -100,7 +97,6 @@ def test_update_table_throughput():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_item_add_and_describe_and_update():
|
||||
table = create_table()
|
||||
|
|
@ -144,7 +140,6 @@ def test_item_add_and_describe_and_update():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_item_put_without_table():
|
||||
table = Table('undeclared-table')
|
||||
|
|
@ -159,7 +154,6 @@ def test_item_put_without_table():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_get_missing_item():
|
||||
table = create_table()
|
||||
|
|
@ -171,7 +165,6 @@ def test_get_missing_item():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_get_item_with_undeclared_table():
|
||||
table = Table('undeclared-table')
|
||||
|
|
@ -179,7 +172,6 @@ def test_get_item_with_undeclared_table():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_get_item_without_range_key():
|
||||
table = Table.create('messages', schema=[
|
||||
|
|
@ -197,7 +189,6 @@ def test_get_item_without_range_key():
|
|||
|
||||
|
||||
@requires_boto_gte("2.30.0")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_delete_item():
|
||||
table = create_table()
|
||||
|
|
@ -220,7 +211,6 @@ def test_delete_item():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_delete_item_with_undeclared_table():
|
||||
table = Table("undeclared-table")
|
||||
|
|
@ -235,7 +225,6 @@ def test_delete_item_with_undeclared_table():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_query():
|
||||
table = create_table()
|
||||
|
|
@ -293,7 +282,6 @@ def test_query():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_query_with_undeclared_table():
|
||||
table = Table('undeclared')
|
||||
|
|
@ -306,7 +294,6 @@ def test_query_with_undeclared_table():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_scan():
|
||||
table = create_table()
|
||||
|
|
@ -362,7 +349,6 @@ def test_scan():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_scan_with_undeclared_table():
|
||||
conn = boto.dynamodb2.layer1.DynamoDBConnection()
|
||||
|
|
@ -380,7 +366,6 @@ def test_scan_with_undeclared_table():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_write_batch():
|
||||
table = create_table()
|
||||
|
|
@ -411,7 +396,6 @@ def test_write_batch():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_batch_read():
|
||||
table = create_table()
|
||||
|
|
@ -456,7 +440,6 @@ def test_batch_read():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_get_key_fields():
|
||||
table = create_table()
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
from __future__ import unicode_literals
|
||||
import six
|
||||
|
||||
import boto
|
||||
import sure # noqa
|
||||
from freezegun import freeze_time
|
||||
from boto.exception import JSONResponseError
|
||||
from moto import mock_dynamodb2
|
||||
from tests.helpers import requires_boto_gte, py3_requires_boto_gte
|
||||
from tests.helpers import requires_boto_gte
|
||||
try:
|
||||
from boto.dynamodb2.fields import HashKey
|
||||
from boto.dynamodb2.table import Table
|
||||
|
|
@ -25,7 +25,6 @@ def create_table():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
@freeze_time("2012-01-14")
|
||||
def test_create_table():
|
||||
|
|
@ -57,7 +56,6 @@ def test_create_table():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_delete_table():
|
||||
create_table()
|
||||
|
|
@ -71,7 +69,6 @@ def test_delete_table():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_update_table_throughput():
|
||||
table = create_table()
|
||||
|
|
@ -88,7 +85,6 @@ def test_update_table_throughput():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_item_add_and_describe_and_update():
|
||||
table = create_table()
|
||||
|
|
@ -123,7 +119,6 @@ def test_item_add_and_describe_and_update():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_item_put_without_table():
|
||||
conn = boto.dynamodb2.layer1.DynamoDBConnection()
|
||||
|
|
@ -139,7 +134,6 @@ def test_item_put_without_table():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_get_missing_item():
|
||||
table = create_table()
|
||||
|
|
@ -148,7 +142,6 @@ def test_get_missing_item():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_get_item_with_undeclared_table():
|
||||
conn = boto.dynamodb2.layer1.DynamoDBConnection()
|
||||
|
|
@ -160,7 +153,6 @@ def test_get_item_with_undeclared_table():
|
|||
|
||||
|
||||
@requires_boto_gte("2.30.0")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_delete_item():
|
||||
table = create_table()
|
||||
|
|
@ -185,7 +177,6 @@ def test_delete_item():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_delete_item_with_undeclared_table():
|
||||
conn = boto.dynamodb2.layer1.DynamoDBConnection()
|
||||
|
|
@ -197,7 +188,6 @@ def test_delete_item_with_undeclared_table():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_query():
|
||||
table = create_table()
|
||||
|
|
@ -218,7 +208,6 @@ def test_query():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_query_with_undeclared_table():
|
||||
conn = boto.dynamodb2.layer1.DynamoDBConnection()
|
||||
|
|
@ -230,7 +219,6 @@ def test_query_with_undeclared_table():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_scan():
|
||||
table = create_table()
|
||||
|
|
@ -282,7 +270,6 @@ def test_scan():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_scan_with_undeclared_table():
|
||||
conn = boto.dynamodb2.layer1.DynamoDBConnection()
|
||||
|
|
@ -301,7 +288,6 @@ def test_scan_with_undeclared_table():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_write_batch():
|
||||
table = create_table()
|
||||
|
|
@ -333,7 +319,6 @@ def test_write_batch():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_batch_read():
|
||||
table = create_table()
|
||||
|
|
@ -375,7 +360,6 @@ def test_batch_read():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_get_key_fields():
|
||||
table = create_table()
|
||||
|
|
@ -384,7 +368,6 @@ def test_get_key_fields():
|
|||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@py3_requires_boto_gte("2.33.0")
|
||||
@mock_dynamodb2
|
||||
def test_get_special_item():
|
||||
table = Table.create('messages', schema=[
|
||||
|
|
|
|||
239
tests/test_kinesis/test_kinesis.py
Normal file
239
tests/test_kinesis/test_kinesis.py
Normal file
|
|
@ -0,0 +1,239 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import boto.kinesis
|
||||
from boto.kinesis.exceptions import ResourceNotFoundException, InvalidArgumentException
|
||||
import sure # noqa
|
||||
|
||||
from moto import mock_kinesis
|
||||
|
||||
|
||||
@mock_kinesis
|
||||
def test_create_cluster():
|
||||
conn = boto.kinesis.connect_to_region("us-west-2")
|
||||
|
||||
conn.create_stream("my_stream", 2)
|
||||
|
||||
stream_response = conn.describe_stream("my_stream")
|
||||
|
||||
stream = stream_response["StreamDescription"]
|
||||
stream["StreamName"].should.equal("my_stream")
|
||||
stream["HasMoreShards"].should.equal(False)
|
||||
stream["StreamARN"].should.equal("arn:aws:kinesis:us-west-2:123456789012:my_stream")
|
||||
stream["StreamStatus"].should.equal("ACTIVE")
|
||||
|
||||
shards = stream['Shards']
|
||||
shards.should.have.length_of(2)
|
||||
|
||||
|
||||
@mock_kinesis
|
||||
def test_describe_non_existant_stream():
|
||||
conn = boto.kinesis.connect_to_region("us-east-1")
|
||||
conn.describe_stream.when.called_with("not-a-stream").should.throw(ResourceNotFoundException)
|
||||
|
||||
|
||||
@mock_kinesis
|
||||
def test_list_and_delete_stream():
|
||||
conn = boto.kinesis.connect_to_region("us-west-2")
|
||||
|
||||
conn.create_stream("stream1", 1)
|
||||
conn.create_stream("stream2", 1)
|
||||
|
||||
conn.list_streams()['StreamNames'].should.have.length_of(2)
|
||||
|
||||
conn.delete_stream("stream2")
|
||||
|
||||
conn.list_streams()['StreamNames'].should.have.length_of(1)
|
||||
|
||||
# Delete invalid id
|
||||
conn.delete_stream.when.called_with("not-a-stream").should.throw(ResourceNotFoundException)
|
||||
|
||||
|
||||
@mock_kinesis
|
||||
def test_basic_shard_iterator():
|
||||
conn = boto.kinesis.connect_to_region("us-west-2")
|
||||
|
||||
stream_name = "my_stream"
|
||||
conn.create_stream(stream_name, 1)
|
||||
|
||||
response = conn.describe_stream(stream_name)
|
||||
shard_id = response['StreamDescription']['Shards'][0]['ShardId']
|
||||
|
||||
response = conn.get_shard_iterator(stream_name, shard_id, 'TRIM_HORIZON')
|
||||
shard_iterator = response['ShardIterator']
|
||||
|
||||
response = conn.get_records(shard_iterator)
|
||||
shard_iterator = response['NextShardIterator']
|
||||
response['Records'].should.equal([])
|
||||
|
||||
|
||||
@mock_kinesis
|
||||
def test_get_invalid_shard_iterator():
|
||||
conn = boto.kinesis.connect_to_region("us-west-2")
|
||||
|
||||
stream_name = "my_stream"
|
||||
conn.create_stream(stream_name, 1)
|
||||
|
||||
conn.get_shard_iterator.when.called_with(stream_name, "123", 'TRIM_HORIZON').should.throw(ResourceNotFoundException)
|
||||
|
||||
|
||||
@mock_kinesis
|
||||
def test_put_records():
|
||||
conn = boto.kinesis.connect_to_region("us-west-2")
|
||||
|
||||
stream_name = "my_stream"
|
||||
conn.create_stream(stream_name, 1)
|
||||
|
||||
data = "hello world"
|
||||
partition_key = "1234"
|
||||
conn.put_record(stream_name, data, partition_key)
|
||||
|
||||
response = conn.describe_stream(stream_name)
|
||||
shard_id = response['StreamDescription']['Shards'][0]['ShardId']
|
||||
|
||||
response = conn.get_shard_iterator(stream_name, shard_id, 'TRIM_HORIZON')
|
||||
shard_iterator = response['ShardIterator']
|
||||
|
||||
response = conn.get_records(shard_iterator)
|
||||
shard_iterator = response['NextShardIterator']
|
||||
response['Records'].should.have.length_of(1)
|
||||
record = response['Records'][0]
|
||||
|
||||
record["Data"].should.equal("hello world")
|
||||
record["PartitionKey"].should.equal("1234")
|
||||
record["SequenceNumber"].should.equal("1")
|
||||
|
||||
|
||||
@mock_kinesis
|
||||
def test_get_records_limit():
|
||||
conn = boto.kinesis.connect_to_region("us-west-2")
|
||||
|
||||
stream_name = "my_stream"
|
||||
conn.create_stream(stream_name, 1)
|
||||
|
||||
# Create some data
|
||||
data = "hello world"
|
||||
for index in range(5):
|
||||
conn.put_record(stream_name, data, index)
|
||||
|
||||
# Get a shard iterator
|
||||
response = conn.describe_stream(stream_name)
|
||||
shard_id = response['StreamDescription']['Shards'][0]['ShardId']
|
||||
response = conn.get_shard_iterator(stream_name, shard_id, 'TRIM_HORIZON')
|
||||
shard_iterator = response['ShardIterator']
|
||||
|
||||
# Retrieve only 3 records
|
||||
response = conn.get_records(shard_iterator, limit=3)
|
||||
response['Records'].should.have.length_of(3)
|
||||
|
||||
# Then get the rest of the results
|
||||
next_shard_iterator = response['NextShardIterator']
|
||||
response = conn.get_records(next_shard_iterator)
|
||||
response['Records'].should.have.length_of(2)
|
||||
|
||||
|
||||
@mock_kinesis
|
||||
def test_get_records_at_sequence_number():
|
||||
# AT_SEQUENCE_NUMBER - Start reading exactly from the position denoted by a specific sequence number.
|
||||
conn = boto.kinesis.connect_to_region("us-west-2")
|
||||
stream_name = "my_stream"
|
||||
conn.create_stream(stream_name, 1)
|
||||
|
||||
# Create some data
|
||||
for index in range(1, 5):
|
||||
conn.put_record(stream_name, str(index), index)
|
||||
|
||||
# Get a shard iterator
|
||||
response = conn.describe_stream(stream_name)
|
||||
shard_id = response['StreamDescription']['Shards'][0]['ShardId']
|
||||
response = conn.get_shard_iterator(stream_name, shard_id, 'TRIM_HORIZON')
|
||||
shard_iterator = response['ShardIterator']
|
||||
|
||||
# Get the second record
|
||||
response = conn.get_records(shard_iterator, limit=2)
|
||||
second_sequence_id = response['Records'][1]['SequenceNumber']
|
||||
|
||||
# Then get a new iterator starting at that id
|
||||
response = conn.get_shard_iterator(stream_name, shard_id, 'AT_SEQUENCE_NUMBER', second_sequence_id)
|
||||
shard_iterator = response['ShardIterator']
|
||||
|
||||
response = conn.get_records(shard_iterator)
|
||||
# And the first result returned should be the second item
|
||||
response['Records'][0]['SequenceNumber'].should.equal(second_sequence_id)
|
||||
response['Records'][0]['Data'].should.equal('2')
|
||||
|
||||
|
||||
@mock_kinesis
|
||||
def test_get_records_after_sequence_number():
|
||||
# AFTER_SEQUENCE_NUMBER - Start reading right after the position denoted by a specific sequence number.
|
||||
conn = boto.kinesis.connect_to_region("us-west-2")
|
||||
stream_name = "my_stream"
|
||||
conn.create_stream(stream_name, 1)
|
||||
|
||||
# Create some data
|
||||
for index in range(1, 5):
|
||||
conn.put_record(stream_name, str(index), index)
|
||||
|
||||
# Get a shard iterator
|
||||
response = conn.describe_stream(stream_name)
|
||||
shard_id = response['StreamDescription']['Shards'][0]['ShardId']
|
||||
response = conn.get_shard_iterator(stream_name, shard_id, 'TRIM_HORIZON')
|
||||
shard_iterator = response['ShardIterator']
|
||||
|
||||
# Get the second record
|
||||
response = conn.get_records(shard_iterator, limit=2)
|
||||
second_sequence_id = response['Records'][1]['SequenceNumber']
|
||||
|
||||
# Then get a new iterator starting after that id
|
||||
response = conn.get_shard_iterator(stream_name, shard_id, 'AFTER_SEQUENCE_NUMBER', second_sequence_id)
|
||||
shard_iterator = response['ShardIterator']
|
||||
|
||||
response = conn.get_records(shard_iterator)
|
||||
# And the first result returned should be the third item
|
||||
response['Records'][0]['Data'].should.equal('3')
|
||||
|
||||
|
||||
@mock_kinesis
|
||||
def test_get_records_latest():
|
||||
# LATEST - Start reading just after the most recent record in the shard, so that you always read the most recent data in the shard.
|
||||
conn = boto.kinesis.connect_to_region("us-west-2")
|
||||
stream_name = "my_stream"
|
||||
conn.create_stream(stream_name, 1)
|
||||
|
||||
# Create some data
|
||||
for index in range(1, 5):
|
||||
conn.put_record(stream_name, str(index), index)
|
||||
|
||||
# Get a shard iterator
|
||||
response = conn.describe_stream(stream_name)
|
||||
shard_id = response['StreamDescription']['Shards'][0]['ShardId']
|
||||
response = conn.get_shard_iterator(stream_name, shard_id, 'TRIM_HORIZON')
|
||||
shard_iterator = response['ShardIterator']
|
||||
|
||||
# Get the second record
|
||||
response = conn.get_records(shard_iterator, limit=2)
|
||||
second_sequence_id = response['Records'][1]['SequenceNumber']
|
||||
|
||||
# Then get a new iterator starting after that id
|
||||
response = conn.get_shard_iterator(stream_name, shard_id, 'LATEST', second_sequence_id)
|
||||
shard_iterator = response['ShardIterator']
|
||||
|
||||
# Write some more data
|
||||
conn.put_record(stream_name, "last_record", "last_record")
|
||||
|
||||
response = conn.get_records(shard_iterator)
|
||||
# And the only result returned should be the new item
|
||||
response['Records'].should.have.length_of(1)
|
||||
response['Records'][0]['PartitionKey'].should.equal('last_record')
|
||||
response['Records'][0]['Data'].should.equal('last_record')
|
||||
|
||||
|
||||
@mock_kinesis
|
||||
def test_invalid_shard_iterator_type():
|
||||
conn = boto.kinesis.connect_to_region("us-west-2")
|
||||
stream_name = "my_stream"
|
||||
conn.create_stream(stream_name, 1)
|
||||
|
||||
response = conn.describe_stream(stream_name)
|
||||
shard_id = response['StreamDescription']['Shards'][0]['ShardId']
|
||||
response = conn.get_shard_iterator.when.called_with(
|
||||
stream_name, shard_id, 'invalid-type').should.throw(InvalidArgumentException)
|
||||
25
tests/test_kinesis/test_server.py
Normal file
25
tests/test_kinesis/test_server.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import json
|
||||
import sure # noqa
|
||||
|
||||
import moto.server as server
|
||||
from moto import mock_kinesis
|
||||
|
||||
'''
|
||||
Test the different server responses
|
||||
'''
|
||||
|
||||
|
||||
@mock_kinesis
|
||||
def test_list_streams():
|
||||
backend = server.create_backend_app("kinesis")
|
||||
test_client = backend.test_client()
|
||||
|
||||
res = test_client.get('/?Action=ListStreams')
|
||||
|
||||
json_data = json.loads(res.data.decode("utf-8"))
|
||||
json_data.should.equal({
|
||||
"HasMoreStreams": False,
|
||||
"StreamNames": [],
|
||||
})
|
||||
441
tests/test_redshift/test_redshift.py
Normal file
441
tests/test_redshift/test_redshift.py
Normal file
|
|
@ -0,0 +1,441 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import boto
|
||||
from boto.redshift.exceptions import (
|
||||
ClusterNotFound,
|
||||
ClusterParameterGroupNotFound,
|
||||
ClusterSecurityGroupNotFound,
|
||||
ClusterSubnetGroupNotFound,
|
||||
InvalidSubnet,
|
||||
)
|
||||
import sure # noqa
|
||||
|
||||
from moto import mock_ec2, mock_redshift
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_create_cluster():
|
||||
conn = boto.redshift.connect_to_region("us-east-1")
|
||||
cluster_identifier = 'my_cluster'
|
||||
|
||||
conn.create_cluster(
|
||||
cluster_identifier,
|
||||
node_type="dw.hs1.xlarge",
|
||||
master_username="username",
|
||||
master_user_password="password",
|
||||
db_name="my_db",
|
||||
cluster_type="multi-node",
|
||||
availability_zone="us-east-1d",
|
||||
preferred_maintenance_window="Mon:03:00-Mon:11:00",
|
||||
automated_snapshot_retention_period=10,
|
||||
port=1234,
|
||||
cluster_version="1.0",
|
||||
allow_version_upgrade=True,
|
||||
number_of_nodes=3,
|
||||
)
|
||||
|
||||
cluster_response = conn.describe_clusters(cluster_identifier)
|
||||
cluster = cluster_response['DescribeClustersResponse']['DescribeClustersResult']['Clusters'][0]
|
||||
|
||||
cluster['ClusterIdentifier'].should.equal(cluster_identifier)
|
||||
cluster['NodeType'].should.equal("dw.hs1.xlarge")
|
||||
cluster['MasterUsername'].should.equal("username")
|
||||
cluster['DBName'].should.equal("my_db")
|
||||
cluster['ClusterSecurityGroups'][0]['ClusterSecurityGroupName'].should.equal("Default")
|
||||
cluster['VpcSecurityGroups'].should.equal([])
|
||||
cluster['ClusterSubnetGroupName'].should.equal(None)
|
||||
cluster['AvailabilityZone'].should.equal("us-east-1d")
|
||||
cluster['PreferredMaintenanceWindow'].should.equal("Mon:03:00-Mon:11:00")
|
||||
cluster['ClusterParameterGroups'][0]['ParameterGroupName'].should.equal("default.redshift-1.0")
|
||||
cluster['AutomatedSnapshotRetentionPeriod'].should.equal(10)
|
||||
cluster['Port'].should.equal(1234)
|
||||
cluster['ClusterVersion'].should.equal("1.0")
|
||||
cluster['AllowVersionUpgrade'].should.equal(True)
|
||||
cluster['NumberOfNodes'].should.equal(3)
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_create_single_node_cluster():
|
||||
conn = boto.redshift.connect_to_region("us-east-1")
|
||||
cluster_identifier = 'my_cluster'
|
||||
|
||||
conn.create_cluster(
|
||||
cluster_identifier,
|
||||
node_type="dw.hs1.xlarge",
|
||||
master_username="username",
|
||||
master_user_password="password",
|
||||
db_name="my_db",
|
||||
cluster_type="single-node",
|
||||
)
|
||||
|
||||
cluster_response = conn.describe_clusters(cluster_identifier)
|
||||
cluster = cluster_response['DescribeClustersResponse']['DescribeClustersResult']['Clusters'][0]
|
||||
|
||||
cluster['ClusterIdentifier'].should.equal(cluster_identifier)
|
||||
cluster['NodeType'].should.equal("dw.hs1.xlarge")
|
||||
cluster['MasterUsername'].should.equal("username")
|
||||
cluster['DBName'].should.equal("my_db")
|
||||
cluster['NumberOfNodes'].should.equal(1)
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_default_cluster_attibutes():
|
||||
conn = boto.redshift.connect_to_region("us-east-1")
|
||||
cluster_identifier = 'my_cluster'
|
||||
|
||||
conn.create_cluster(
|
||||
cluster_identifier,
|
||||
node_type="dw.hs1.xlarge",
|
||||
master_username="username",
|
||||
master_user_password="password",
|
||||
)
|
||||
|
||||
cluster_response = conn.describe_clusters(cluster_identifier)
|
||||
cluster = cluster_response['DescribeClustersResponse']['DescribeClustersResult']['Clusters'][0]
|
||||
|
||||
cluster['DBName'].should.equal("dev")
|
||||
cluster['ClusterSubnetGroupName'].should.equal(None)
|
||||
assert "us-east-" in cluster['AvailabilityZone']
|
||||
cluster['PreferredMaintenanceWindow'].should.equal("Mon:03:00-Mon:03:30")
|
||||
cluster['ClusterParameterGroups'][0]['ParameterGroupName'].should.equal("default.redshift-1.0")
|
||||
cluster['AutomatedSnapshotRetentionPeriod'].should.equal(1)
|
||||
cluster['Port'].should.equal(5439)
|
||||
cluster['ClusterVersion'].should.equal("1.0")
|
||||
cluster['AllowVersionUpgrade'].should.equal(True)
|
||||
cluster['NumberOfNodes'].should.equal(1)
|
||||
|
||||
|
||||
@mock_redshift
|
||||
@mock_ec2
|
||||
def test_create_cluster_in_subnet_group():
|
||||
vpc_conn = boto.connect_vpc()
|
||||
vpc = vpc_conn.create_vpc("10.0.0.0/16")
|
||||
subnet = vpc_conn.create_subnet(vpc.id, "10.0.0.0/24")
|
||||
redshift_conn = boto.connect_redshift()
|
||||
redshift_conn.create_cluster_subnet_group(
|
||||
"my_subnet_group",
|
||||
"This is my subnet group",
|
||||
subnet_ids=[subnet.id],
|
||||
)
|
||||
|
||||
redshift_conn.create_cluster(
|
||||
"my_cluster",
|
||||
node_type="dw.hs1.xlarge",
|
||||
master_username="username",
|
||||
master_user_password="password",
|
||||
cluster_subnet_group_name='my_subnet_group',
|
||||
)
|
||||
|
||||
cluster_response = redshift_conn.describe_clusters("my_cluster")
|
||||
cluster = cluster_response['DescribeClustersResponse']['DescribeClustersResult']['Clusters'][0]
|
||||
cluster['ClusterSubnetGroupName'].should.equal('my_subnet_group')
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_create_cluster_with_security_group():
|
||||
conn = boto.redshift.connect_to_region("us-east-1")
|
||||
conn.create_cluster_security_group(
|
||||
"security_group1",
|
||||
"This is my security group",
|
||||
)
|
||||
conn.create_cluster_security_group(
|
||||
"security_group2",
|
||||
"This is my security group",
|
||||
)
|
||||
|
||||
cluster_identifier = 'my_cluster'
|
||||
conn.create_cluster(
|
||||
cluster_identifier,
|
||||
node_type="dw.hs1.xlarge",
|
||||
master_username="username",
|
||||
master_user_password="password",
|
||||
cluster_security_groups=["security_group1", "security_group2"]
|
||||
)
|
||||
|
||||
cluster_response = conn.describe_clusters(cluster_identifier)
|
||||
cluster = cluster_response['DescribeClustersResponse']['DescribeClustersResult']['Clusters'][0]
|
||||
group_names = [group['ClusterSecurityGroupName'] for group in cluster['ClusterSecurityGroups']]
|
||||
set(group_names).should.equal(set(["security_group1", "security_group2"]))
|
||||
|
||||
|
||||
@mock_redshift
|
||||
@mock_ec2
|
||||
def test_create_cluster_with_vpc_security_groups():
|
||||
vpc_conn = boto.connect_vpc()
|
||||
ec2_conn = boto.connect_ec2()
|
||||
redshift_conn = boto.connect_redshift()
|
||||
vpc = vpc_conn.create_vpc("10.0.0.0/16")
|
||||
security_group = ec2_conn.create_security_group("vpc_security_group", "a group", vpc_id=vpc.id)
|
||||
|
||||
redshift_conn.create_cluster(
|
||||
"my_cluster",
|
||||
node_type="dw.hs1.xlarge",
|
||||
master_username="username",
|
||||
master_user_password="password",
|
||||
vpc_security_group_ids=[security_group.id],
|
||||
)
|
||||
|
||||
cluster_response = redshift_conn.describe_clusters("my_cluster")
|
||||
cluster = cluster_response['DescribeClustersResponse']['DescribeClustersResult']['Clusters'][0]
|
||||
group_ids = [group['VpcSecurityGroupId'] for group in cluster['VpcSecurityGroups']]
|
||||
list(group_ids).should.equal([security_group.id])
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_create_cluster_with_parameter_group():
|
||||
conn = boto.connect_redshift()
|
||||
conn.create_cluster_parameter_group(
|
||||
"my_parameter_group",
|
||||
"redshift-1.0",
|
||||
"This is my parameter group",
|
||||
)
|
||||
|
||||
conn.create_cluster(
|
||||
"my_cluster",
|
||||
node_type="dw.hs1.xlarge",
|
||||
master_username="username",
|
||||
master_user_password="password",
|
||||
cluster_parameter_group_name='my_parameter_group',
|
||||
)
|
||||
|
||||
cluster_response = conn.describe_clusters("my_cluster")
|
||||
cluster = cluster_response['DescribeClustersResponse']['DescribeClustersResult']['Clusters'][0]
|
||||
cluster['ClusterParameterGroups'][0]['ParameterGroupName'].should.equal("my_parameter_group")
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_describe_non_existant_cluster():
|
||||
conn = boto.redshift.connect_to_region("us-east-1")
|
||||
conn.describe_clusters.when.called_with("not-a-cluster").should.throw(ClusterNotFound)
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_delete_cluster():
|
||||
conn = boto.connect_redshift()
|
||||
cluster_identifier = 'my_cluster'
|
||||
|
||||
conn.create_cluster(
|
||||
cluster_identifier,
|
||||
node_type='single-node',
|
||||
master_username="username",
|
||||
master_user_password="password",
|
||||
)
|
||||
|
||||
clusters = conn.describe_clusters()['DescribeClustersResponse']['DescribeClustersResult']['Clusters']
|
||||
list(clusters).should.have.length_of(1)
|
||||
|
||||
conn.delete_cluster(cluster_identifier)
|
||||
|
||||
clusters = conn.describe_clusters()['DescribeClustersResponse']['DescribeClustersResult']['Clusters']
|
||||
list(clusters).should.have.length_of(0)
|
||||
|
||||
# Delete invalid id
|
||||
conn.delete_cluster.when.called_with("not-a-cluster").should.throw(ClusterNotFound)
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_modify_cluster():
|
||||
conn = boto.connect_redshift()
|
||||
cluster_identifier = 'my_cluster'
|
||||
conn.create_cluster_security_group(
|
||||
"security_group",
|
||||
"This is my security group",
|
||||
)
|
||||
conn.create_cluster_parameter_group(
|
||||
"my_parameter_group",
|
||||
"redshift-1.0",
|
||||
"This is my parameter group",
|
||||
)
|
||||
|
||||
conn.create_cluster(
|
||||
cluster_identifier,
|
||||
node_type='single-node',
|
||||
master_username="username",
|
||||
master_user_password="password",
|
||||
)
|
||||
|
||||
conn.modify_cluster(
|
||||
cluster_identifier,
|
||||
cluster_type="multi-node",
|
||||
node_type="dw.hs1.xlarge",
|
||||
number_of_nodes=2,
|
||||
cluster_security_groups="security_group",
|
||||
master_user_password="new_password",
|
||||
cluster_parameter_group_name="my_parameter_group",
|
||||
automated_snapshot_retention_period=7,
|
||||
preferred_maintenance_window="Tue:03:00-Tue:11:00",
|
||||
allow_version_upgrade=False,
|
||||
new_cluster_identifier="new_identifier",
|
||||
)
|
||||
|
||||
cluster_response = conn.describe_clusters("new_identifier")
|
||||
cluster = cluster_response['DescribeClustersResponse']['DescribeClustersResult']['Clusters'][0]
|
||||
|
||||
cluster['ClusterIdentifier'].should.equal("new_identifier")
|
||||
cluster['NodeType'].should.equal("dw.hs1.xlarge")
|
||||
cluster['ClusterSecurityGroups'][0]['ClusterSecurityGroupName'].should.equal("security_group")
|
||||
cluster['PreferredMaintenanceWindow'].should.equal("Tue:03:00-Tue:11:00")
|
||||
cluster['ClusterParameterGroups'][0]['ParameterGroupName'].should.equal("my_parameter_group")
|
||||
cluster['AutomatedSnapshotRetentionPeriod'].should.equal(7)
|
||||
cluster['AllowVersionUpgrade'].should.equal(False)
|
||||
cluster['NumberOfNodes'].should.equal(2)
|
||||
|
||||
|
||||
@mock_redshift
|
||||
@mock_ec2
|
||||
def test_create_cluster_subnet_group():
|
||||
vpc_conn = boto.connect_vpc()
|
||||
vpc = vpc_conn.create_vpc("10.0.0.0/16")
|
||||
subnet1 = vpc_conn.create_subnet(vpc.id, "10.0.0.0/24")
|
||||
subnet2 = vpc_conn.create_subnet(vpc.id, "10.0.1.0/24")
|
||||
|
||||
redshift_conn = boto.connect_redshift()
|
||||
|
||||
redshift_conn.create_cluster_subnet_group(
|
||||
"my_subnet",
|
||||
"This is my subnet group",
|
||||
subnet_ids=[subnet1.id, subnet2.id],
|
||||
)
|
||||
|
||||
subnets_response = redshift_conn.describe_cluster_subnet_groups("my_subnet")
|
||||
my_subnet = subnets_response['DescribeClusterSubnetGroupsResponse']['DescribeClusterSubnetGroupsResult']['ClusterSubnetGroups'][0]
|
||||
|
||||
my_subnet['ClusterSubnetGroupName'].should.equal("my_subnet")
|
||||
my_subnet['Description'].should.equal("This is my subnet group")
|
||||
subnet_ids = [subnet['SubnetIdentifier'] for subnet in my_subnet['Subnets']]
|
||||
set(subnet_ids).should.equal(set([subnet1.id, subnet2.id]))
|
||||
|
||||
|
||||
@mock_redshift
|
||||
@mock_ec2
|
||||
def test_create_invalid_cluster_subnet_group():
|
||||
redshift_conn = boto.connect_redshift()
|
||||
redshift_conn.create_cluster_subnet_group.when.called_with(
|
||||
"my_subnet",
|
||||
"This is my subnet group",
|
||||
subnet_ids=["subnet-1234"],
|
||||
).should.throw(InvalidSubnet)
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_describe_non_existant_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)
|
||||
|
||||
|
||||
@mock_redshift
|
||||
@mock_ec2
|
||||
def test_delete_cluster_subnet_group():
|
||||
vpc_conn = boto.connect_vpc()
|
||||
vpc = vpc_conn.create_vpc("10.0.0.0/16")
|
||||
subnet = vpc_conn.create_subnet(vpc.id, "10.0.0.0/24")
|
||||
redshift_conn = boto.connect_redshift()
|
||||
|
||||
redshift_conn.create_cluster_subnet_group(
|
||||
"my_subnet",
|
||||
"This is my subnet group",
|
||||
subnet_ids=[subnet.id],
|
||||
)
|
||||
|
||||
subnets_response = redshift_conn.describe_cluster_subnet_groups()
|
||||
subnets = subnets_response['DescribeClusterSubnetGroupsResponse']['DescribeClusterSubnetGroupsResult']['ClusterSubnetGroups']
|
||||
subnets.should.have.length_of(1)
|
||||
|
||||
redshift_conn.delete_cluster_subnet_group("my_subnet")
|
||||
|
||||
subnets_response = redshift_conn.describe_cluster_subnet_groups()
|
||||
subnets = subnets_response['DescribeClusterSubnetGroupsResponse']['DescribeClusterSubnetGroupsResult']['ClusterSubnetGroups']
|
||||
subnets.should.have.length_of(0)
|
||||
|
||||
# Delete invalid id
|
||||
redshift_conn.delete_cluster_subnet_group.when.called_with("not-a-subnet-group").should.throw(ClusterSubnetGroupNotFound)
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_create_cluster_security_group():
|
||||
conn = boto.connect_redshift()
|
||||
conn.create_cluster_security_group(
|
||||
"my_security_group",
|
||||
"This is my security group",
|
||||
)
|
||||
|
||||
groups_response = conn.describe_cluster_security_groups("my_security_group")
|
||||
my_group = groups_response['DescribeClusterSecurityGroupsResponse']['DescribeClusterSecurityGroupsResult']['ClusterSecurityGroups'][0]
|
||||
|
||||
my_group['ClusterSecurityGroupName'].should.equal("my_security_group")
|
||||
my_group['Description'].should.equal("This is my security group")
|
||||
list(my_group['IPRanges']).should.equal([])
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_describe_non_existant_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)
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_delete_cluster_security_group():
|
||||
conn = boto.connect_redshift()
|
||||
conn.create_cluster_security_group(
|
||||
"my_security_group",
|
||||
"This is my security group",
|
||||
)
|
||||
|
||||
groups_response = conn.describe_cluster_security_groups()
|
||||
groups = groups_response['DescribeClusterSecurityGroupsResponse']['DescribeClusterSecurityGroupsResult']['ClusterSecurityGroups']
|
||||
groups.should.have.length_of(2) # The default group already exists
|
||||
|
||||
conn.delete_cluster_security_group("my_security_group")
|
||||
|
||||
groups_response = conn.describe_cluster_security_groups()
|
||||
groups = groups_response['DescribeClusterSecurityGroupsResponse']['DescribeClusterSecurityGroupsResult']['ClusterSecurityGroups']
|
||||
groups.should.have.length_of(1)
|
||||
|
||||
# Delete invalid id
|
||||
conn.delete_cluster_security_group.when.called_with("not-a-security-group").should.throw(ClusterSecurityGroupNotFound)
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_create_cluster_parameter_group():
|
||||
conn = boto.connect_redshift()
|
||||
conn.create_cluster_parameter_group(
|
||||
"my_parameter_group",
|
||||
"redshift-1.0",
|
||||
"This is my parameter group",
|
||||
)
|
||||
|
||||
groups_response = conn.describe_cluster_parameter_groups("my_parameter_group")
|
||||
my_group = groups_response['DescribeClusterParameterGroupsResponse']['DescribeClusterParameterGroupsResult']['ParameterGroups'][0]
|
||||
|
||||
my_group['ParameterGroupName'].should.equal("my_parameter_group")
|
||||
my_group['ParameterGroupFamily'].should.equal("redshift-1.0")
|
||||
my_group['Description'].should.equal("This is my parameter group")
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_describe_non_existant_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)
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_delete_cluster_parameter_group():
|
||||
conn = boto.connect_redshift()
|
||||
conn.create_cluster_parameter_group(
|
||||
"my_parameter_group",
|
||||
"redshift-1.0",
|
||||
"This is my parameter group",
|
||||
)
|
||||
|
||||
groups_response = conn.describe_cluster_parameter_groups()
|
||||
groups = groups_response['DescribeClusterParameterGroupsResponse']['DescribeClusterParameterGroupsResult']['ParameterGroups']
|
||||
groups.should.have.length_of(2) # The default group already exists
|
||||
|
||||
conn.delete_cluster_parameter_group("my_parameter_group")
|
||||
|
||||
groups_response = conn.describe_cluster_parameter_groups()
|
||||
groups = groups_response['DescribeClusterParameterGroupsResponse']['DescribeClusterParameterGroupsResult']['ParameterGroups']
|
||||
groups.should.have.length_of(1)
|
||||
|
||||
# Delete invalid id
|
||||
conn.delete_cluster_parameter_group.when.called_with("not-a-parameter-group").should.throw(ClusterParameterGroupNotFound)
|
||||
23
tests/test_redshift/test_server.py
Normal file
23
tests/test_redshift/test_server.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import json
|
||||
import sure # noqa
|
||||
|
||||
import moto.server as server
|
||||
from moto import mock_redshift
|
||||
|
||||
'''
|
||||
Test the different server responses
|
||||
'''
|
||||
|
||||
|
||||
@mock_redshift
|
||||
def test_describe_clusters():
|
||||
backend = server.create_backend_app("redshift")
|
||||
test_client = backend.test_client()
|
||||
|
||||
res = test_client.get('/?Action=DescribeClusters')
|
||||
|
||||
json_data = json.loads(res.data.decode("utf-8"))
|
||||
clusters = json_data['DescribeClustersResponse']['DescribeClustersResult']['Clusters']
|
||||
list(clusters).should.equal([])
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import unicode_literals
|
||||
from six.moves.urllib.request import urlopen
|
||||
from six.moves.urllib.error import HTTPError
|
||||
|
|
@ -615,3 +617,40 @@ def test_acl_is_ignored_for_now():
|
|||
key = bucket.get_key(keyname)
|
||||
|
||||
assert key.get_contents_as_string() == content
|
||||
|
||||
|
||||
@mock_s3
|
||||
def test_unicode_key():
|
||||
conn = boto.connect_s3()
|
||||
bucket = conn.create_bucket('mybucket')
|
||||
key = Key(bucket)
|
||||
key.key = u'こんにちは.jpg'
|
||||
key.set_contents_from_string('Hello world!')
|
||||
list(bucket.list())
|
||||
key = bucket.get_key(key.key)
|
||||
assert key.get_contents_as_string().decode("utf-8") == 'Hello world!'
|
||||
|
||||
|
||||
@mock_s3
|
||||
def test_unicode_value():
|
||||
conn = boto.connect_s3()
|
||||
bucket = conn.create_bucket('mybucket')
|
||||
key = Key(bucket)
|
||||
key.key = 'some_key'
|
||||
key.set_contents_from_string(u'こんにちは.jpg')
|
||||
list(bucket.list())
|
||||
key = bucket.get_key(key.key)
|
||||
assert key.get_contents_as_string().decode("utf-8") == u'こんにちは.jpg'
|
||||
|
||||
|
||||
@mock_s3
|
||||
def test_setting_content_encoding():
|
||||
conn = boto.connect_s3()
|
||||
bucket = conn.create_bucket('mybucket')
|
||||
key = bucket.new_key("keyname")
|
||||
key.set_metadata("Content-Encoding", "gzip")
|
||||
compressed_data = "abcdef"
|
||||
key.set_contents_from_string(compressed_data)
|
||||
|
||||
key = bucket.get_key("keyname")
|
||||
key.content_encoding.should.equal("gzip")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue