Пример #1
0
 def test_lambda_handler_ohio(self):
     from lambda_local.main import call
     from lambda_local.context import Context
     # event = json.loads(open('ohio.json').read())[0]
     json_file = open('ohio.json')
     event = json_file.read()
     context = Context(timeout=5,
                       arn_string="arn.12345",
                       version_name="1.0")
     # context = Context(5)
     call("lambda_handler", event, context)
def test_happy(s3):
    os.environ["ATTACHMENT_BUCKET"] = "a.bucket.ons.digital"
    s3.create_bucket(Bucket=os.environ['ATTACHMENT_BUCKET'])
    s3.create_bucket(Bucket='email')
    (result, error_type) = call(lambda_function.lambda_handler, good_event(),
                                Context(2))
    assert error_type is None
    assert result['statusCode'] == '201'
def test_noBucketConfigured():
    event = good_event()
    (result, error_type) = call(lambda_function.lambda_handler, event,
                                Context(2))
    assert error_type is not None

    e = json.loads(result)
    assert e["errorMessage"] == "expected string or bytes-like object"
    assert e["errorType"] == "TypeError"
def test_bucketDoesNotExist():
    os.environ["ATTACHMENT_BUCKET"] = "a.bucket.ons.digital"
    (result, error_type) = call(lambda_function.lambda_handler, good_event(),
                                Context(2))
    assert error_type is not None

    e = json.loads(result)
    assert e["errorMessage"] == (
        'An error occurred (NoSuchBucket) when calling '
        'the GetBucketLocation operation: The specified '
        'bucket does not exist')
    assert e["errorType"] == "NoSuchBucket"
Пример #5
0
     event = generate_event('NoIntent')
 elif utterance in ['play who am i', 'launch']:
     dialog_state = ''
     event = generate_event('LaunchRequest', template='LaunchRequest', dialog_state='')
 elif utterance in ['download movie']:
     event = generate_event('DownloadIntent')
 else:
     if elicit_slot == 'title':
         dialog_state = 'IN_PROGRESS'
         elicit_slot = ''
         event = generate_event('DownloadIntent', slots={'title': utterance}, dialog_state='IN_PROGRESS')
     else:
         event = {}
 context = Context(8, arn_string=arn_string, version_name='$LATEST')
 if event:
     response_json = call(lambda_handler, event, default_timeout)
     # print(response[0])
     speech = ''
     reprompt = ''
     response = response_json[0].get('response', {})
     if response:
         if response.get('outputSpeech', {}):
             if response['outputSpeech']['type'] == 'PlainText':
                 speech = response['outputSpeech']['text']
             elif response['outputSpeech']['type'] == 'SSML':
                 speech = response['outputSpeech']['ssml']
             if response.get('reprompt', {}):
                 if response['reprompt']['outputSpeech']['type'] == 'PlainText':
                     reprompt = response['reprompt']['outputSpeech']['text']
                 elif response['reprompt']['outputSpeech']['type'] == 'SSML':
                     reprompt = response['reprompt']['outputSpeech']['ssml']
Пример #6
0
def test():
    event = {}
    context = Context(5)
    call(lambda_handler.handler, event, context)
Пример #7
0
def index():
    # context = Context(8, arn_string=arn_string, version_name='$LATEST')
    response = call(lambda_handler, request.json, Context(8))
    return (json.dumps(response), 200, {'Content-Type': 'application/json'})
def execute(event):
    """Shorthand execute lambda call"""
    return call(lambda_function.lambda_handler, event, Context(2))