From bcd6d907086e4dc0dbe23d4ba91cebc13bebdfa5 Mon Sep 17 00:00:00 2001 From: ian-whitestone Date: Thu, 31 Dec 2020 17:00:01 -0700 Subject: [PATCH] Update tests for new docker functionality Related #2188 --- .gitignore | 1 + .../lambda.GetFunctionConfiguration_1.json | 3 +- .../lambda.ListVersionsByFunction_2.json | 9 +- .../lambda.ListVersionsByFunction_4.json | 9 +- .../lambda.CreateAlias_1.json | 9 ++ .../lambda.CreateFunction_1.json | 20 +++ .../lambda.DeleteFunctionConcurrency_1.json | 9 ++ .../lambda.GetAlias_1.json | 9 ++ .../lambda.UpdateAlias_1.json | 9 ++ .../lambda.UpdateFunctionCode_1.json | 20 +++ .../lambda.GetFunction_1.json | 29 ++++ .../lambda.ListVersionsByFunction_1.json | 27 ++-- .../lambda.ListVersionsByFunction_2.json | 27 ++-- .../lambda.ListVersionsByFunction_1.json | 128 ++++++++++++++++++ .../lambda.ListVersionsByFunction_2.json | 128 ++++++++++++++++++ tests/tests.py | 32 ++++- tests/tests_placebo.py | 39 ++++++ zappa/cli.py | 2 +- zappa/core.py | 2 +- zappa/handler.py | 2 - 20 files changed, 480 insertions(+), 34 deletions(-) create mode 100644 tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.CreateAlias_1.json create mode 100644 tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.CreateFunction_1.json create mode 100644 tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.DeleteFunctionConcurrency_1.json create mode 100644 tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.GetAlias_1.json create mode 100644 tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.UpdateAlias_1.json create mode 100644 tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.UpdateFunctionCode_1.json create mode 100644 tests/placebo/TestZappa.test_is_lambda_function_ready/lambda.GetFunction_1.json create mode 100644 tests/placebo/TestZappa.test_rollback_lambda_function_version_docker/lambda.ListVersionsByFunction_1.json create mode 100644 tests/placebo/TestZappa.test_rollback_lambda_function_version_docker/lambda.ListVersionsByFunction_2.json diff --git a/.gitignore b/.gitignore index 0be75798d..0b094269d 100644 --- a/.gitignore +++ b/.gitignore @@ -92,3 +92,4 @@ README.test.md .mypy_cache .pytest_cache pyproject.toml +poetry.lock diff --git a/tests/placebo/TestZappa.test_cli_aws/lambda.GetFunctionConfiguration_1.json b/tests/placebo/TestZappa.test_cli_aws/lambda.GetFunctionConfiguration_1.json index bac7a999f..1d826bbf1 100644 --- a/tests/placebo/TestZappa.test_cli_aws/lambda.GetFunctionConfiguration_1.json +++ b/tests/placebo/TestZappa.test_cli_aws/lambda.GetFunctionConfiguration_1.json @@ -27,6 +27,7 @@ "Version": "$LATEST", "Environment": { "Variables": {} - } + }, + "PackageType": "Zip" } } \ No newline at end of file diff --git a/tests/placebo/TestZappa.test_cli_aws/lambda.ListVersionsByFunction_2.json b/tests/placebo/TestZappa.test_cli_aws/lambda.ListVersionsByFunction_2.json index f939d9acc..463721dd5 100644 --- a/tests/placebo/TestZappa.test_cli_aws/lambda.ListVersionsByFunction_2.json +++ b/tests/placebo/TestZappa.test_cli_aws/lambda.ListVersionsByFunction_2.json @@ -18,7 +18,8 @@ "Timeout": 30, "LastModified": "2016-06-02T19:24:32.878+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" }, { "Version": "1", @@ -32,7 +33,8 @@ "Timeout": 30, "LastModified": "2016-06-02T19:23:48.902+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" }, { "Version": "2", @@ -46,7 +48,8 @@ "Timeout": 30, "LastModified": "2016-06-02T19:24:32.878+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" } ] } diff --git a/tests/placebo/TestZappa.test_cli_aws/lambda.ListVersionsByFunction_4.json b/tests/placebo/TestZappa.test_cli_aws/lambda.ListVersionsByFunction_4.json index f0241afd6..e8b68dc6a 100644 --- a/tests/placebo/TestZappa.test_cli_aws/lambda.ListVersionsByFunction_4.json +++ b/tests/placebo/TestZappa.test_cli_aws/lambda.ListVersionsByFunction_4.json @@ -25,7 +25,8 @@ "Timeout": 30, "LastModified": "2016-08-25T03:31:23.343+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" }, { "Version": "4", @@ -39,7 +40,8 @@ "Timeout": 30, "LastModified": "2016-08-25T03:29:40.612+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" }, { "Version": "5", @@ -53,7 +55,8 @@ "Timeout": 30, "LastModified": "2016-08-25T03:31:18.572+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" } ] } diff --git a/tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.CreateAlias_1.json b/tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.CreateAlias_1.json new file mode 100644 index 000000000..08d0bb9ed --- /dev/null +++ b/tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.CreateAlias_1.json @@ -0,0 +1,9 @@ +{ + "status_code": 201, + "data": { + "AliasArn": "arn:aws:lambda:us-east-1:12345:function:test_lmbda_function55:current-alb-version", + "Description": "Zappa Deployment", + "FunctionVersion": "1", + "Name": "current-alb-version" + } +} diff --git a/tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.CreateFunction_1.json b/tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.CreateFunction_1.json new file mode 100644 index 000000000..62b5b853b --- /dev/null +++ b/tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.CreateFunction_1.json @@ -0,0 +1,20 @@ +{ + "status_code": 201, + "data": { + "CodeSha256": "q4duEOI611sqtkU+YbdNkjH5qGRlgmvc9+FhpdykYuk=", + "FunctionName": "test_lmbda_function55", + "ResponseMetadata": { + "HTTPStatusCode": 201, + "RequestId": "12b75ef1-e226-11e5-84a2-ad7ddc64ad40" + }, + "CodeSize": 26585626, + "MemorySize": 512, + "FunctionArn": "arn:aws:lambda:us-east-1:12345:function:test_lmbda_function55", + "Version": "1", + "Role": "arn:aws:iam::12345:role/ZappaLambdaExecution", + "Timeout": 30, + "LastModified": "2016-03-04T16:28:06.633+0000", + "Description": "Zappa Deployment", + "PackageType": "Docker" + } +} diff --git a/tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.DeleteFunctionConcurrency_1.json b/tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.DeleteFunctionConcurrency_1.json new file mode 100644 index 000000000..c226aef56 --- /dev/null +++ b/tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.DeleteFunctionConcurrency_1.json @@ -0,0 +1,9 @@ +{ + "status_code": 200, + "data": { + "ResponseMetadata": { + "HTTPStatusCode": 200, + "RequestId": "aff3a3f9-28f4-11e6-9dbb-5dd116b9ddf1" + } + } +} diff --git a/tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.GetAlias_1.json b/tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.GetAlias_1.json new file mode 100644 index 000000000..cf839c230 --- /dev/null +++ b/tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.GetAlias_1.json @@ -0,0 +1,9 @@ +{ + "status_code": 200, + "data": { + "AliasArn": "arn:aws:lambda:us-east-1:12345:function:test_lmbda_function55:current-alb-version", + "Description": "Zappa Deployment", + "FunctionVersion": "1", + "Name": "current-alb-version" + } +} diff --git a/tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.UpdateAlias_1.json b/tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.UpdateAlias_1.json new file mode 100644 index 000000000..08d0bb9ed --- /dev/null +++ b/tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.UpdateAlias_1.json @@ -0,0 +1,9 @@ +{ + "status_code": 201, + "data": { + "AliasArn": "arn:aws:lambda:us-east-1:12345:function:test_lmbda_function55:current-alb-version", + "Description": "Zappa Deployment", + "FunctionVersion": "1", + "Name": "current-alb-version" + } +} diff --git a/tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.UpdateFunctionCode_1.json b/tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.UpdateFunctionCode_1.json new file mode 100644 index 000000000..7184d51e5 --- /dev/null +++ b/tests/placebo/TestZappa.test_create_lambda_function_docker/lambda.UpdateFunctionCode_1.json @@ -0,0 +1,20 @@ +{ + "status_code": 200, + "data": { + "CodeSha256": "q4duEOI611sqtkU+YbdNkjH5qGRlgmvc9+FhpdykYuk=", + "FunctionName": "test_lmbda_function55", + "ResponseMetadata": { + "HTTPStatusCode": 200, + "RequestId": "153e09be-e226-11e5-a3b8-7b263f053e5a" + }, + "CodeSize": 26585626, + "MemorySize": 512, + "FunctionArn": "arn:aws:lambda:us-east-1:12345:function:test_lmbda_function55:1", + "Version": "1", + "Role": "arn:aws:iam::12345:role/ZappaLambdaExecution", + "Timeout": 30, + "LastModified": "2016-03-04T16:28:06.633+0000", + "Description": "Zappa Deployment", + "PackageType": "Docker" + } +} diff --git a/tests/placebo/TestZappa.test_is_lambda_function_ready/lambda.GetFunction_1.json b/tests/placebo/TestZappa.test_is_lambda_function_ready/lambda.GetFunction_1.json new file mode 100644 index 000000000..7debf4b45 --- /dev/null +++ b/tests/placebo/TestZappa.test_is_lambda_function_ready/lambda.GetFunction_1.json @@ -0,0 +1,29 @@ +{ + "status_code": 200, + "data": { + "Code": { + "RepositoryType": "S3", + "Location": "https://prod-04-2014-tasks.s3.amazonaws.com/snapshots/724336686645/django-helloworld-unicode-a0d56d69-de7c-421b-9527-f49e100a8613?x-amz-security-token=AQoDYXdzEEka4AOil22HD1z9lkxZ7yiced%2FbYEWzXJHbMHexq2zxzMQ7%2Fj2a06AP9z3nK0QgGPUADK2A6FUpFFl%2BjO7gBmP%2FKifl9jTvvaf72YhPbZDJTIrFvZZ%2B5NjhkDrfRgyK%2BhBROGNH85L46iJSShwZ5lmKgADTnnVMT9pZ2JXF3uNLUzrWoJTpf%2F7lDBMEoFO%2BNLer7MsLsuCiemzKV4Kcvo0Mu3qhkk1u2BfoRTj4xmiaWE7UfqD%2FeQkINdwkUgXeQ9SA1T2l70omZ1ss2l1y18xeUvCQde5OrE7ue5cVpENyjYr9dEwPYwm1wG9%2B%2FJE%2BMQZ8Lz6CNex%2BTVuBvY09JL8vTV7WpRxGhr96a7OIn5YCCQ7cJfNVIWpdBUrWmqnE8Jh9oL558TVA0e5RFP9YU%2BFYxJcA6fH%2B0DZBAAK9797XPltzhSXrUcB8JuHfa%2FC1n2w8X7HbsMTI8m1OAIkQQtppYHtl4T5o3012VcSTLRSv945sCodMOmueKsEwAZlc1gFflcwGXE4v4hB6YJjvcRj2SQiK7Yzw7ShODOroOsWT18te8p9Qjs2mL6akLt1%2Fo8tddWskKzqrfYfBTvfFL5Y0nU4sI96JUXM0KXmJotPRmCdFEktGk4Fre0wm%2FyAau0NdaDQg7NzmtgU%3D&AWSAccessKeyId=ASIAIQFLXUK7E7GUTQ2A&Expires=1457113092&Signature=%2FH0RMGKWk1tEGnK9R6CCPXQ6Y04%3D" + }, + "Configuration": { + "Version": "7", + "CodeSha256": "t3pcqjdrLOqd2p0bRsCEOhgvLJ9sLJrVazpGqhDybsc=", + "FunctionName": "django-helloworld-unicode", + "MemorySize": 512, + "CodeSize": 12154784, + "FunctionArn": "arn:aws:lambda:us-east-1:724336686645:function:django-helloworld-unicode:7", + "Handler": "handler.lambda_handler", + "Role": "arn:aws:iam::724336686645:role/ZappaLambdaExecution", + "Timeout": 30, + "LastModified": "2016-03-01T00:24:01.446+0000", + "Runtime": "python2.7", + "Description": "Zappa Deployment", + "State": "Active", + "LastUpdateStatus": "Successful" + }, + "ResponseMetadata": { + "HTTPStatusCode": 200, + "RequestId": "78da1863-e22e-11e5-a5ae-01cbfdebdc8f" + } + } +} diff --git a/tests/placebo/TestZappa.test_rollback_lambda_function_version/lambda.ListVersionsByFunction_1.json b/tests/placebo/TestZappa.test_rollback_lambda_function_version/lambda.ListVersionsByFunction_1.json index d88e58f13..9dcb16e68 100644 --- a/tests/placebo/TestZappa.test_rollback_lambda_function_version/lambda.ListVersionsByFunction_1.json +++ b/tests/placebo/TestZappa.test_rollback_lambda_function_version/lambda.ListVersionsByFunction_1.json @@ -18,7 +18,8 @@ "Timeout": 30, "LastModified": "2016-03-01T00:55:35.845+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" }, { "Version": "1", @@ -32,7 +33,8 @@ "Timeout": 30, "LastModified": "2016-02-29T14:39:31.557+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" }, { "Version": "2", @@ -46,7 +48,8 @@ "Timeout": 30, "LastModified": "2016-02-29T14:47:04.499+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" }, { "Version": "3", @@ -60,7 +63,8 @@ "Timeout": 30, "LastModified": "2016-02-29T14:58:08.443+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" }, { "Version": "4", @@ -74,7 +78,8 @@ "Timeout": 30, "LastModified": "2016-02-29T16:25:49.425+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" }, { "Version": "5", @@ -88,7 +93,8 @@ "Timeout": 30, "LastModified": "2016-02-29T16:34:47.988+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" }, { "Version": "6", @@ -102,7 +108,8 @@ "Timeout": 30, "LastModified": "2016-03-01T00:12:28.708+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" }, { "Version": "7", @@ -116,7 +123,8 @@ "Timeout": 30, "LastModified": "2016-03-01T00:24:01.446+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" }, { "Version": "8", @@ -130,7 +138,8 @@ "Timeout": 30, "LastModified": "2016-03-01T00:55:35.845+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" } ] } diff --git a/tests/placebo/TestZappa.test_rollback_lambda_function_version/lambda.ListVersionsByFunction_2.json b/tests/placebo/TestZappa.test_rollback_lambda_function_version/lambda.ListVersionsByFunction_2.json index 0970214cb..5ce591a50 100644 --- a/tests/placebo/TestZappa.test_rollback_lambda_function_version/lambda.ListVersionsByFunction_2.json +++ b/tests/placebo/TestZappa.test_rollback_lambda_function_version/lambda.ListVersionsByFunction_2.json @@ -18,7 +18,8 @@ "Timeout": 30, "LastModified": "2016-03-01T00:55:35.845+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" }, { "Version": "1", @@ -32,7 +33,8 @@ "Timeout": 30, "LastModified": "2016-02-29T14:39:31.557+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" }, { "Version": "2", @@ -46,7 +48,8 @@ "Timeout": 30, "LastModified": "2016-02-29T14:47:04.499+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" }, { "Version": "3", @@ -60,7 +63,8 @@ "Timeout": 30, "LastModified": "2016-02-29T14:58:08.443+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" }, { "Version": "4", @@ -74,7 +78,8 @@ "Timeout": 30, "LastModified": "2016-02-29T16:25:49.425+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" }, { "Version": "5", @@ -88,7 +93,8 @@ "Timeout": 30, "LastModified": "2016-02-29T16:34:47.988+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" }, { "Version": "6", @@ -102,7 +108,8 @@ "Timeout": 30, "LastModified": "2016-03-01T00:12:28.708+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" }, { "Version": "7", @@ -116,7 +123,8 @@ "Timeout": 30, "LastModified": "2016-03-01T00:24:01.446+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" }, { "Version": "8", @@ -130,7 +138,8 @@ "Timeout": 30, "LastModified": "2016-03-01T00:55:35.845+0000", "Runtime": "python2.7", - "Description": "Zappa Deployment" + "Description": "Zappa Deployment", + "PackageType": "Zip" } ] } diff --git a/tests/placebo/TestZappa.test_rollback_lambda_function_version_docker/lambda.ListVersionsByFunction_1.json b/tests/placebo/TestZappa.test_rollback_lambda_function_version_docker/lambda.ListVersionsByFunction_1.json new file mode 100644 index 000000000..1e4ff953f --- /dev/null +++ b/tests/placebo/TestZappa.test_rollback_lambda_function_version_docker/lambda.ListVersionsByFunction_1.json @@ -0,0 +1,128 @@ +{ + "status_code": 200, + "data": { + "ResponseMetadata": { + "HTTPStatusCode": 200, + "RequestId": "786c144e-e22e-11e5-86f4-4528d3e5269b" + }, + "Versions": [ + { + "Version": "$LATEST", + "CodeSha256": "qPyTWxngvz505vUX4v0IbW4H6CdQCSiYSGPsNQHPNTc=", + "FunctionName": "django-helloworld-unicode", + "MemorySize": 512, + "CodeSize": 12154778, + "FunctionArn": "arn:aws:lambda:us-east-1:724336686645:function:django-helloworld-unicode:$LATEST", + "Role": "arn:aws:iam::724336686645:role/ZappaLambdaExecution", + "Timeout": 30, + "LastModified": "2016-03-01T00:55:35.845+0000", + "Description": "Zappa Deployment", + "PackageType": "Image" + }, + { + "Version": "1", + "CodeSha256": "eEW6OoZIm1g+3sLnoGqkfG9PcvYcXYoTd8uZYCMhA2U=", + "FunctionName": "django-helloworld-unicode", + "MemorySize": 512, + "CodeSize": 12102921, + "FunctionArn": "arn:aws:lambda:us-east-1:724336686645:function:django-helloworld-unicode:1", + "Role": "arn:aws:iam::724336686645:role/ZappaLambdaExecution", + "Timeout": 30, + "LastModified": "2016-02-29T14:39:31.557+0000", + "Description": "Zappa Deployment", + "PackageType": "Image" + }, + { + "Version": "2", + "CodeSha256": "QXwkHDWCmczXTdDi9AYf6Ws74jkAI6zUJ+tf7s5zLzk=", + "FunctionName": "django-helloworld-unicode", + "MemorySize": 512, + "CodeSize": 12152312, + "FunctionArn": "arn:aws:lambda:us-east-1:724336686645:function:django-helloworld-unicode:2", + "Role": "arn:aws:iam::724336686645:role/ZappaLambdaExecution", + "Timeout": 30, + "LastModified": "2016-02-29T14:47:04.499+0000", + "Description": "Zappa Deployment", + "PackageType": "Image" + }, + { + "Version": "3", + "CodeSha256": "Hpt/J6gyhnYXm7NVWwzomJoExr0i9II//4zaLm0DYgc=", + "FunctionName": "django-helloworld-unicode", + "MemorySize": 512, + "CodeSize": 12152182, + "FunctionArn": "arn:aws:lambda:us-east-1:724336686645:function:django-helloworld-unicode:3", + "Role": "arn:aws:iam::724336686645:role/ZappaLambdaExecution", + "Timeout": 30, + "LastModified": "2016-02-29T14:58:08.443+0000", + "Description": "Zappa Deployment", + "PackageType": "Image" + }, + { + "Version": "4", + "CodeSha256": "1ofpfK2Jonu13iPUBMeNYR962iWcD5vL1YrJazF9tF0=", + "FunctionName": "django-helloworld-unicode", + "MemorySize": 512, + "CodeSize": 12154467, + "FunctionArn": "arn:aws:lambda:us-east-1:724336686645:function:django-helloworld-unicode:4", + "Role": "arn:aws:iam::724336686645:role/ZappaLambdaExecution", + "Timeout": 30, + "LastModified": "2016-02-29T16:25:49.425+0000", + "Description": "Zappa Deployment", + "PackageType": "Image" + }, + { + "Version": "5", + "CodeSha256": "bwLhQSjeZOmNC10s2eMO0ljWJBNX5tT4S9MgkvBWjOM=", + "FunctionName": "django-helloworld-unicode", + "MemorySize": 512, + "CodeSize": 12154507, + "FunctionArn": "arn:aws:lambda:us-east-1:724336686645:function:django-helloworld-unicode:5", + "Role": "arn:aws:iam::724336686645:role/ZappaLambdaExecution", + "Timeout": 30, + "LastModified": "2016-02-29T16:34:47.988+0000", + "Description": "Zappa Deployment", + "PackageType": "Image" + }, + { + "Version": "6", + "CodeSha256": "uxHYC6Uf/sUl884TWUqlwi0WWE+ixfxhO964yPec5zM=", + "FunctionName": "django-helloworld-unicode", + "MemorySize": 512, + "CodeSize": 12154780, + "FunctionArn": "arn:aws:lambda:us-east-1:724336686645:function:django-helloworld-unicode:6", + "Role": "arn:aws:iam::724336686645:role/ZappaLambdaExecution", + "Timeout": 30, + "LastModified": "2016-03-01T00:12:28.708+0000", + "Description": "Zappa Deployment", + "PackageType": "Image" + }, + { + "Version": "7", + "CodeSha256": "t3pcqjdrLOqd2p0bRsCEOhgvLJ9sLJrVazpGqhDybsc=", + "FunctionName": "django-helloworld-unicode", + "MemorySize": 512, + "CodeSize": 12154784, + "FunctionArn": "arn:aws:lambda:us-east-1:724336686645:function:django-helloworld-unicode:7", + "Role": "arn:aws:iam::724336686645:role/ZappaLambdaExecution", + "Timeout": 30, + "LastModified": "2016-03-01T00:24:01.446+0000", + "Description": "Zappa Deployment", + "PackageType": "Image" + }, + { + "Version": "8", + "CodeSha256": "qPyTWxngvz505vUX4v0IbW4H6CdQCSiYSGPsNQHPNTc=", + "FunctionName": "django-helloworld-unicode", + "MemorySize": 512, + "CodeSize": 12154778, + "FunctionArn": "arn:aws:lambda:us-east-1:724336686645:function:django-helloworld-unicode:8", + "Role": "arn:aws:iam::724336686645:role/ZappaLambdaExecution", + "Timeout": 30, + "LastModified": "2016-03-01T00:55:35.845+0000", + "Description": "Zappa Deployment", + "PackageType": "Image" + } + ] + } +} diff --git a/tests/placebo/TestZappa.test_rollback_lambda_function_version_docker/lambda.ListVersionsByFunction_2.json b/tests/placebo/TestZappa.test_rollback_lambda_function_version_docker/lambda.ListVersionsByFunction_2.json new file mode 100644 index 000000000..cfe367df5 --- /dev/null +++ b/tests/placebo/TestZappa.test_rollback_lambda_function_version_docker/lambda.ListVersionsByFunction_2.json @@ -0,0 +1,128 @@ +{ + "status_code": 200, + "data": { + "ResponseMetadata": { + "HTTPStatusCode": 200, + "RequestId": "78c11231-e22e-11e5-bb00-6935e1456f05" + }, + "Versions": [ + { + "Version": "$LATEST", + "CodeSha256": "qPyTWxngvz505vUX4v0IbW4H6CdQCSiYSGPsNQHPNTc=", + "FunctionName": "django-helloworld-unicode", + "MemorySize": 512, + "CodeSize": 12154778, + "FunctionArn": "arn:aws:lambda:us-east-1:724336686645:function:django-helloworld-unicode:$LATEST", + "Role": "arn:aws:iam::724336686645:role/ZappaLambdaExecution", + "Timeout": 30, + "LastModified": "2016-03-01T00:55:35.845+0000", + "Description": "Zappa Deployment", + "PackageType": "Image" + }, + { + "Version": "1", + "CodeSha256": "eEW6OoZIm1g+3sLnoGqkfG9PcvYcXYoTd8uZYCMhA2U=", + "FunctionName": "django-helloworld-unicode", + "MemorySize": 512, + "CodeSize": 12102921, + "FunctionArn": "arn:aws:lambda:us-east-1:724336686645:function:django-helloworld-unicode:1", + "Role": "arn:aws:iam::724336686645:role/ZappaLambdaExecution", + "Timeout": 30, + "LastModified": "2016-02-29T14:39:31.557+0000", + "Description": "Zappa Deployment", + "PackageType": "Image" + }, + { + "Version": "2", + "CodeSha256": "QXwkHDWCmczXTdDi9AYf6Ws74jkAI6zUJ+tf7s5zLzk=", + "FunctionName": "django-helloworld-unicode", + "MemorySize": 512, + "CodeSize": 12152312, + "FunctionArn": "arn:aws:lambda:us-east-1:724336686645:function:django-helloworld-unicode:2", + "Role": "arn:aws:iam::724336686645:role/ZappaLambdaExecution", + "Timeout": 30, + "LastModified": "2016-02-29T14:47:04.499+0000", + "Description": "Zappa Deployment", + "PackageType": "Image" + }, + { + "Version": "3", + "CodeSha256": "Hpt/J6gyhnYXm7NVWwzomJoExr0i9II//4zaLm0DYgc=", + "FunctionName": "django-helloworld-unicode", + "MemorySize": 512, + "CodeSize": 12152182, + "FunctionArn": "arn:aws:lambda:us-east-1:724336686645:function:django-helloworld-unicode:3", + "Role": "arn:aws:iam::724336686645:role/ZappaLambdaExecution", + "Timeout": 30, + "LastModified": "2016-02-29T14:58:08.443+0000", + "Description": "Zappa Deployment", + "PackageType": "Image" + }, + { + "Version": "4", + "CodeSha256": "1ofpfK2Jonu13iPUBMeNYR962iWcD5vL1YrJazF9tF0=", + "FunctionName": "django-helloworld-unicode", + "MemorySize": 512, + "CodeSize": 12154467, + "FunctionArn": "arn:aws:lambda:us-east-1:724336686645:function:django-helloworld-unicode:4", + "Role": "arn:aws:iam::724336686645:role/ZappaLambdaExecution", + "Timeout": 30, + "LastModified": "2016-02-29T16:25:49.425+0000", + "Description": "Zappa Deployment", + "PackageType": "Image" + }, + { + "Version": "5", + "CodeSha256": "bwLhQSjeZOmNC10s2eMO0ljWJBNX5tT4S9MgkvBWjOM=", + "FunctionName": "django-helloworld-unicode", + "MemorySize": 512, + "CodeSize": 12154507, + "FunctionArn": "arn:aws:lambda:us-east-1:724336686645:function:django-helloworld-unicode:5", + "Role": "arn:aws:iam::724336686645:role/ZappaLambdaExecution", + "Timeout": 30, + "LastModified": "2016-02-29T16:34:47.988+0000", + "Description": "Zappa Deployment", + "PackageType": "Image" + }, + { + "Version": "6", + "CodeSha256": "uxHYC6Uf/sUl884TWUqlwi0WWE+ixfxhO964yPec5zM=", + "FunctionName": "django-helloworld-unicode", + "MemorySize": 512, + "CodeSize": 12154780, + "FunctionArn": "arn:aws:lambda:us-east-1:724336686645:function:django-helloworld-unicode:6", + "Role": "arn:aws:iam::724336686645:role/ZappaLambdaExecution", + "Timeout": 30, + "LastModified": "2016-03-01T00:12:28.708+0000", + "Description": "Zappa Deployment", + "PackageType": "Image" + }, + { + "Version": "7", + "CodeSha256": "t3pcqjdrLOqd2p0bRsCEOhgvLJ9sLJrVazpGqhDybsc=", + "FunctionName": "django-helloworld-unicode", + "MemorySize": 512, + "CodeSize": 12154784, + "FunctionArn": "arn:aws:lambda:us-east-1:724336686645:function:django-helloworld-unicode:7", + "Role": "arn:aws:iam::724336686645:role/ZappaLambdaExecution", + "Timeout": 30, + "LastModified": "2016-03-01T00:24:01.446+0000", + "Description": "Zappa Deployment", + "PackageType": "Image" + }, + { + "Version": "8", + "CodeSha256": "qPyTWxngvz505vUX4v0IbW4H6CdQCSiYSGPsNQHPNTc=", + "FunctionName": "django-helloworld-unicode", + "MemorySize": 512, + "CodeSize": 12154778, + "FunctionArn": "arn:aws:lambda:us-east-1:724336686645:function:django-helloworld-unicode:8", + "Role": "arn:aws:iam::724336686645:role/ZappaLambdaExecution", + "Timeout": 30, + "LastModified": "2016-03-01T00:55:35.845+0000", + "Description": "Zappa Deployment", + "PackageType": "Image" + } + ] + } +} diff --git a/tests/tests.py b/tests/tests.py index 5cc6b882a..35e02ac28 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -366,7 +366,10 @@ def test_update_aws_env_vars(self): with mock.patch.object(z, "lambda_client") as mock_client: # Simulate already having some AWS env vars remotely - mock_client.get_function_configuration.return_value = {"Environment": {"Variables": {"REMOTE_ONLY": "AAA", "CHANGED_REMOTE" : "BBB"}}} + mock_client.get_function_configuration.return_value = { + "PackageType": "Zip", + "Environment": {"Variables": {"REMOTE_ONLY": "AAA", "CHANGED_REMOTE" : "BBB"}} + } z.update_lambda_configuration("test", "test", "test", aws_environment_variables={"CHANGED_REMOTE" : "ZZ", "LOCAL_ONLY" : "YY"}) end_result_should_be = {"REMOTE_ONLY": "AAA", "CHANGED_REMOTE" : "ZZ", "LOCAL_ONLY" : "YY"} self.assertEqual(mock_client.update_function_configuration.call_args[1]["Environment"], { "Variables": end_result_should_be}) @@ -374,7 +377,9 @@ def test_update_aws_env_vars(self): with mock.patch.object(z, "lambda_client") as mock_client: # Simulate already having some AWS env vars remotely but none set in aws_environment_variables mock_client.get_function_configuration.return_value = { - "Environment": {"Variables": {"REMOTE_ONLY_1": "AAA", "REMOTE_ONLY_2": "BBB"}}} + "PackageType": "Zip", + "Environment": {"Variables": {"REMOTE_ONLY_1": "AAA", "REMOTE_ONLY_2": "BBB"}} + } z.update_lambda_configuration("test", "test", "test") end_result_should_be = {"REMOTE_ONLY_1": "AAA", "REMOTE_ONLY_2": "BBB"} self.assertEqual(mock_client.update_function_configuration.call_args[1]["Environment"], @@ -386,11 +391,11 @@ def test_update_layers(self): z.credentials_arn = object() with mock.patch.object(z, "lambda_client") as mock_client: - mock_client.get_function_configuration.return_value = {} + mock_client.get_function_configuration.return_value = {"PackageType": "Zip"} z.update_lambda_configuration("test", "test", "test", layers=["Layer1", "Layer2"]) self.assertEqual(mock_client.update_function_configuration.call_args[1]["Layers"], ["Layer1", "Layer2"]) with mock.patch.object(z, "lambda_client") as mock_client: - mock_client.get_function_configuration.return_value = {} + mock_client.get_function_configuration.return_value = {"PackageType": "Zip"} z.update_lambda_configuration("test", "test", "test") self.assertEqual(mock_client.update_function_configuration.call_args[1]["Layers"], []) @@ -401,7 +406,7 @@ def test_update_empty_aws_env_hash(self): with mock.patch.object(z, "lambda_client") as mock_client: # Simulate having no AWS env vars remotely - mock_client.get_function_configuration.return_value = {} + mock_client.get_function_configuration.return_value = {"PackageType": "Zip"} z.update_lambda_configuration("test", "test", "test", aws_environment_variables={"LOCAL_ONLY" : "LZ", "SHOW_AND_TELL" : "SHA"}) end_result_should_be = {"LOCAL_ONLY" : "LZ", "SHOW_AND_TELL" : "SHA"} self.assertEqual(mock_client.update_function_configuration.call_args[1]["Environment"], { "Variables": end_result_should_be}) @@ -932,6 +937,23 @@ def test_cli_colorize_invoke_command_bad_string(self): colorized_string = zappa_cli.colorize_invoke_command(plain_string) self.assertEqual(final_string, colorized_string) + def test_cli_save_python_settings_file(self): + zappa_cli = ZappaCLI() + zappa_cli.api_stage = 'ttt888' + zappa_cli.load_settings('test_settings.json') + + + temp_dir = tempfile.mkdtemp() + good_output_path = os.path.join(temp_dir, 'zappa_settings.py') + assert not os.path.exists(good_output_path) + zappa_cli.save_python_settings_file(good_output_path) + assert os.path.exists(good_output_path) + + bad_output_path = os.path.join(temp_dir, 'settings.py') + with self.assertRaises(ValueError): + zappa_cli.save_python_settings_file(bad_output_path) + + # def test_cli_args(self): # zappa_cli = ZappaCLI() # # Sanity diff --git a/tests/tests_placebo.py b/tests/tests_placebo.py index 47e477173..68b098d76 100644 --- a/tests/tests_placebo.py +++ b/tests/tests_placebo.py @@ -132,6 +132,28 @@ def test_create_lambda_function_local(self, session): function_name='test_lmbda_function55', ) + @placebo_session + def test_create_lambda_function_docker(self, session): + bucket_name = 'lmbda' + docker_image_uri = 'docker_image_uri' + + z = Zappa(session) + z.aws_region = 'us-east-1' + z.load_credentials(session) + z.credentials_arn = 'arn:aws:iam::12345:role/ZappaLambdaExecution' + + arn = z.create_lambda_function( + bucket=bucket_name, + docker_image_uri=docker_image_uri, + function_name='test_lmbda_function55', + ) + + arn = z.update_lambda_function( + bucket=bucket_name, + docker_image_uri=docker_image_uri, + function_name='test_lmbda_function55', + ) + @placebo_session def test_rollback_lambda_function_version(self, session): z = Zappa(session) @@ -143,6 +165,23 @@ def test_rollback_lambda_function_version(self, session): function_arn = z.rollback_lambda_function_version(function_name, 1) + @placebo_session + def test_rollback_lambda_function_version_docker(self, session): + z = Zappa(session) + z.credentials_arn = 'arn:aws:iam::724336686645:role/ZappaLambdaExecution' + + function_name = 'django-helloworld-unicode' + + with self.assertRaises(NotImplementedError): + z.rollback_lambda_function_version(function_name) + + @placebo_session + def test_is_lambda_function_ready(self, session): + z = Zappa(session) + z.credentials_arn = 'arn:aws:iam::724336686645:role/ZappaLambdaExecution' + function_name = 'django-helloworld-unicode' + z.is_lambda_function_ready(function_name) + @placebo_session def test_invoke_lambda_function(self, session): z = Zappa(session) diff --git a/zappa/cli.py b/zappa/cli.py index 6fa118b58..a89c3baf6 100755 --- a/zappa/cli.py +++ b/zappa/cli.py @@ -652,7 +652,7 @@ def save_python_settings_file(self, output_path=None): settings_path = output_path or 'zappa_settings.py' print('Generating Zappa settings Python file and saving to {}'.format(settings_path)) if not settings_path.endswith('zappa_settings.py'): - raise Exception('Settings file must be named zappa_settings.py') + raise ValueError('Settings file must be named zappa_settings.py') zappa_settings_s = self.get_zappa_settings_string() with open(settings_path, 'w') as f_out: f_out.write(zappa_settings_s) diff --git a/zappa/core.py b/zappa/core.py index 9e3bc7465..b4feef89f 100644 --- a/zappa/core.py +++ b/zappa/core.py @@ -1279,7 +1279,7 @@ def rollback_lambda_function_version(self, function_name, versions_back=1, publi response = self.lambda_client.list_versions_by_function(FunctionName=function_name) # https://github.com/Miserlou/Zappa/pull/2192 - if response['Versions'][-1]["PackageType"] == "Image": + if len(response.get('Versions', [])) > 1 and response['Versions'][-1]["PackageType"] == "Image": raise NotImplementedError( "Zappa's rollback functionality is not available for Docker based deployments" ) diff --git a/zappa/handler.py b/zappa/handler.py index 358cf0955..78a31cfda 100644 --- a/zappa/handler.py +++ b/zappa/handler.py @@ -606,8 +606,6 @@ def handler(self, event, context): def lambda_handler(event, context): # pragma: no cover - print(event) - print(context) return LambdaHandler.lambda_handler(event, context)