Merge branch 'master' into bugfix/2384
This commit is contained in:
commit
34d4379b9f
10 changed files with 389 additions and 121 deletions
|
|
@ -1245,3 +1245,175 @@ def test_delete_event_source_mapping():
|
|||
assert response['State'] == 'Deleting'
|
||||
conn.get_event_source_mapping.when.called_with(UUID=response['UUID'])\
|
||||
.should.throw(botocore.client.ClientError)
|
||||
|
||||
|
||||
@mock_lambda
|
||||
@mock_s3
|
||||
def test_update_configuration():
|
||||
s3_conn = boto3.client('s3', 'us-west-2')
|
||||
s3_conn.create_bucket(Bucket='test-bucket')
|
||||
|
||||
zip_content = get_test_zip_file2()
|
||||
s3_conn.put_object(Bucket='test-bucket', Key='test.zip', Body=zip_content)
|
||||
conn = boto3.client('lambda', 'us-west-2')
|
||||
|
||||
fxn = conn.create_function(
|
||||
FunctionName='testFunction',
|
||||
Runtime='python2.7',
|
||||
Role='test-iam-role',
|
||||
Handler='lambda_function.lambda_handler',
|
||||
Code={
|
||||
'S3Bucket': 'test-bucket',
|
||||
'S3Key': 'test.zip',
|
||||
},
|
||||
Description='test lambda function',
|
||||
Timeout=3,
|
||||
MemorySize=128,
|
||||
Publish=True,
|
||||
)
|
||||
|
||||
assert fxn['Description'] == 'test lambda function'
|
||||
assert fxn['Handler'] == 'lambda_function.lambda_handler'
|
||||
assert fxn['MemorySize'] == 128
|
||||
assert fxn['Runtime'] == 'python2.7'
|
||||
assert fxn['Timeout'] == 3
|
||||
|
||||
updated_config = conn.update_function_configuration(
|
||||
FunctionName='testFunction',
|
||||
Description='updated test lambda function',
|
||||
Handler='lambda_function.new_lambda_handler',
|
||||
Runtime='python3.6',
|
||||
Timeout=7
|
||||
)
|
||||
|
||||
assert updated_config['ResponseMetadata']['HTTPStatusCode'] == 200
|
||||
assert updated_config['Description'] == 'updated test lambda function'
|
||||
assert updated_config['Handler'] == 'lambda_function.new_lambda_handler'
|
||||
assert updated_config['MemorySize'] == 128
|
||||
assert updated_config['Runtime'] == 'python3.6'
|
||||
assert updated_config['Timeout'] == 7
|
||||
|
||||
|
||||
@mock_lambda
|
||||
def test_update_function_zip():
|
||||
conn = boto3.client('lambda', 'us-west-2')
|
||||
|
||||
zip_content_one = get_test_zip_file1()
|
||||
|
||||
fxn = conn.create_function(
|
||||
FunctionName='testFunctionZip',
|
||||
Runtime='python2.7',
|
||||
Role='test-iam-role',
|
||||
Handler='lambda_function.lambda_handler',
|
||||
Code={
|
||||
'ZipFile': zip_content_one,
|
||||
},
|
||||
Description='test lambda function',
|
||||
Timeout=3,
|
||||
MemorySize=128,
|
||||
Publish=True,
|
||||
)
|
||||
|
||||
zip_content_two = get_test_zip_file2()
|
||||
|
||||
fxn_updated = conn.update_function_code(
|
||||
FunctionName='testFunctionZip',
|
||||
ZipFile=zip_content_two,
|
||||
Publish=True
|
||||
)
|
||||
|
||||
response = conn.get_function(
|
||||
FunctionName='testFunctionZip',
|
||||
Qualifier='2'
|
||||
)
|
||||
response['Configuration'].pop('LastModified')
|
||||
|
||||
response['ResponseMetadata']['HTTPStatusCode'].should.equal(200)
|
||||
assert len(response['Code']) == 2
|
||||
assert response['Code']['RepositoryType'] == 'S3'
|
||||
assert response['Code']['Location'].startswith('s3://awslambda-{0}-tasks.s3-{0}.amazonaws.com'.format(_lambda_region))
|
||||
response['Configuration'].should.equal(
|
||||
{
|
||||
"CodeSha256": hashlib.sha256(zip_content_two).hexdigest(),
|
||||
"CodeSize": len(zip_content_two),
|
||||
"Description": "test lambda function",
|
||||
"FunctionArn": 'arn:aws:lambda:{}:123456789012:function:testFunctionZip:2'.format(_lambda_region),
|
||||
"FunctionName": "testFunctionZip",
|
||||
"Handler": "lambda_function.lambda_handler",
|
||||
"MemorySize": 128,
|
||||
"Role": "test-iam-role",
|
||||
"Runtime": "python2.7",
|
||||
"Timeout": 3,
|
||||
"Version": '2',
|
||||
"VpcConfig": {
|
||||
"SecurityGroupIds": [],
|
||||
"SubnetIds": [],
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@mock_lambda
|
||||
@mock_s3
|
||||
def test_update_function_s3():
|
||||
s3_conn = boto3.client('s3', 'us-west-2')
|
||||
s3_conn.create_bucket(Bucket='test-bucket')
|
||||
|
||||
zip_content = get_test_zip_file1()
|
||||
s3_conn.put_object(Bucket='test-bucket', Key='test.zip', Body=zip_content)
|
||||
|
||||
conn = boto3.client('lambda', 'us-west-2')
|
||||
|
||||
fxn = conn.create_function(
|
||||
FunctionName='testFunctionS3',
|
||||
Runtime='python2.7',
|
||||
Role='test-iam-role',
|
||||
Handler='lambda_function.lambda_handler',
|
||||
Code={
|
||||
'S3Bucket': 'test-bucket',
|
||||
'S3Key': 'test.zip',
|
||||
},
|
||||
Description='test lambda function',
|
||||
Timeout=3,
|
||||
MemorySize=128,
|
||||
Publish=True,
|
||||
)
|
||||
|
||||
zip_content_two = get_test_zip_file2()
|
||||
s3_conn.put_object(Bucket='test-bucket', Key='test2.zip', Body=zip_content_two)
|
||||
|
||||
fxn_updated = conn.update_function_code(
|
||||
FunctionName='testFunctionS3',
|
||||
S3Bucket='test-bucket',
|
||||
S3Key='test2.zip',
|
||||
Publish=True
|
||||
)
|
||||
|
||||
response = conn.get_function(
|
||||
FunctionName='testFunctionS3',
|
||||
Qualifier='2'
|
||||
)
|
||||
response['Configuration'].pop('LastModified')
|
||||
|
||||
response['ResponseMetadata']['HTTPStatusCode'].should.equal(200)
|
||||
assert len(response['Code']) == 2
|
||||
assert response['Code']['RepositoryType'] == 'S3'
|
||||
assert response['Code']['Location'].startswith('s3://awslambda-{0}-tasks.s3-{0}.amazonaws.com'.format(_lambda_region))
|
||||
response['Configuration'].should.equal(
|
||||
{
|
||||
"CodeSha256": hashlib.sha256(zip_content_two).hexdigest(),
|
||||
"CodeSize": len(zip_content_two),
|
||||
"Description": "test lambda function",
|
||||
"FunctionArn": 'arn:aws:lambda:{}:123456789012:function:testFunctionS3:2'.format(_lambda_region),
|
||||
"FunctionName": "testFunctionS3",
|
||||
"Handler": "lambda_function.lambda_handler",
|
||||
"MemorySize": 128,
|
||||
"Role": "test-iam-role",
|
||||
"Runtime": "python2.7",
|
||||
"Timeout": 3,
|
||||
"Version": '2',
|
||||
"VpcConfig": {
|
||||
"SecurityGroupIds": [],
|
||||
"SubnetIds": [],
|
||||
}
|
||||
},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2324,6 +2324,45 @@ def test_sorted_query_with_numerical_sort_key():
|
|||
assert expected_prices == response_prices, "result items are not sorted by numerical value"
|
||||
|
||||
|
||||
# https://github.com/spulec/moto/issues/1874
|
||||
@mock_dynamodb2
|
||||
def test_item_size_is_under_400KB():
|
||||
dynamodb = boto3.resource('dynamodb')
|
||||
client = boto3.client('dynamodb')
|
||||
|
||||
dynamodb.create_table(
|
||||
TableName='moto-test',
|
||||
KeySchema=[{'AttributeName': 'id', 'KeyType': 'HASH'}],
|
||||
AttributeDefinitions=[{'AttributeName': 'id', 'AttributeType': 'S'}],
|
||||
ProvisionedThroughput={'ReadCapacityUnits': 1, 'WriteCapacityUnits': 1}
|
||||
)
|
||||
table = dynamodb.Table('moto-test')
|
||||
|
||||
large_item = 'x' * 410 * 1000
|
||||
assert_failure_due_to_item_size(func=client.put_item,
|
||||
TableName='moto-test',
|
||||
Item={'id': {'S': 'foo'}, 'item': {'S': large_item}})
|
||||
assert_failure_due_to_item_size(func=table.put_item, Item = {'id': 'bar', 'item': large_item})
|
||||
assert_failure_due_to_item_size(func=client.update_item,
|
||||
TableName='moto-test',
|
||||
Key={'id': {'S': 'foo2'}},
|
||||
UpdateExpression='set item=:Item',
|
||||
ExpressionAttributeValues={':Item': {'S': large_item}})
|
||||
# Assert op fails when updating a nested item
|
||||
assert_failure_due_to_item_size(func=table.put_item,
|
||||
Item={'id': 'bar', 'itemlist': [{'item': large_item}]})
|
||||
assert_failure_due_to_item_size(func=client.put_item,
|
||||
TableName='moto-test',
|
||||
Item={'id': {'S': 'foo'}, 'itemlist': {'L': [{'M': {'item1': {'S': large_item}}}]}})
|
||||
|
||||
|
||||
def assert_failure_due_to_item_size(func, **kwargs):
|
||||
with assert_raises(ClientError) as ex:
|
||||
func(**kwargs)
|
||||
ex.exception.response['Error']['Code'].should.equal('ValidationException')
|
||||
ex.exception.response['Error']['Message'].should.equal('Item size has exceeded the maximum allowed size')
|
||||
|
||||
|
||||
def _create_user_table():
|
||||
client = boto3.client('dynamodb', region_name='us-east-1')
|
||||
client.create_table(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue