def test_invoke(self):
helloWorld= 'test_invoke_hello_world_' + ''.join(random.choice(string.ascii_lowercase) for _ in range(8))
logging.info('create function: {0}'.format(helloWorld))
self.client.create_function(
self.serviceName, helloWorld,
handler='main.my_handler', runtime='python2.7', codeZipFile='test/hello_world/hello_world.zip')
r = self.client.invoke_function(self.serviceName, helloWorld)
self.assertEqual(r.data.decode('utf-8'), 'hello world')
self.client.delete_function(self.serviceName, helloWorld)
# read a image as invoke parameter.
imageProcess = 'test_invoke_nodejs_image_resize'
logging.info('create function: {0}'.format(imageProcess))
self.client.create_function(
self.serviceName, imageProcess,
handler='image_process.resize', runtime='nodejs4.4', codeDir='test/image_process/code')
sourceImage = open('test/image_process/data/serverless.png', 'rb')
destImage = open('/tmp/serverless.png', 'wb')
r = self.client.invoke_function(self.serviceName, imageProcess, payload=sourceImage)
destImage.write(r.data)
sourceImage.close()
destImage.close()
self.assertEqual(imghdr.what('/tmp/serverless.png'), 'png')
self.client.delete_function(self.serviceName, imageProcess)
评论列表
文章目录