moto/tests/test_dynamodb2/test_dynamodb.py

67 lines
2.0 KiB
Python
Raw Normal View History

2014-08-26 17:25:50 +00:00
from __future__ import unicode_literals, print_function
import six
2013-12-05 11:16:56 +00:00
import boto
import sure # noqa
import requests
2017-02-16 03:35:45 +00:00
from moto import mock_dynamodb2, mock_dynamodb2_deprecated
2013-12-05 11:16:56 +00:00
from moto.dynamodb2 import dynamodb_backend2
from boto.exception import JSONResponseError
from tests.helpers import requires_boto_gte
2014-08-26 17:25:50 +00:00
import tests.backport_assert_raises
from nose.tools import assert_raises
try:
import boto.dynamodb2
except ImportError:
2014-08-26 17:25:50 +00:00
print("This boto version is not supported")
2013-12-05 11:16:56 +00:00
2017-02-24 02:37:43 +00:00
@requires_boto_gte("2.9")
2017-02-16 03:35:45 +00:00
@mock_dynamodb2_deprecated
2013-12-05 11:16:56 +00:00
def test_list_tables():
name = 'TestTable'
#{'schema': }
2017-02-24 02:37:43 +00:00
dynamodb_backend2.create_table(name, schema=[
{u'KeyType': u'HASH', u'AttributeName': u'forum_name'},
2013-12-05 11:16:56 +00:00
{u'KeyType': u'RANGE', u'AttributeName': u'subject'}
])
2017-02-24 02:37:43 +00:00
conn = boto.dynamodb2.connect_to_region(
'us-west-2',
2013-12-05 11:16:56 +00:00
aws_access_key_id="ak",
aws_secret_access_key="sk")
assert conn.list_tables()["TableNames"] == [name]
@requires_boto_gte("2.9")
2017-02-16 03:35:45 +00:00
@mock_dynamodb2_deprecated
2013-12-05 11:16:56 +00:00
def test_list_tables_layer_1():
2017-02-24 02:37:43 +00:00
dynamodb_backend2.create_table("test_1", schema=[
2013-12-05 11:16:56 +00:00
{u'KeyType': u'HASH', u'AttributeName': u'name'}
])
2017-02-24 02:37:43 +00:00
dynamodb_backend2.create_table("test_2", schema=[
2013-12-05 11:16:56 +00:00
{u'KeyType': u'HASH', u'AttributeName': u'name'}
])
2017-02-24 02:37:43 +00:00
conn = boto.dynamodb2.connect_to_region(
2013-12-05 11:16:56 +00:00
'us-west-2',
aws_access_key_id="ak",
aws_secret_access_key="sk")
2013-12-05 11:16:56 +00:00
res = conn.list_tables(limit=1)
expected = {"TableNames": ["test_1"], "LastEvaluatedTableName": "test_1"}
res.should.equal(expected)
res = conn.list_tables(limit=1, exclusive_start_table_name="test_1")
expected = {"TableNames": ["test_2"]}
res.should.equal(expected)
@requires_boto_gte("2.9")
2017-02-16 03:35:45 +00:00
@mock_dynamodb2_deprecated
2013-12-05 11:16:56 +00:00
def test_describe_missing_table():
2017-02-24 02:37:43 +00:00
conn = boto.dynamodb2.connect_to_region(
2013-12-05 11:16:56 +00:00
'us-west-2',
aws_access_key_id="ak",
aws_secret_access_key="sk")
2014-08-26 17:25:50 +00:00
with assert_raises(JSONResponseError):
conn.describe_table('messages')