Merge branch 'master' of https://github.com/spulec/moto into add-empty-string-validation-exception

This commit is contained in:
Chris Keogh 2017-09-12 09:29:35 +12:00
commit 722859748e
7 changed files with 109 additions and 46 deletions

View file

@ -118,10 +118,11 @@ class Item(BaseModel):
def update(self, update_expression, expression_attribute_names, expression_attribute_values):
# Update subexpressions are identifiable by the operator keyword, so split on that and
# get rid of the empty leading string.
parts = [p for p in re.split(r'\b(SET|REMOVE|ADD|DELETE)\b', update_expression) if p]
parts = [p for p in re.split(r'\b(SET|REMOVE|ADD|DELETE)\b', update_expression, flags=re.I) if p]
# make sure that we correctly found only operator/value pairs
assert len(parts) % 2 == 0, "Mismatched operators and values in update expression: '{}'".format(update_expression)
for action, valstr in zip(parts[:-1:2], parts[1::2]):
action = action.upper()
values = valstr.split(',')
for value in values:
# A Real value
@ -171,6 +172,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

@ -151,8 +151,7 @@ class DynamoHandler(BaseResponse):
return 400, {'server': 'amazon.com'}, dynamo_json_dump(
{'__type': er,
'message': ('One or more parameter values were invalid: '
'An AttributeValue may not contain an empty string')
})
'An AttributeValue may not contain an empty string')})
overwrite = 'Expected' not in self.body
if not overwrite: