Skip to content

Commit

Permalink
added a couple tests and build update
Browse files Browse the repository at this point in the history
  • Loading branch information
yuric committed Jul 7, 2017
1 parent 25d8a42 commit a2ef4ee
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pip-delete-this-directory.txt
htmlcov/
.tox/
.coverage
.coveragerc
.coverage.*
.cache
nosetests.xml
Expand Down
Empty file modified setup.py
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"status_code": 204,
"data": {
"ResponseMetadata": {
"HTTPStatusCode": 204,
"RetryAttempts": 0,
"HostId": "J61KH771JIvmpimO/UbQq7mpaBTi8isqV6ZB09PZT/acUplPw86JfzN2d3ajuAAqxL1pDq8X41U=",
"RequestId": "1D3CFD82C46C3516",
"HTTPHeaders": {
"x-amz-id-2": "J61KH771JIvmpimO/UbQq7mpaBTi8isqV6ZB09PZT/acUplPw86JfzN2d3ajuAAqxL1pDq8X41U=",
"date": "Tue, 08 Nov 2016 23:19:25 GMT",
"x-amz-request-id": "1D3CFD82C46C3516",
"server": "AmazonS3"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"status_code": 200,
"data": {
"ETag": "\"86865b71093464f5a301e1027439491b-1\"",
"Bucket": "test_zappa_upload_s3",
"Location": "https://test_zappa_upload_s3.s3.amazonaws.com/lambda_package-1456273359.zip",
"ResponseMetadata": {
"HTTPStatusCode": 200,
"HostId": "MRuE82ncxtI6IA04QwvcPHGZX/81kUhSZ+LwV7jAGsv674NknH9btnGPsUuLXBspNuqGtFbdWKY=",
"RequestId": "4BD122934F722C61"
},
"Key": "lambda_package-1456273359.zip"
}
}
34 changes: 34 additions & 0 deletions tests/placebo/TestZappa.test_copy_on_s3/s3.CopyObject_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"status_code": 200,
"data": {
"CopyObjectResult": {
"LastModified": {
"hour": 23,
"__class__": "datetime",
"month": 12,
"second": 29,
"microsecond": 0,
"year": 2016,
"day": 20,
"minute": 43
},
"ETag": "\"b2e189abf85e809a51522cdb0e53083a\""
},
"ResponseMetadata": {
"HTTPStatusCode": 200,
"RetryAttempts": 0,
"HostId": "xDC1DVrFVSxJNrdVsZrQ38WucHFdgeJiY2+W7kUZtORrfYb2RRA4aqWOQD5j2No4NOoXN9u8vxk=",
"RequestId": "9622D9960549D775",
"HTTPHeaders": {
"content-length": "234",
"x-amz-id-2": "xDC1DVrFVSxJNrdVsZrQ38WucHFdgeJiY2+W7kUZtORrfYb2RRA4aqWOQD5j2No4NOoXN9u8vxk=",
"server": "AmazonS3",
"x-amz-request-id": "9622D9960549D775",
"date": "Tue, 20 Dec 2016 23:43:29 GMT",
"x-amz-server-side-encryption": "AES256",
"content-type": "application/xml"
}
},
"ServerSideEncryption": "AES256"
}
}
11 changes: 11 additions & 0 deletions tests/placebo/TestZappa.test_copy_on_s3/s3.CreateBucket_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"status_code": 200,
"data": {
"Location": "/test_zappa_upload_s3",
"ResponseMetadata": {
"HTTPStatusCode": 200,
"HostId": "8sXq+Uc6Ao7tM6js+GCOK99fJGbL2cNEZsug+9karxoklp9ml5MxqSJiTOw6yHlCWEGDGv7BZFw=",
"RequestId": "B99377D822A42891"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"status_code": 200,
"data": {
"Bucket": "test_zappa_upload_s3",
"UploadId": "qPM3MaoOZRezVJwiULIVGtsj0K99hO9YbuPdzMJQVUzZ.XX3YdscjOUnnzBHbFi2XGBgZjeOBb2NryiJzKxlHRiVKyYVezXsc_o9PCRar.icz3ks66jij8A0tkuwp1o0",
"Key": "lambda_package-1456272533.zip",
"ResponseMetadata": {
"HTTPStatusCode": 200,
"HostId": "1awKoHujZxpAAG1hGnOKHetwi4vY1Dszt4QvFiAcUMkENvnGHt7yDuJ4n6eR5sRK",
"RequestId": "7CE018CCC678149E"
}
}
}
10 changes: 10 additions & 0 deletions tests/placebo/TestZappa.test_copy_on_s3/s3.HeadBucket_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"status_code": 200,
"data": {
"ResponseMetadata": {
"HTTPStatusCode": 200,
"HostId": "bIWJow7rK8U4lxn9VTIz3/lH+agH9OA8BGD80vbICTWwHNqfEdGt4D3s2EmVWm/U01XtUZdq5OY=",
"RequestId": "501E18A0BFB1B76C"
}
}
}
25 changes: 25 additions & 0 deletions tests/placebo/TestZappa.test_copy_on_s3/s3.HeadObject_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"status_code": 200,
"data": {
"AcceptRanges": "bytes",
"ContentType": "binary/octet-stream",
"ResponseMetadata": {
"HTTPStatusCode": 200,
"HostId": "PnlRCp+1zp2qblsjbRFvph/eBOb8dN/k9fTPmW45pfDP/6GoUs/Z7hfZIpFo5CjVgLtsuZk/IYw=",
"RequestId": "AD1ABEA37433B785"
},
"LastModified": {
"hour": 23,
"__class__": "datetime",
"month": 2,
"second": 10,
"microsecond": 0,
"year": 2016,
"day": 23,
"minute": 32
},
"ContentLength": 4507898,
"ETag": "\"58098b238b9a6ed2b3a954601e9b8e5f\"",
"Metadata": {}
}
}
11 changes: 11 additions & 0 deletions tests/placebo/TestZappa.test_copy_on_s3/s3.PutObject_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"status_code": 200,
"data": {
"ETag": "\"58098b238b9a6ed2b3a954601e9b8e5f\"",
"ResponseMetadata": {
"HTTPStatusCode": 200,
"HostId": "tedGhtpKSnTti2bVK33LeOe6Iy0D4uLMfZt8TqJJWFRK3XI35EahQd2F+ShUX9l6O0vw7yyEmMA=",
"RequestId": "D90365BC22767711"
}
}
}
11 changes: 11 additions & 0 deletions tests/placebo/TestZappa.test_copy_on_s3/s3.UploadPart_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"status_code": 200,
"data": {
"ETag": "\"781936e8a21849d38e955224ef70d71e\"",
"ResponseMetadata": {
"HTTPStatusCode": 200,
"HostId": "/Dt2sy50X8WRf6CeE4OhoXMQftr4n5PUtT22ZblpVdfLkqo8pv7oeq6XaEoNCdjiPmN9+AtaXy0=",
"RequestId": "C3816300C7FA5E5F"
}
}
}
29 changes: 28 additions & 1 deletion tests/tests_placebo.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def test_upload_remove_s3(self, session):
z = Zappa(session)
zip_path = z.create_lambda_zip(minify=False)
res = z.upload_to_s3(zip_path, bucket_name)
os.remove(zip_path)
self.assertTrue(res)
s3 = session.resource('s3')

