DynamoDB - Error when providing table with 0 indexes (#4661)
This commit is contained in:
parent
c4338b8aea
commit
4e8e91d11a
@ -179,8 +179,20 @@ class DynamoHandler(BaseResponse):
|
|||||||
# getting attribute definition
|
# getting attribute definition
|
||||||
attr = body["AttributeDefinitions"]
|
attr = body["AttributeDefinitions"]
|
||||||
# getting the indexes
|
# getting the indexes
|
||||||
global_indexes = body.get("GlobalSecondaryIndexes", [])
|
global_indexes = body.get("GlobalSecondaryIndexes")
|
||||||
local_secondary_indexes = body.get("LocalSecondaryIndexes", [])
|
if global_indexes == []:
|
||||||
|
return self.error(
|
||||||
|
"ValidationException",
|
||||||
|
"One or more parameter values were invalid: List of GlobalSecondaryIndexes is empty",
|
||||||
|
)
|
||||||
|
global_indexes = global_indexes or []
|
||||||
|
local_secondary_indexes = body.get("LocalSecondaryIndexes")
|
||||||
|
if local_secondary_indexes == []:
|
||||||
|
return self.error(
|
||||||
|
"ValidationException",
|
||||||
|
"One or more parameter values were invalid: List of LocalSecondaryIndexes is empty",
|
||||||
|
)
|
||||||
|
local_secondary_indexes = local_secondary_indexes or []
|
||||||
# Verify AttributeDefinitions list all
|
# Verify AttributeDefinitions list all
|
||||||
expected_attrs = []
|
expected_attrs = []
|
||||||
expected_attrs.extend([key["AttributeName"] for key in key_schema])
|
expected_attrs.extend([key["AttributeName"] for key in key_schema])
|
||||||
|
@ -428,3 +428,41 @@ def test_hash_key_can_only_use_equals_operations(operator):
|
|||||||
err = exc.value.response["Error"]
|
err = exc.value.response["Error"]
|
||||||
err["Code"].should.equal("ValidationException")
|
err["Code"].should.equal("ValidationException")
|
||||||
err["Message"].should.equal("Query key condition not supported")
|
err["Message"].should.equal("Query key condition not supported")
|
||||||
|
|
||||||
|
|
||||||
|
@mock_dynamodb2
|
||||||
|
def test_creating_table_with_0_local_indexes():
|
||||||
|
dynamodb = boto3.resource("dynamodb", region_name="us-east-1")
|
||||||
|
|
||||||
|
with pytest.raises(ClientError) as exc:
|
||||||
|
dynamodb.create_table(
|
||||||
|
TableName="test-table",
|
||||||
|
KeySchema=[{"AttributeName": "pk", "KeyType": "HASH"}],
|
||||||
|
AttributeDefinitions=[{"AttributeName": "pk", "AttributeType": "S"}],
|
||||||
|
ProvisionedThroughput={"ReadCapacityUnits": 1, "WriteCapacityUnits": 1},
|
||||||
|
LocalSecondaryIndexes=[],
|
||||||
|
)
|
||||||
|
err = exc.value.response["Error"]
|
||||||
|
err["Code"].should.equal("ValidationException")
|
||||||
|
err["Message"].should.equal(
|
||||||
|
"One or more parameter values were invalid: List of LocalSecondaryIndexes is empty"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_dynamodb2
|
||||||
|
def test_creating_table_with_0_global_indexes():
|
||||||
|
dynamodb = boto3.resource("dynamodb", region_name="us-east-1")
|
||||||
|
|
||||||
|
with pytest.raises(ClientError) as exc:
|
||||||
|
dynamodb.create_table(
|
||||||
|
TableName="test-table",
|
||||||
|
KeySchema=[{"AttributeName": "pk", "KeyType": "HASH"}],
|
||||||
|
AttributeDefinitions=[{"AttributeName": "pk", "AttributeType": "S"}],
|
||||||
|
ProvisionedThroughput={"ReadCapacityUnits": 1, "WriteCapacityUnits": 1},
|
||||||
|
GlobalSecondaryIndexes=[],
|
||||||
|
)
|
||||||
|
err = exc.value.response["Error"]
|
||||||
|
err["Code"].should.equal("ValidationException")
|
||||||
|
err["Message"].should.equal(
|
||||||
|
"One or more parameter values were invalid: List of GlobalSecondaryIndexes is empty"
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user