Allow doing an ADD update of a string set

Fix test
This commit is contained in:
Brian Rower 2017-09-11 12:06:24 -07:00
parent 1d600011c5
commit 386ac94abe
2 changed files with 36 additions and 0 deletions

View File

@ -171,6 +171,12 @@ class Item(BaseModel):
decimal.Decimal(existing.value) +
decimal.Decimal(new_value)
)})
elif set(update_action['Value'].keys()) == set(['SS']):
existing = self.attrs.get(attribute_name, DynamoType({"SS": {}}))
new_set = set(existing.value).union(set(new_value))
self.attrs[attribute_name] = DynamoType({
"SS": list(new_set)
})
else:
# TODO: implement other data types
raise NotImplementedError(

View File

@ -1306,6 +1306,36 @@ def test_update_item_add_value():
})
@mock_dynamodb2
def test_update_item_add_value_string_set():
table = _create_table_with_range_key()
table.put_item(Item={
'forum_name': 'the-key',
'subject': '123',
'string_set': set(['str1', 'str2']),
})
item_key = {'forum_name': 'the-key', 'subject': '123'}
table.update_item(
Key=item_key,
AttributeUpdates={
'string_set': {
'Action': u'ADD',
'Value': set(['str3']),
},
},
)
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({
'string_set': set(['str1', 'str2', 'str3']),
'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()