DynamoDB: correct no table error (#6449)

This commit is contained in:
rafcio19 2023-06-27 22:06:49 +01:00 committed by GitHub
parent 1d50326585
commit 5c12416492
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 12 deletions

View File

@ -13,7 +13,6 @@ from moto.dynamodb.parsing.reserved_keywords import ReservedKeywords
from .exceptions import (
MockValidationException,
ResourceNotFoundException,
ConditionalCheckFailed,
)
from moto.dynamodb.models import dynamodb_backends, Table, DynamoDBBackend
from moto.dynamodb.models.utilities import dynamo_json_dump
@ -806,12 +805,7 @@ class DynamoHandler(BaseResponse):
if return_values not in ("ALL_OLD", "NONE"):
raise MockValidationException("Return values set to invalid value")
try:
self.dynamodb_backend.get_table(name)
except ResourceNotFoundException:
raise ConditionalCheckFailed(
"A condition specified in the operation could not be evaluated."
)
self.dynamodb_backend.get_table(name)
# Attempt to parse simple ConditionExpressions into an Expected
# expression

View File

@ -1753,6 +1753,38 @@ def test_delete_item():
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
def test_describe_limits():
client = boto3.client("dynamodb", region_name="eu-central-1")

View File

@ -197,11 +197,9 @@ def test_delete_item_with_undeclared_table():
TableName="messages", Key={"forum_name": {"S": "LOLCat Forum"}}
)
ex.value.response["Error"]["Code"].should.equal("ConditionalCheckFailedException")
ex.value.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(400)
ex.value.response["Error"]["Message"].should.equal(
"A condition specified in the operation could not be evaluated."
)
assert ex.value.response["Error"]["Code"] == "ResourceNotFoundException"
assert ex.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400
assert ex.value.response["Error"]["Message"] == "Requested resource not found"
@mock_dynamodb