Add support for empty strings in non-key dynamo attributes (#3467)
* Add support for empty strings in non-key attributes https://github.com/spulec/moto/issues/3339 * Nose, not pytest * Revert "Nose, not pytest" This reverts commit 5a3cf6c887dd9fafa49096c82cfa3a3b7f91d224. * PUT is default action
This commit is contained in:
parent
62d382ff70
commit
f045af7e0a
8 changed files with 257 additions and 52 deletions
|
|
@ -186,7 +186,7 @@ def test_list_not_found_table_tags():
|
|||
|
||||
@requires_boto_gte("2.9")
|
||||
@mock_dynamodb2
|
||||
def test_item_add_empty_string_exception():
|
||||
def test_item_add_empty_string_in_key_exception():
|
||||
name = "TestTable"
|
||||
conn = boto3.client(
|
||||
"dynamodb",
|
||||
|
|
@ -205,10 +205,10 @@ def test_item_add_empty_string_exception():
|
|||
conn.put_item(
|
||||
TableName=name,
|
||||
Item={
|
||||
"forum_name": {"S": "LOLCat Forum"},
|
||||
"forum_name": {"S": ""},
|
||||
"subject": {"S": "Check this out!"},
|
||||
"Body": {"S": "http://url_to_lolcat.gif"},
|
||||
"SentBy": {"S": ""},
|
||||
"SentBy": {"S": "someone@somewhere.edu"},
|
||||
"ReceivedTime": {"S": "12/9/2011 11:36:03 PM"},
|
||||
},
|
||||
)
|
||||
|
|
@ -222,7 +222,36 @@ def test_item_add_empty_string_exception():
|
|||
|
||||
@requires_boto_gte("2.9")
|
||||
@mock_dynamodb2
|
||||
def test_update_item_with_empty_string_exception():
|
||||
def test_item_add_empty_string_no_exception():
|
||||
name = "TestTable"
|
||||
conn = boto3.client(
|
||||
"dynamodb",
|
||||
region_name="us-west-2",
|
||||
aws_access_key_id="ak",
|
||||
aws_secret_access_key="sk",
|
||||
)
|
||||
conn.create_table(
|
||||
TableName=name,
|
||||
KeySchema=[{"AttributeName": "forum_name", "KeyType": "HASH"}],
|
||||
AttributeDefinitions=[{"AttributeName": "forum_name", "AttributeType": "S"}],
|
||||
ProvisionedThroughput={"ReadCapacityUnits": 5, "WriteCapacityUnits": 5},
|
||||
)
|
||||
|
||||
conn.put_item(
|
||||
TableName=name,
|
||||
Item={
|
||||
"forum_name": {"S": "LOLCat Forum"},
|
||||
"subject": {"S": "Check this out!"},
|
||||
"Body": {"S": "http://url_to_lolcat.gif"},
|
||||
"SentBy": {"S": ""},
|
||||
"ReceivedTime": {"S": "12/9/2011 11:36:03 PM"},
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@mock_dynamodb2
|
||||
def test_update_item_with_empty_string_in_key_exception():
|
||||
name = "TestTable"
|
||||
conn = boto3.client(
|
||||
"dynamodb",
|
||||
|
|
@ -252,8 +281,8 @@ def test_update_item_with_empty_string_exception():
|
|||
conn.update_item(
|
||||
TableName=name,
|
||||
Key={"forum_name": {"S": "LOLCat Forum"}},
|
||||
UpdateExpression="set Body=:Body",
|
||||
ExpressionAttributeValues={":Body": {"S": ""}},
|
||||
UpdateExpression="set forum_name=:NewName",
|
||||
ExpressionAttributeValues={":NewName": {"S": ""}},
|
||||
)
|
||||
|
||||
ex.value.response["Error"]["Code"].should.equal("ValidationException")
|
||||
|
|
@ -263,6 +292,42 @@ def test_update_item_with_empty_string_exception():
|
|||
)
|
||||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@mock_dynamodb2
|
||||
def test_update_item_with_empty_string_no_exception():
|
||||
name = "TestTable"
|
||||
conn = boto3.client(
|
||||
"dynamodb",
|
||||
region_name="us-west-2",
|
||||
aws_access_key_id="ak",
|
||||
aws_secret_access_key="sk",
|
||||
)
|
||||
conn.create_table(
|
||||
TableName=name,
|
||||
KeySchema=[{"AttributeName": "forum_name", "KeyType": "HASH"}],
|
||||
AttributeDefinitions=[{"AttributeName": "forum_name", "AttributeType": "S"}],
|
||||
ProvisionedThroughput={"ReadCapacityUnits": 5, "WriteCapacityUnits": 5},
|
||||
)
|
||||
|
||||
conn.put_item(
|
||||
TableName=name,
|
||||
Item={
|
||||
"forum_name": {"S": "LOLCat Forum"},
|
||||
"subject": {"S": "Check this out!"},
|
||||
"Body": {"S": "http://url_to_lolcat.gif"},
|
||||
"SentBy": {"S": "test"},
|
||||
"ReceivedTime": {"S": "12/9/2011 11:36:03 PM"},
|
||||
},
|
||||
)
|
||||
|
||||
conn.update_item(
|
||||
TableName=name,
|
||||
Key={"forum_name": {"S": "LOLCat Forum"}},
|
||||
UpdateExpression="set Body=:Body",
|
||||
ExpressionAttributeValues={":Body": {"S": ""}},
|
||||
)
|
||||
|
||||
|
||||
@requires_boto_gte("2.9")
|
||||
@mock_dynamodb2
|
||||
def test_query_invalid_table():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue