Support ADD for numeric values

This commit is contained in:
Paul Craciunoiu 2016-01-14 15:44:28 -07:00
commit bdd4ae824b
2 changed files with 65 additions and 0 deletions

View file

@ -888,6 +888,60 @@ def test_update_item_does_not_exist_is_created():
})
@mock_dynamodb2
def test_update_item_add_value():
table = _create_table_with_range_key()
table.put_item(Item={
'forum_name': 'the-key',
'subject': '123',
'numeric_field': Decimal('-1'),
})
item_key = {'forum_name': 'the-key', 'subject': '123'}
table.update_item(
Key=item_key,
AttributeUpdates={
'numeric_field': {
'Action': u'ADD',
'Value': Decimal('2'),
},
},
)
returned_item = dict((k, str(v) if isinstance(v, Decimal) else v)
for k, v in table.get_item(Key=item_key)['Item'].items())
dict(returned_item).should.equal({
'numeric_field': '1',
'forum_name': 'the-key',
'subject': '123',
})
@mock_dynamodb2
def test_update_item_add_value_does_not_exist_is_created():
table = _create_table_with_range_key()
item_key = {'forum_name': 'the-key', 'subject': '123'}
table.update_item(
Key=item_key,
AttributeUpdates={
'numeric_field': {
'Action': u'ADD',
'Value': Decimal('2'),
},
},
)
returned_item = dict((k, str(v) if isinstance(v, Decimal) else v)
for k, v in table.get_item(Key=item_key)['Item'].items())
dict(returned_item).should.equal({
'numeric_field': '2',
'forum_name': 'the-key',
'subject': '123',
})
@mock_dynamodb2
def test_boto3_query_gsi_range_comparison():
table = _create_table_with_range_key()