Expand All @@ -59,6 +58,34 @@ def test_upload_remove_s3(self, session):
fail = z.upload_to_s3('/tmp/this_isnt_real', bucket_name)
self.assertFalse(fail)

#Will graciouly handle quirky S3 behavior on 'us-east-1' region name'
z.aws_region = 'us-east-1'
res = z.upload_to_s3(zip_path, bucket_name)
os.remove(zip_path)
self.assertTrue(res)

@placebo_session
def test_copy_on_s3(self, session):
bucket_name = 'test_zappa_upload_s3'
z = Zappa(session)
zip_path = z.create_lambda_zip(minify=False)
res = z.upload_to_s3(zip_path, bucket_name)
self.assertTrue(res)
s3 = session.resource('s3')

# will throw ClientError with 404 if bucket doesn't exist
s3.meta.client.head_bucket(Bucket=bucket_name)

# will throw ClientError with 404 if object doesn't exist
s3.meta.client.head_object(
Bucket=bucket_name,
Key=zip_path,
)
zp = 'copy_' + zip_path
res = z.copy_on_s3(zip_path, zp, bucket_name)
os.remove(zip_path)
self.assertTrue(res)

@placebo_session
def test_create_lambda_function(self, session):
bucket_name = 'lmbda'
Expand Down
12 changes: 5 additions & 7 deletions zappa/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,13 +918,11 @@ def update_lambda_configuration( self,
if not aws_environment_variables:
aws_environment_variables = {}
else:
# There may not be an Environment key defined.
# https://github.com/Miserlou/Zappa/issues/987
lambda_aws_environment_variables = self.lambda_client.get_function_configuration(FunctionName=function_name)
if "Environment" in lambda_aws_environment_variables:
# Get any remote aws lambda env vars so they don't get trashed
# Related: https://github.com/Miserlou/Zappa/issues/765
lambda_aws_environment_variables["Environment"].get("Variables", {})
# Check if there are any remote aws lambda env vars so they don't get trashed.
# https://github.com/Miserlou/Zappa/issues/987, Related: https://github.com/Miserlou/Zappa/issues/765
lambda_aws_config = self.lambda_client.get_function_configuration(FunctionName=function_name)
if "Environment" in lambda_aws_config:
lambda_aws_environment_variables = lambda_aws_config["Environment"].get("Variables", {})
# Append keys that are remote but not in settings file
for key, value in lambda_aws_environment_variables.items():
if key not in aws_environment_variables:
Expand Down

0 comments on commit a2ef4ee

Please sign in to comment.