DynamoDB: correct no table error (#6449)
This commit is contained in:
parent
1d50326585
commit
5c12416492
@ -13,7 +13,6 @@ from moto.dynamodb.parsing.reserved_keywords import ReservedKeywords
|
|||||||
from .exceptions import (
|
from .exceptions import (
|
||||||
MockValidationException,
|
MockValidationException,
|
||||||
ResourceNotFoundException,
|
ResourceNotFoundException,
|
||||||
ConditionalCheckFailed,
|
|
||||||
)
|
)
|
||||||
from moto.dynamodb.models import dynamodb_backends, Table, DynamoDBBackend
|
from moto.dynamodb.models import dynamodb_backends, Table, DynamoDBBackend
|
||||||
from moto.dynamodb.models.utilities import dynamo_json_dump
|
from moto.dynamodb.models.utilities import dynamo_json_dump
|
||||||
@ -806,12 +805,7 @@ class DynamoHandler(BaseResponse):
|
|||||||
if return_values not in ("ALL_OLD", "NONE"):
|
if return_values not in ("ALL_OLD", "NONE"):
|
||||||
raise MockValidationException("Return values set to invalid value")
|
raise MockValidationException("Return values set to invalid value")
|
||||||
|
|
||||||
try:
|
self.dynamodb_backend.get_table(name)
|
||||||
self.dynamodb_backend.get_table(name)
|
|
||||||
except ResourceNotFoundException:
|
|
||||||
raise ConditionalCheckFailed(
|
|
||||||
"A condition specified in the operation could not be evaluated."
|
|
||||||
)
|
|
||||||
|
|
||||||
# Attempt to parse simple ConditionExpressions into an Expected
|
# Attempt to parse simple ConditionExpressions into an Expected
|
||||||
# expression
|
# expression
|
||||||
|
@ -1753,6 +1753,38 @@ def test_delete_item():
|
|||||||
assert response["Count"] == 0
|
assert response["Count"] == 0
|
||||||
|
|
||||||
|
|
||||||
|
@mock_dynamodb
|
||||||
|
def test_delete_item_error():
|
||||||
|
# Setup
|
||||||
|
client = boto3.resource("dynamodb", region_name="us-east-1")
|
||||||
|
# Create the DynamoDB table.
|
||||||
|
client.create_table(
|
||||||
|
TableName="test1",
|
||||||
|
AttributeDefinitions=[
|
||||||
|
{"AttributeName": "client", "AttributeType": "S"},
|
||||||
|
{"AttributeName": "app", "AttributeType": "S"},
|
||||||
|
],
|
||||||
|
KeySchema=[
|
||||||
|
{"AttributeName": "client", "KeyType": "HASH"},
|
||||||
|
{"AttributeName": "app", "KeyType": "RANGE"},
|
||||||
|
],
|
||||||
|
BillingMode="PAY_PER_REQUEST",
|
||||||
|
)
|
||||||
|
table = client.Table("test1")
|
||||||
|
table.delete()
|
||||||
|
|
||||||
|
# Execute
|
||||||
|
with pytest.raises(ClientError) as ex:
|
||||||
|
table.delete_item(
|
||||||
|
Key={"client": "client1", "app": "app1"},
|
||||||
|
)
|
||||||
|
|
||||||
|
# Verify
|
||||||
|
err = ex.value.response["Error"]
|
||||||
|
assert err["Code"] == "ResourceNotFoundException"
|
||||||
|
assert err["Message"] == "Requested resource not found"
|
||||||
|
|
||||||
|
|
||||||
@mock_dynamodb
|
@mock_dynamodb
|
||||||
def test_describe_limits():
|
def test_describe_limits():
|
||||||
client = boto3.client("dynamodb", region_name="eu-central-1")
|
client = boto3.client("dynamodb", region_name="eu-central-1")
|
||||||
|
@ -197,11 +197,9 @@ def test_delete_item_with_undeclared_table():
|
|||||||
TableName="messages", Key={"forum_name": {"S": "LOLCat Forum"}}
|
TableName="messages", Key={"forum_name": {"S": "LOLCat Forum"}}
|
||||||
)
|
)
|
||||||
|
|
||||||
ex.value.response["Error"]["Code"].should.equal("ConditionalCheckFailedException")
|
assert ex.value.response["Error"]["Code"] == "ResourceNotFoundException"
|
||||||
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
|
assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400
|
||||||
ex.value.response["Error"]["Message"].should.equal(
|
assert ex.value.response["Error"]["Message"] == "Requested resource not found"
|
||||||
"A condition specified in the operation could not be evaluated."
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@mock_dynamodb
|
@mock_dynamodb
|
||||||
|
Loading…
Reference in New Issue
Block a user