FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
aws-cli/tests/functional/awslambda/test_function.py at develop · abinkrishna/aws-cli · GitHub
abinkrishna
/
aws-cli
Public
forked from
aws/aws-cli
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
aws-cli
/
tests
/
functional
/
awslambda
/
test_function.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
145 lines (125 loc) · 5.67 KB
Breadcrumbs
aws-cli
/
tests
/
functional
/
awslambda
/
test_function.py
Copy path
File metadata and controls
145 lines (125 loc) · 5.67 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import
os
import
zipfile
from
contextlib
import
closing
from
awscli
.
testutils
import
unittest
from
awscli
.
testutils
import
BaseAWSCommandParamsTest
from
awscli
.
testutils
import
FileCreator
class
BaseLambdaTests
(
BaseAWSCommandParamsTest
):
def
setUp
(
self
):
super
(
BaseLambdaTests
,
self
).
setUp
()
self
.
files
=
FileCreator
()
self
.
temp_file
=
self
.
files
.
create_file
(
'foo'
,
'mycontents'
)
self
.
zip_file
=
os
.
path
.
join
(
self
.
files
.
rootdir
,
'foo.zip'
)
with
closing
(
zipfile
.
ZipFile
(
self
.
zip_file
,
'w'
))
as
f
:
f
.
write
(
self
.
temp_file
)
with
open
(
self
.
zip_file
,
'rb'
)
as
f
:
self
.
zip_file_contents
=
f
.
read
()
def
tearDown
(
self
):
super
(
BaseLambdaTests
,
self
).
tearDown
()
self
.
files
.
remove_all
()
class
TestCreateFunction
(
BaseLambdaTests
):
prefix
=
'lambda create-function'
def
test_create_function_with_file
(
self
):
cmdline
=
self
.
prefix
cmdline
+=
' --function-name myfunction --runtime myruntime'
cmdline
+=
' --role myrole --handler myhandler'
cmdline
+=
' --zip-file fileb://%s'
%
self
.
zip_file
result
=
{
'FunctionName'
:
'myfunction'
,
'Runtime'
:
'myruntime'
,
'Role'
:
'myrole'
,
'Handler'
:
'myhandler'
,
'Code'
: {
'ZipFile'
:
self
.
zip_file_contents
}
}
self
.
assert_params_for_cmd
(
cmdline
,
result
)
def
test_create_function_with_code_argument
(
self
):
cmdline
=
self
.
prefix
cmdline
+=
' --function-name myfunction --runtime myruntime'
cmdline
+=
' --role myrole --handler myhandler'
cmdline
+=
' --code S3Bucket=mybucket,S3Key=mykey,S3ObjectVersion=vs'
result
=
{
'FunctionName'
:
'myfunction'
,
'Runtime'
:
'myruntime'
,
'Role'
:
'myrole'
,
'Handler'
:
'myhandler'
,
'Code'
: {
'S3Bucket'
:
'mybucket'
,
'S3Key'
:
'mykey'
,
'S3ObjectVersion'
:
'vs'
}
}
self
.
assert_params_for_cmd
(
cmdline
,
result
)
def
test_create_function_with_code_and_zipfile_argument
(
self
):
cmdline
=
self
.
prefix
cmdline
+=
' --function-name myfunction --runtime myruntime'
cmdline
+=
' --role myrole --handler myhandler'
cmdline
+=
' --code S3Bucket=mybucket,S3Key=mykey,S3ObjectVersion=vs'
cmdline
+=
' --zip-file fileb://%s'
%
self
.
zip_file
result
=
{
'FunctionName'
:
'myfunction'
,
'Runtime'
:
'myruntime'
,
'Role'
:
'myrole'
,
'Handler'
:
'myhandler'
,
'Code'
: {
'S3Bucket'
:
'mybucket'
,
'S3Key'
:
'mykey'
,
'S3ObjectVersion'
:
'vs'
,
'ZipFile'
:
self
.
zip_file_contents
}
}
self
.
assert_params_for_cmd
(
cmdline
,
result
)
def
test_create_function_with_zip_file_in_code_argument
(
self
):
cmdline
=
self
.
prefix
cmdline
+=
' --function-name myfunction --runtime myruntime'
cmdline
+=
' --role myrole --handler myhandler'
cmdline
+=
' --code S3Bucket=mybucket,S3Key=mykey,S3ObjectVersion=vs,'
cmdline
+=
'ZipFile=foo'
stdout
,
stderr
,
rc
=
self
.
run_cmd
(
cmdline
,
expected_rc
=
255
)
self
.
assertIn
(
'ZipFile cannot be provided as part of the --code'
,
stderr
)
def
test_create_function_with_invalid_file_contents
(
self
):
cmdline
=
self
.
prefix
cmdline
+=
' --function-name myfunction --runtime myruntime'
cmdline
+=
' --role myrole --handler myhandler'
cmdline
+=
' --zip-file filename_instead_of_contents.zip'
stdout
,
stderr
,
rc
=
self
.
run_cmd
(
cmdline
,
expected_rc
=
255
)
self
.
assertIn
(
'must be a zip file with the fileb:// prefix'
,
stderr
)
# Should also give a pointer to fileb:// for them.
self
.
assertIn
(
'fileb://'
,
stderr
)
def
test_not_using_fileb_prefix
(
self
):
cmdline
=
self
.
prefix
cmdline
+=
' --function-name myfunction --runtime myruntime'
cmdline
+=
' --role myrole --handler myhandler'
# Note file:// instead of fileb://
cmdline
+=
' --zip-file file://%s'
%
self
.
zip_file
stdout
,
stderr
,
rc
=
self
.
run_cmd
(
cmdline
,
expected_rc
=
255
)
# Ensure we mention fileb:// to give the user an idea of
# where to go next.
self
.
assertIn
(
'fileb://'
,
stderr
)
class
TestUpdateFunctionCode
(
BaseLambdaTests
):
prefix
=
'lambda update-function-code'
def
test_not_using_fileb_prefix
(
self
):
cmdline
=
self
.
prefix
+
' --function-name foo'
cmdline
+=
' --zip-file filename_instead_of_contents.zip'
stdout
,
stderr
,
rc
=
self
.
run_cmd
(
cmdline
,
expected_rc
=
255
)
self
.
assertIn
(
'must be a zip file with the fileb:// prefix'
,
stderr
)
# Should also give a pointer to fileb:// for them.
self
.
assertIn
(
'fileb://'
,
stderr
)
def
test_using_fileb_prefix_succeeds
(
self
):
cmdline
=
self
.
prefix
cmdline
+=
' --function-name myfunction'
cmdline
+=
' --zip-file fileb://%s'
%
self
.
zip_file
result
=
{
'FunctionName'
:
'myfunction'
,
'ZipFile'
:
self
.
zip_file_contents
,
}
self
.
assert_params_for_cmd
(
cmdline
,
result
)
Back
|
FazBrowse Home
|
New Git URL