Merge pull request #510 from pcraciunoiu/feature/dynamodb-add-value
Add value and UPDATE fixes
This commit is contained in:
commit
9596772546
4 changed files with 145 additions and 12 deletions
|
|
@ -941,6 +941,98 @@ def test_update_item_range_key_set():
|
|||
})
|
||||
|
||||
|
||||
|
||||
@mock_dynamodb2
|
||||
def test_update_item_does_not_exist_is_created():
|
||||
table = _create_table_with_range_key()
|
||||
|
||||
item_key = {'forum_name': 'the-key', 'subject': '123'}
|
||||
result = table.update_item(
|
||||
Key=item_key,
|
||||
AttributeUpdates={
|
||||
'username': {
|
||||
'Action': u'PUT',
|
||||
'Value': 'johndoe2'
|
||||
},
|
||||
'created': {
|
||||
'Action': u'PUT',
|
||||
'Value': Decimal('4'),
|
||||
},
|
||||
'mapfield': {
|
||||
'Action': u'PUT',
|
||||
'Value': {'key': 'value'},
|
||||
}
|
||||
},
|
||||
ReturnValues='ALL_OLD',
|
||||
)
|
||||
|
||||
assert not result.get('Attributes')
|
||||
|
||||
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({
|
||||
'username': "johndoe2",
|
||||
'forum_name': 'the-key',
|
||||
'subject': '123',
|
||||
'created': '4',
|
||||
'mapfield': {'key': 'value'},
|
||||
})
|
||||
|
||||
|
||||
@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()
|
||||
|
|
|
|||
|
|
@ -431,7 +431,7 @@ def test_update_item_remove():
|
|||
}
|
||||
table.put_item(data=data)
|
||||
key_map = {
|
||||
"S": "steve"
|
||||
'username': {"S": "steve"}
|
||||
}
|
||||
|
||||
# Then remove the SentBy field
|
||||
|
|
@ -456,7 +456,7 @@ def test_update_item_set():
|
|||
}
|
||||
table.put_item(data=data)
|
||||
key_map = {
|
||||
"S": "steve"
|
||||
'username': {"S": "steve"}
|
||||
}
|
||||
|
||||
conn.update_item("messages", key_map, update_expression="SET foo=:bar, blah=:baz REMOVE :SentBy")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue