2023-02-27 23:05:50 +00:00
|
|
|
import json
|
2021-10-18 19:44:29 +00:00
|
|
|
import sure # noqa # pylint: disable=unused-import
|
2023-02-27 23:05:50 +00:00
|
|
|
from moto import mock_dynamodb
|
2013-03-05 13:14:43 +00:00
|
|
|
import moto.server as server
|
|
|
|
|
2019-10-31 15:44:26 +00:00
|
|
|
"""
|
2013-03-05 13:14:43 +00:00
|
|
|
Test the different server responses
|
2019-10-31 15:44:26 +00:00
|
|
|
"""
|
2013-03-05 13:14:43 +00:00
|
|
|
|
2013-12-29 01:15:37 +00:00
|
|
|
|
2023-02-27 23:05:50 +00:00
|
|
|
@mock_dynamodb
|
2022-03-09 17:57:25 +00:00
|
|
|
def test_table_list():
|
|
|
|
backend = server.create_backend_app("dynamodb")
|
|
|
|
test_client = backend.test_client()
|
2019-10-31 15:44:26 +00:00
|
|
|
res = test_client.get("/")
|
2013-03-05 13:14:43 +00:00
|
|
|
res.status_code.should.equal(404)
|
|
|
|
|
2021-09-22 21:22:56 +00:00
|
|
|
headers = {"X-Amz-Target": "TestTable.ListTables"}
|
|
|
|
res = test_client.get("/", headers=headers)
|
2022-03-09 17:57:25 +00:00
|
|
|
res.data.should.contain(b"TableNames")
|
|
|
|
res.headers.should.have.key("X-Amz-Crc32")
|
2023-02-27 23:05:50 +00:00
|
|
|
|
|
|
|
headers = {"X-Amz-Target": "DynamoDB_20120810.DescribeTable"}
|
|
|
|
res = test_client.post(
|
|
|
|
"/", headers=headers, data=json.dumps({"TableName": "test-table2"})
|
|
|
|
)
|
2023-03-02 14:28:21 +00:00
|
|
|
res.headers.should.have.key("X-Amzn-ErrorType").equals("ResourceNotFoundException")
|
2023-02-27 23:05:50 +00:00
|
|
|
body = json.loads(res.data.decode("utf-8"))
|
|
|
|
body.should.equal(
|
|
|
|
{
|
|
|
|
"__type": "com.amazonaws.dynamodb.v20120810#ResourceNotFoundException",
|
|
|
|
"message": "Requested resource not found: Table: test-table2 not found",
|
|
|
|
}
|
|
|
|
)
|