attmpt 2 to resolve StringIO not being within Python 3 anymore
This commit is contained in:
parent
6c577091da
commit
7c3005e582
@ -1,14 +1,19 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import StringIO
|
||||
import base64
|
||||
import datetime
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
import StringIO
|
||||
import sys
|
||||
import zipfile
|
||||
|
||||
try:
|
||||
from StringIO import StringIO
|
||||
except:
|
||||
from io import StringIO
|
||||
|
||||
import boto.awslambda
|
||||
from moto.core import BaseBackend
|
||||
from moto.s3.models import s3_backend
|
||||
@ -104,18 +109,18 @@ class LambdaFunction(object):
|
||||
def _invoke_lambda(self, code, event={}, context={}):
|
||||
# TO DO: context not yet implemented
|
||||
try:
|
||||
codeOut = StringIO.StringIO()
|
||||
codeErr = StringIO.StringIO()
|
||||
mycode = "\n".join([self.code, 'print lambda_handler(%s, %s)' % (event, context)])
|
||||
codeOut = StringIO()
|
||||
codeErr = StringIO()
|
||||
mycode = "\n".join([self.code, 'print lambda_handler(%s, %s)' % (event, context)])
|
||||
#print "moto_lambda_debug: ", mycode
|
||||
sys.stdout = codeOut
|
||||
sys.stderr = codeErr
|
||||
exec(mycode, {'event': event, 'context': context})
|
||||
exec mycode
|
||||
exec_err = codeErr.getvalue()
|
||||
exec_out = codeOut.getvalue()
|
||||
result = "\n".join([exec_out, exec_err])
|
||||
except Exception as ex:
|
||||
result = 'Exception %s, %s' % (ex, ex.message)
|
||||
result = '%s\n\n\nException %s, %s' % (mycode, ex, ex.message)
|
||||
finally:
|
||||
codeErr.close()
|
||||
codeOut.close()
|
||||
|
@ -5,6 +5,7 @@ import botocore.client
|
||||
import boto3
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
import zipfile
|
||||
import sure # noqa
|
||||
|
||||
@ -67,7 +68,7 @@ def test_invoke_function():
|
||||
Publish=True,
|
||||
)
|
||||
|
||||
success_result = conn.invoke(FunctionName='testFunction', InvocationType='Event', Payload="Mostly Harmless")
|
||||
success_result = conn.invoke(FunctionName='testFunction', InvocationType='Event', Payload='Mostly Harmless')
|
||||
success_result["StatusCode"].should.equal(202)
|
||||
|
||||
conn.invoke.when.called_with(
|
||||
@ -76,10 +77,9 @@ def test_invoke_function():
|
||||
Payload='{}'
|
||||
).should.throw(botocore.client.ClientError)
|
||||
|
||||
success_result = conn.invoke(FunctionName='testFunction', InvocationType='RequestResponse', Payload='{"msg": "So long and thanks for all the fish"}')
|
||||
success_result = conn.invoke(FunctionName='testFunction', InvocationType='RequestResponse',
|
||||
Payload=json.dumps({'msg': 'So long and thanks for all the fish'}))
|
||||
success_result["StatusCode"].should.equal(202)
|
||||
|
||||
import base64
|
||||
base64.b64decode(success_result["LogResult"]).decode('utf-8').should.equal("({u'msg': u'So long and thanks for all the fish'}, {})\n\n")
|
||||
|
||||
@mock_ec2
|
||||
|
Loading…
Reference in New Issue
Block a user