Merge pull request #2014 from garyd203/dynamodb-set-comparison
Make EQ conditions on sets work reliably in DynamoDB
This commit is contained in:
commit
142fc65260
2 changed files with 47 additions and 10 deletions
|
|
@ -750,6 +750,47 @@ def test_boto3_update_item_conditions_pass_because_expect_exists_by_compare_to_n
|
|||
returned_item = table.get_item(Key={'username': 'johndoe'})
|
||||
assert dict(returned_item)['Item']['foo'].should.equal("baz")
|
||||
|
||||
|
||||
@mock_dynamodb2
|
||||
def test_boto3_update_settype_item_with_conditions():
|
||||
class OrderedSet(set):
|
||||
"""A set with predictable iteration order"""
|
||||
def __init__(self, values):
|
||||
super(OrderedSet, self).__init__(values)
|
||||
self.__ordered_values = values
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self.__ordered_values)
|
||||
|
||||
table = _create_user_table()
|
||||
table.put_item(Item={'username': 'johndoe'})
|
||||
table.update_item(
|
||||
Key={'username': 'johndoe'},
|
||||
UpdateExpression='SET foo=:new_value',
|
||||
ExpressionAttributeValues={
|
||||
':new_value': OrderedSet(['hello', 'world']),
|
||||
},
|
||||
)
|
||||
|
||||
table.update_item(
|
||||
Key={'username': 'johndoe'},
|
||||
UpdateExpression='SET foo=:new_value',
|
||||
ExpressionAttributeValues={
|
||||
':new_value': set(['baz']),
|
||||
},
|
||||
Expected={
|
||||
'foo': {
|
||||
'ComparisonOperator': 'EQ',
|
||||
'AttributeValueList': [
|
||||
OrderedSet(['world', 'hello']), # Opposite order to original
|
||||
],
|
||||
}
|
||||
},
|
||||
)
|
||||
returned_item = table.get_item(Key={'username': 'johndoe'})
|
||||
assert dict(returned_item)['Item']['foo'].should.equal(set(['baz']))
|
||||
|
||||
|
||||
@mock_dynamodb2
|
||||
def test_boto3_put_item_conditions_pass():
|
||||
table = _create_user_table()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue