diff options
author | kyleknap <kyleknap@amazon.com> | 2015-01-19 14:05:22 -0800 |
---|---|---|
committer | kyleknap <kyleknap@amazon.com> | 2015-01-21 14:24:14 -0800 |
commit | f40e985fb1af22c9fbb77b97753b0627716b2478 (patch) | |
tree | d8995923bdb7b9afa20bcd3792b400789bf21a69 /tests | |
parent | 89f08692c2c4727d4d686bd4a8f05504d30b952c (diff) | |
download | boto-f40e985fb1af22c9fbb77b97753b0627716b2478.tar.gz |
Update lambda to be more flexible with streams
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/awslambda/__init__.py | 21 | ||||
-rw-r--r-- | tests/unit/awslambda/test_awslambda.py | 91 |
2 files changed, 112 insertions, 0 deletions
diff --git a/tests/unit/awslambda/__init__.py b/tests/unit/awslambda/__init__.py new file mode 100644 index 00000000..70cc23fe --- /dev/null +++ b/tests/unit/awslambda/__init__.py @@ -0,0 +1,21 @@ +# Copyright (c) 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, dis- +# tribute, sublicense, and/or sell copies of the Software, and to permit +# persons to whom the Software is furnished to do so, subject to the fol- +# lowing conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- +# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# diff --git a/tests/unit/awslambda/test_awslambda.py b/tests/unit/awslambda/test_awslambda.py new file mode 100644 index 00000000..74cb0a0e --- /dev/null +++ b/tests/unit/awslambda/test_awslambda.py @@ -0,0 +1,91 @@ +# Copyright (c) 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, dis- +# tribute, sublicense, and/or sell copies of the Software, and to permit +# persons to whom the Software is furnished to do so, subject to the fol- +# lowing conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- +# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +import tempfile +import shutil +import os + +from boto.compat import json +from boto.awslambda.layer1 import AWSLambdaConnection +from tests.unit import AWSMockServiceTestCase + + +class TestAWSLambda(AWSMockServiceTestCase): + connection_class = AWSLambdaConnection + + def default_body(self): + return b'{}' + + def test_upload_function_binary(self): + self.set_http_response(status_code=201) + function_data = b'This is my file' + self.service_connection.upload_function( + function_name='my-function', + function_zip=function_data, + role='myrole', + handler='myhandler', + mode='event', + runtime='nodejs' + ) + self.assertEqual(self.actual_request.body, function_data) + self.assertEqual( + self.actual_request.headers['Content-Length'], + str(len(function_data)) + ) + self.assertEqual( + self.actual_request.path, + '/2014-11-13/functions/my-function?Handler=myhandler&Mode' + '=event&Role=myrole&Runtime=nodejs' + ) + + def test_upload_function_file(self): + self.set_http_response(status_code=201) + rootdir = tempfile.mkdtemp() + self.addCleanup(shutil.rmtree, rootdir) + + filename = 'test_file' + function_data = b'This is my file' + full_path = os.path.join(rootdir, filename) + + with open(full_path, 'wb') as f: + f.write(function_data) + + with open(full_path, 'rb') as f: + self.service_connection.upload_function( + function_name='my-function', + function_zip=f, + role='myrole', + handler='myhandler', + mode='event', + runtime='nodejs' + ) + # Ensure the body is a file like object by checking that it + # can be read. + self.assertTrue(hasattr(self.actual_request.body, 'read')) + self.assertEqual( + self.actual_request.headers['Content-Length'], + str(len(function_data)) + ) + self.assertEqual( + self.actual_request.path, + '/2014-11-13/functions/my-function?Handler=myhandler&Mode' + '=event&Role=myrole&Runtime=nodejs' + ) |