moto/tests/test_dynamodb/test_dynamodb.py

60 lines
2.0 KiB
Python
Raw Normal View History

import boto
2014-08-26 17:25:50 +00:00
import boto.dynamodb
2021-10-18 19:44:29 +00:00
import sure # noqa # pylint: disable=unused-import
import pytest
2013-02-20 01:39:04 +00:00
from moto import mock_dynamodb, mock_dynamodb_deprecated
from moto.dynamodb import dynamodb_backend
2013-03-10 19:46:27 +00:00
from boto.exception import DynamoDBResponseError
def test_deprecation_warning():
with pytest.warns(None) as record:
mock_dynamodb()
str(record[0].message).should.contain(
"Module mock_dynamodb has been deprecated, and will be repurposed in a later release"
)
2021-09-22 21:22:56 +00:00
# Has boto3 equivalent
2017-02-16 03:35:45 +00:00
@mock_dynamodb_deprecated
2013-02-20 01:01:31 +00:00
def test_list_tables():
2019-10-31 15:44:26 +00:00
name = "TestTable"
dynamodb_backend.create_table(name, hash_key_attr="name", hash_key_type="S")
conn = boto.connect_dynamodb("the_key", "the_secret")
assert conn.list_tables() == ["TestTable"]
2013-02-20 01:39:04 +00:00
2017-02-16 03:35:45 +00:00
@mock_dynamodb_deprecated
def test_list_tables_layer_1():
2019-10-31 15:44:26 +00:00
dynamodb_backend.create_table("test_1", hash_key_attr="name", hash_key_type="S")
dynamodb_backend.create_table("test_2", hash_key_attr="name", hash_key_type="S")
conn = boto.connect_dynamodb("the_key", "the_secret")
res = conn.layer1.list_tables(limit=1)
expected = {"TableNames": ["test_1"], "LastEvaluatedTableName": "test_1"}
res.should.equal(expected)
res = conn.layer1.list_tables(limit=1, start_table="test_1")
expected = {"TableNames": ["test_2"]}
res.should.equal(expected)
2021-09-22 21:22:56 +00:00
# Has boto3 equivalent
2017-02-16 03:35:45 +00:00
@mock_dynamodb_deprecated
2013-03-10 19:46:27 +00:00
def test_describe_missing_table():
2019-10-31 15:44:26 +00:00
conn = boto.connect_dynamodb("the_key", "the_secret")
with pytest.raises(DynamoDBResponseError):
2019-10-31 15:44:26 +00:00
conn.describe_table("messages")
2013-03-17 22:39:21 +00:00
2021-09-22 21:22:56 +00:00
# Has boto3 equivalent
# This test is pointless though, as we treat DynamoDB as a global resource
2017-02-16 03:35:45 +00:00
@mock_dynamodb_deprecated
def test_dynamodb_with_connect_to_region():
# this will work if connected with boto.connect_dynamodb()
2019-10-31 15:44:26 +00:00
dynamodb = boto.dynamodb.connect_to_region("us-west-2")
2019-10-31 15:44:26 +00:00
schema = dynamodb.create_schema("column1", str(), "column2", int())
dynamodb.create_table("table1", schema, 200, 200)