Merge pull request #1869 from uncovertruth/master
Allow spaces to if_not_exists, attribute_exists and attribute_not_exists
This commit is contained in:
commit
ac13f86641
@ -154,7 +154,7 @@ class Item(BaseModel):
|
|||||||
# If not exists, changes value to a default if needed, else its the same as it was
|
# If not exists, changes value to a default if needed, else its the same as it was
|
||||||
if value.startswith('if_not_exists'):
|
if value.startswith('if_not_exists'):
|
||||||
# Function signature
|
# Function signature
|
||||||
match = re.match(r'.*if_not_exists\((?P<path>.+),\s*(?P<default>.+)\).*', value)
|
match = re.match(r'.*if_not_exists\s*\((?P<path>.+),\s*(?P<default>.+)\).*', value)
|
||||||
if not match:
|
if not match:
|
||||||
raise TypeError
|
raise TypeError
|
||||||
|
|
||||||
|
@ -204,9 +204,9 @@ class DynamoHandler(BaseResponse):
|
|||||||
if cond_items:
|
if cond_items:
|
||||||
expected = {}
|
expected = {}
|
||||||
overwrite = False
|
overwrite = False
|
||||||
exists_re = re.compile('^attribute_exists\((.*)\)$')
|
exists_re = re.compile('^attribute_exists\s*\((.*)\)$')
|
||||||
not_exists_re = re.compile(
|
not_exists_re = re.compile(
|
||||||
'^attribute_not_exists\((.*)\)$')
|
'^attribute_not_exists\s*\((.*)\)$')
|
||||||
|
|
||||||
for cond in cond_items:
|
for cond in cond_items:
|
||||||
exists_m = exists_re.match(cond)
|
exists_m = exists_re.match(cond)
|
||||||
@ -556,9 +556,9 @@ class DynamoHandler(BaseResponse):
|
|||||||
|
|
||||||
if cond_items:
|
if cond_items:
|
||||||
expected = {}
|
expected = {}
|
||||||
exists_re = re.compile('^attribute_exists\((.*)\)$')
|
exists_re = re.compile('^attribute_exists\s*\((.*)\)$')
|
||||||
not_exists_re = re.compile(
|
not_exists_re = re.compile(
|
||||||
'^attribute_not_exists\((.*)\)$')
|
'^attribute_not_exists\s*\((.*)\)$')
|
||||||
|
|
||||||
for cond in cond_items:
|
for cond in cond_items:
|
||||||
exists_m = exists_re.match(cond)
|
exists_m = exists_re.match(cond)
|
||||||
|
@ -700,7 +700,7 @@ def test_filter_expression():
|
|||||||
filter_expr = moto.dynamodb2.comparisons.get_filter_expression('Id IN :v0', {}, {':v0': {'NS': [7, 8, 9]}})
|
filter_expr = moto.dynamodb2.comparisons.get_filter_expression('Id IN :v0', {}, {':v0': {'NS': [7, 8, 9]}})
|
||||||
filter_expr.expr(row1).should.be(True)
|
filter_expr.expr(row1).should.be(True)
|
||||||
|
|
||||||
# attribute function tests
|
# attribute function tests (with extra spaces)
|
||||||
filter_expr = moto.dynamodb2.comparisons.get_filter_expression('attribute_exists(Id) AND attribute_not_exists (User)', {}, {})
|
filter_expr = moto.dynamodb2.comparisons.get_filter_expression('attribute_exists(Id) AND attribute_not_exists (User)', {}, {})
|
||||||
filter_expr.expr(row1).should.be(True)
|
filter_expr.expr(row1).should.be(True)
|
||||||
|
|
||||||
@ -1220,6 +1220,7 @@ def test_update_if_not_exists():
|
|||||||
'forum_name': 'the-key',
|
'forum_name': 'the-key',
|
||||||
'subject': '123'
|
'subject': '123'
|
||||||
},
|
},
|
||||||
|
# if_not_exists without space
|
||||||
UpdateExpression='SET created_at=if_not_exists(created_at,:created_at)',
|
UpdateExpression='SET created_at=if_not_exists(created_at,:created_at)',
|
||||||
ExpressionAttributeValues={
|
ExpressionAttributeValues={
|
||||||
':created_at': 123
|
':created_at': 123
|
||||||
@ -1233,6 +1234,7 @@ def test_update_if_not_exists():
|
|||||||
'forum_name': 'the-key',
|
'forum_name': 'the-key',
|
||||||
'subject': '123'
|
'subject': '123'
|
||||||
},
|
},
|
||||||
|
# if_not_exists with space
|
||||||
UpdateExpression='SET created_at = if_not_exists (created_at, :created_at)',
|
UpdateExpression='SET created_at = if_not_exists (created_at, :created_at)',
|
||||||
ExpressionAttributeValues={
|
ExpressionAttributeValues={
|
||||||
':created_at': 456
|
':created_at': 456
|
||||||
|
Loading…
Reference in New Issue
Block a user