add test for attr doesn't exist
This commit is contained in:
parent
83082df4d9
commit
467f669c1e
@ -13,7 +13,6 @@ from moto.compat import OrderedDict
|
|||||||
from moto.core import BaseBackend, BaseModel
|
from moto.core import BaseBackend, BaseModel
|
||||||
from moto.core.utils import unix_time
|
from moto.core.utils import unix_time
|
||||||
from moto.core.exceptions import JsonRESTError
|
from moto.core.exceptions import JsonRESTError
|
||||||
from .comparisons import get_comparison_func, get_filter_expression, Op
|
|
||||||
from .comparisons import get_comparison_func
|
from .comparisons import get_comparison_func
|
||||||
from .comparisons import get_filter_expression
|
from .comparisons import get_filter_expression
|
||||||
from .comparisons import get_expected
|
from .comparisons import get_expected
|
||||||
|
@ -1563,7 +1563,6 @@ def test_dynamodb_streams_2():
|
|||||||
@mock_dynamodb2
|
@mock_dynamodb2
|
||||||
def test_condition_expressions():
|
def test_condition_expressions():
|
||||||
client = boto3.client('dynamodb', region_name='us-east-1')
|
client = boto3.client('dynamodb', region_name='us-east-1')
|
||||||
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
|
|
||||||
|
|
||||||
# Create the DynamoDB table.
|
# Create the DynamoDB table.
|
||||||
client.create_table(
|
client.create_table(
|
||||||
@ -1720,7 +1719,7 @@ def test_condition_expressions():
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Make sure update_item honors ConditionExpression as well
|
# Make sure update_item honors ConditionExpression as well
|
||||||
dynamodb.update_item(
|
client.update_item(
|
||||||
TableName='test1',
|
TableName='test1',
|
||||||
Key={
|
Key={
|
||||||
'client': {'S': 'client1'},
|
'client': {'S': 'client1'},
|
||||||
@ -1737,8 +1736,8 @@ def test_condition_expressions():
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
with assert_raises(dynamodb.exceptions.ConditionalCheckFailedException):
|
with assert_raises(client.exceptions.ConditionalCheckFailedException):
|
||||||
dynamodb.update_item(
|
client.update_item(
|
||||||
TableName='test1',
|
TableName='test1',
|
||||||
Key={
|
Key={
|
||||||
'client': { 'S': 'client1'},
|
'client': { 'S': 'client1'},
|
||||||
@ -1756,6 +1755,53 @@ def test_condition_expressions():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_dynamodb2
|
||||||
|
def test_condition_expression__attr_doesnt_exist():
|
||||||
|
client = boto3.client('dynamodb', region_name='us-east-1')
|
||||||
|
|
||||||
|
client.create_table(
|
||||||
|
TableName='test',
|
||||||
|
KeySchema=[{'AttributeName': 'forum_name', 'KeyType': 'HASH'}],
|
||||||
|
AttributeDefinitions=[
|
||||||
|
{'AttributeName': 'forum_name', 'AttributeType': 'S'},
|
||||||
|
],
|
||||||
|
ProvisionedThroughput={'ReadCapacityUnits': 1, 'WriteCapacityUnits': 1},
|
||||||
|
)
|
||||||
|
|
||||||
|
client.put_item(
|
||||||
|
TableName='test',
|
||||||
|
Item={
|
||||||
|
'forum_name': {'S': 'foo'},
|
||||||
|
'ttl': {'N': 'bar'},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def update_if_attr_doesnt_exist():
|
||||||
|
# Test nonexistent top-level attribute.
|
||||||
|
client.update_item(
|
||||||
|
TableName='test',
|
||||||
|
Key={
|
||||||
|
'forum_name': {'S': 'the-key'},
|
||||||
|
'subject': {'S': 'the-subject'},
|
||||||
|
},
|
||||||
|
UpdateExpression='set #new_state=:new_state, #ttl=:ttl',
|
||||||
|
ConditionExpression='attribute_not_exists(#new_state)',
|
||||||
|
ExpressionAttributeNames={'#new_state': 'foobar', '#ttl': 'ttl'},
|
||||||
|
ExpressionAttributeValues={
|
||||||
|
':new_state': {'S': 'some-value'},
|
||||||
|
':ttl': {'N': '12345.67'},
|
||||||
|
},
|
||||||
|
ReturnValues='ALL_NEW',
|
||||||
|
)
|
||||||
|
|
||||||
|
update_if_attr_doesnt_exist()
|
||||||
|
|
||||||
|
# Second time should fail
|
||||||
|
with assert_raises(client.exceptions.ConditionalCheckFailedException):
|
||||||
|
update_if_attr_doesnt_exist()
|
||||||
|
|
||||||
|
|
||||||
@mock_dynamodb2
|
@mock_dynamodb2
|
||||||
def test_query_gsi_with_range_key():
|
def test_query_gsi_with_range_key():
|
||||||
dynamodb = boto3.client('dynamodb', region_name='us-east-1')
|
dynamodb = boto3.client('dynamodb', region_name='us-east-1')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user