Skip to content

Commit

Permalink
create and update function add runtime check
Browse files Browse the repository at this point in the history
  • Loading branch information
rsonghuster committed Jan 18, 2018
1 parent 82cfbbc commit a70c5e8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fc2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""

__author__ = 'Aliyun Function Compute'
__version__ = '2.0.2'
__version__ = '2.0.4'

from .client import Client
from .fc_exceptions import FcError
Expand Down
6 changes: 6 additions & 0 deletions fc2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ def create_function(
"""
self._check_function_param_valid(codeZipFile, codeDir, codeOSSBucket, codeOSSObject)

if not isinstance(runtime, str):
raise Exception("runtime type must be string")

method = 'POST'
path = '/{0}/services/{1}/functions'.format(self.api_version, serviceName)
headers = self._build_common_headers(method, path, headers)
Expand Down Expand Up @@ -403,6 +406,9 @@ def update_function(
'timeout': 60, // in second
}
"""
if runtime and (not isinstance(runtime, str)):
raise Exception("runtime type must be string")

method = 'PUT'
path = '/{0}/services/{1}/functions/{2}'.format(self.api_version, serviceName, functionName)
headers = self._build_common_headers(method, path, headers)
Expand Down
8 changes: 8 additions & 0 deletions test/function_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ def test_update(self):
with self.assertRaises(fc2.FcError):
self.client.update_function(self.serviceName, functionName, description='invalid', headers ={'if-match':'invalid etag'})

with self.assertRaises(Exception):
self.client.update_function(self.serviceName, functionName, codeZipFile='test/hello_world/hello_world.zip', runtime = 10)

self.assertEqual(func['description'], desc)

self.client.delete_function(self.serviceName, functionName)
Expand Down Expand Up @@ -290,6 +293,11 @@ def test_check_op_function_param_check(self):
self.serviceName, functionName,
handler='main.my_handler', runtime='python2.7', codeOSSBucket='test-bucket' , description=desc)

with self.assertRaises(Exception):
function = self.client.create_function(
self.serviceName, functionName,
handler='main.my_handler', runtime=10, codeZipFile='test/hello_world/hello_world.zip')


if __name__ == '__main__':
unittest.main()

0 comments on commit a70c5e8

Please sign in to comment.