return validation error for empty attribute

This commit is contained in:
Chris Keogh 2017-09-12 09:28:36 +12:00
parent a0283fc1ca
commit ed820cc80e
2 changed files with 40 additions and 0 deletions

View File

@ -144,6 +144,16 @@ class DynamoHandler(BaseResponse):
def put_item(self):
name = self.body['TableName']
item = self.body['Item']
res = re.search('\"\"', json.dumps(item))
if res:
er = 'com.amazonaws.dynamodb.v20111205#ValidationException'
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')
})
overwrite = 'Expected' not in self.body
if not overwrite:
expected = self.body['Expected']

View File

@ -149,3 +149,33 @@ def test_list_not_found_table_tags():
conn.list_tags_of_resource(ResourceArn=arn)
except ClientError as exception:
assert exception.response['Error']['Code'] == "ResourceNotFoundException"
@requires_boto_gte("2.9")
@mock_dynamodb2
def test_item_add_empty_string_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})
session = boto3.Session()
dynamodb = session.resource('dynamodb',
region_name='us-west-2',
aws_access_key_id="ak",
aws_secret_access_key="sk")
table = dynamodb.Table('TestTable')
try:
response = table.put_item(Item={
'forum_name': 'LOLCat Forum',
'subject': 'Check this out!',
'Body': 'http://url_to_lolcat.gif',
'SentBy': "",
'ReceivedTime': '12/9/2011 11:36:03 PM',
})
except ClientError as exception:
assert exception.response['Error']['Code'] == "ValidationException"