Пример #1
0
    def test_error_message_response(self):
        zip_code = "94501"
        self.given_dynamo_table_exists()

        event = self.load_resource("inbound_{}.json".format(zip_code))

        response = lambda_function.lambda_handler(event, {})

        self.assertEqual(response, {"body": "<?xml version='1.0' encoding='UTF-8'?><Response><Message><Body>Oops, an unknown error occurred. AirNow may be overloaded at the moment.</Body></Message></Response>"})
Пример #2
0
    def test_inbound_text(self):
        event = self.load_resource("inbound_text.json")

        response = lambda_function.lambda_handler(event, {})

        self.assertEqual(
            response, {
                "body":
                "<?xml version='1.0' encoding='UTF-8'?><Response><Message><Body>Send us a zip code and we'll reply with the area's Air Quality Index (AQI). Put \"map\" at the end and we'll include the regional map too.</Body></Message></Response>"
            })
Пример #3
0
    def test_inbound_52328(self):
        zip_code = "52328"
        self.given_dynamo_table_exists()
        self.given_api_routes_mocked()
        self.given_airnow_routes_mocked()

        event = self.load_resource("inbound_{}.json".format(zip_code))

        response = lambda_function.lambda_handler(event, {})

        self.assertEqual(response, {"body": "<?xml version='1.0' encoding='UTF-8'?><Response><Message><Body>Sorry, AirNow data is unavailable for this zip code.</Body></Message></Response>"})
Пример #4
0
    def test_inbound_94501_map(self):
        zip_code = "94501"
        self.given_dynamo_table_exists()
        self.given_api_routes_mocked()
        self.given_airnow_routes_mocked()

        event = self.load_resource("inbound_{}_map.json".format(zip_code))

        response = lambda_function.lambda_handler(event, {})

        self.assertTrue("body" in response)
        self.assertTrue("<Response><Message><Body>" in response["body"])
        self.assertTrue("AQI of" in response["body"])
        self.assertTrue("<Media>" in response["body"])
Пример #5
0
def route_inbound():
    event = {
        "body-json": urlencode(request.form),
        "params": {
            "path": {},
            "querystring": {},
            "header": {
                "Accept": "*/*",
                "Cache-Control": "max-age=259200",
                "Content-Type": "application/x-www-form-urlencoded",
                "Host": "127.0.0.1",
                "User-Agent": "TwilioProxy/1.1",
                "X-Amzn-Trace-Id": "Root=XXX",
                "X-Forwarded-For": "10.10.10.10",
                "X-Forwarded-Port": "443",
                "X-Forwarded-Proto": "https",
                "X-Twilio-Signature": "XXX="
            }
        },
        "stage-variables": {},
        "context": {
            "account-id": "",
            "api-id": "XXX",
            "api-key": "",
            "authorizer-principal-id": "",
            "caller": "",
            "cognito-authentication-provider": "",
            "cognito-authentication-type": "",
            "cognito-identity-id": "",
            "cognito-identity-pool-id": "",
            "http-method": "POST",
            "stage": "prod",
            "source-ip": "10.10.10.10",
            "user": "",
            "user-agent": "TwilioProxy/1.1",
            "user-arn": "",
            "request-id": "XXX",
            "resource-id": "XXX",
            "resource-path": "/inbound"
        }
    }

    return inbound_route.lambda_handler(event, {})["body"]