moto/tests/test_dynamodb_v20111205/test_servermode.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
2.3 KiB
Python
Raw Normal View History

2022-03-09 17:57:25 +00:00
import json
from unittest import SkipTest
from uuid import uuid4
2022-03-09 17:57:25 +00:00
import requests
from moto import settings
"""
Test the different server responses
Docs:
2022-03-09 17:57:25 +00:00
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Appendix.APIv20111205.html
"""
def test_table_list():
if not settings.TEST_SERVER_MODE:
raise SkipTest("Only run test with external server")
headers = {
"X-Amz-Target": "DynamoDB_20111205.ListTables",
"AUTHORIZATION": "AWS4-HMAC-SHA256 Credential=ACCESS_KEY/20220226/us-east-1/dynamodb/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-target, Signature=sig",
2022-03-09 17:57:25 +00:00
}
requests.post(settings.test_server_mode_endpoint() + "/moto-api/reset")
res = requests.get(settings.test_server_mode_endpoint(), headers=headers)
assert res.status_code == 200
assert json.loads(res.content) == {"TableNames": []}
2022-03-09 17:57:25 +00:00
def test_create_table():
if not settings.TEST_SERVER_MODE:
raise SkipTest("Only run test with external server")
table_name = str(uuid4())
headers = {
"X-Amz-Target": "DynamoDB_20111205.CreateTable",
"Content-Type": "application/x-amz-json-1.0",
"AUTHORIZATION": "AWS4-HMAC-SHA256 Credential=ACCESS_KEY/20220226/us-east-1/dynamodb/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-target, Signature=sig",
}
request_body = {
"TableName": table_name,
"KeySchema": {
"HashKeyElement": {"AttributeName": "hkey", "AttributeType": "S"}
},
"ProvisionedThroughput": {"ReadCapacityUnits": 5, "WriteCapacityUnits": 10},
}
res = requests.post(
settings.test_server_mode_endpoint(), headers=headers, json=request_body
)
res = json.loads(res.content)["Table"]
assert "CreationDateTime" in res
2022-03-09 17:57:25 +00:00
del res["CreationDateTime"]
assert res == {
"KeySchema": {
"HashKeyElement": {"AttributeName": "hkey", "AttributeType": "S"}
},
"ProvisionedThroughput": {"ReadCapacityUnits": 5, "WriteCapacityUnits": 10},
"TableName": table_name,
"TableStatus": "ACTIVE",
"ItemCount": 0,
"TableSizeBytes": 0,
}
2022-03-09 17:57:25 +00:00
headers["X-Amz-Target"] = "DynamoDB_20111205.ListTables"
res = requests.get(settings.test_server_mode_endpoint(), headers=headers)
res = json.loads(res.content)
assert table_name in res["TableNames"]