Merge in functionality from #1899
This commit is contained in:
parent
770ad1db56
commit
2ec32c80f7
@ -185,6 +185,10 @@ class DynamoHandler(BaseResponse):
|
|||||||
item = self.body['Item']
|
item = self.body['Item']
|
||||||
return_values = self.body.get('ReturnValues', 'NONE')
|
return_values = self.body.get('ReturnValues', 'NONE')
|
||||||
|
|
||||||
|
if return_values not in ('ALL_OLD', 'NONE'):
|
||||||
|
er = 'com.amazonaws.dynamodb.v20111205#ValidationException'
|
||||||
|
return self.error(er, 'Return values set to invalid value')
|
||||||
|
|
||||||
if has_empty_keys_or_values(item):
|
if has_empty_keys_or_values(item):
|
||||||
return get_empty_str_error()
|
return get_empty_str_error()
|
||||||
|
|
||||||
@ -524,7 +528,11 @@ class DynamoHandler(BaseResponse):
|
|||||||
def delete_item(self):
|
def delete_item(self):
|
||||||
name = self.body['TableName']
|
name = self.body['TableName']
|
||||||
keys = self.body['Key']
|
keys = self.body['Key']
|
||||||
return_values = self.body.get('ReturnValues', '')
|
return_values = self.body.get('ReturnValues', 'NONE')
|
||||||
|
if return_values not in ('ALL_OLD', 'NONE'):
|
||||||
|
er = 'com.amazonaws.dynamodb.v20111205#ValidationException'
|
||||||
|
return self.error(er, 'Return values set to invalid value')
|
||||||
|
|
||||||
table = self.dynamodb_backend.get_table(name)
|
table = self.dynamodb_backend.get_table(name)
|
||||||
if not table:
|
if not table:
|
||||||
er = 'com.amazonaws.dynamodb.v20120810#ConditionalCheckFailedException'
|
er = 'com.amazonaws.dynamodb.v20120810#ConditionalCheckFailedException'
|
||||||
@ -554,6 +562,11 @@ class DynamoHandler(BaseResponse):
|
|||||||
else:
|
else:
|
||||||
existing_attributes = {}
|
existing_attributes = {}
|
||||||
|
|
||||||
|
if return_values not in ('NONE', 'ALL_OLD', 'ALL_NEW', 'UPDATED_OLD',
|
||||||
|
'UPDATED_NEW'):
|
||||||
|
er = 'com.amazonaws.dynamodb.v20111205#ValidationException'
|
||||||
|
return self.error(er, 'Return values set to invalid value')
|
||||||
|
|
||||||
if has_empty_keys_or_values(expression_attribute_values):
|
if has_empty_keys_or_values(expression_attribute_values):
|
||||||
return get_empty_str_error()
|
return get_empty_str_error()
|
||||||
|
|
||||||
|
@ -1000,6 +1000,11 @@ def test_delete_item():
|
|||||||
response = table.scan()
|
response = table.scan()
|
||||||
assert response['Count'] == 2
|
assert response['Count'] == 2
|
||||||
|
|
||||||
|
# Test ReturnValues validation
|
||||||
|
with assert_raises(ClientError) as ex:
|
||||||
|
table.delete_item(Key={'client': 'client1', 'app': 'app1'},
|
||||||
|
ReturnValues='ALL_NEW')
|
||||||
|
|
||||||
# Test deletion and returning old value
|
# Test deletion and returning old value
|
||||||
response = table.delete_item(Key={'client': 'client1', 'app': 'app1'}, ReturnValues='ALL_OLD')
|
response = table.delete_item(Key={'client': 'client1', 'app': 'app1'}, ReturnValues='ALL_OLD')
|
||||||
response['Attributes'].should.contain('client')
|
response['Attributes'].should.contain('client')
|
||||||
@ -1281,6 +1286,9 @@ def test_update_return_attributes():
|
|||||||
r = update('col1', 'val5', 'NONE')
|
r = update('col1', 'val5', 'NONE')
|
||||||
assert r['Attributes'] == {}
|
assert r['Attributes'] == {}
|
||||||
|
|
||||||
|
with assert_raises(ClientError) as ex:
|
||||||
|
r = update('col1', 'val6', 'WRONG')
|
||||||
|
|
||||||
|
|
||||||
@mock_dynamodb2
|
@mock_dynamodb2
|
||||||
def test_put_return_attributes():
|
def test_put_return_attributes():
|
||||||
@ -1307,6 +1315,15 @@ def test_put_return_attributes():
|
|||||||
)
|
)
|
||||||
assert r['Attributes'] == {'id': {'S': 'foo'}, 'col1': {'S': 'val1'}}
|
assert r['Attributes'] == {'id': {'S': 'foo'}, 'col1': {'S': 'val1'}}
|
||||||
|
|
||||||
|
with assert_raises(ClientError) as ex:
|
||||||
|
dynamodb.put_item(
|
||||||
|
TableName='moto-test',
|
||||||
|
Item={'id': {'S': 'foo'}, 'col1': {'S': 'val3'}},
|
||||||
|
ReturnValues='ALL_NEW'
|
||||||
|
)
|
||||||
|
ex.exception.response['Error']['Code'].should.equal('ValidationException')
|
||||||
|
ex.exception.response['ResponseMetadata']['HTTPStatusCode'].should.equal(400)
|
||||||
|
ex.exception.response['Error']['Message'].should.equal('Return values set to invalid value')
|
||||||
|
|
||||||
|
|
||||||
@mock_dynamodb2
|
@mock_dynamodb2
|
||||||
|
Loading…
Reference in New Issue
Block a user