Exemple #1
0
    def test_email_boarding_pass(self, mock_make_request):
        fake_data = {
            'names': [{
                'firstName': 'George',
                'lastName': 'Bush'
            }],
            'emailAddress': '*****@*****.**'
        }

        swa.email_boarding_pass(self.names, self.confirmation_number,
                                self.email)
        mock_make_request.assert_called_with(
            "/record-locator/ABC123/operation-infos/mobile-boarding-pass/notifications",
            fake_data,
            "application/vnd.swacorp.com.mobile.notifications-v1.0+json")
Exemple #2
0
def check_in(event, context):
    """
    This function is triggered at check-in time and completes the check-in via
    the Southwest API and emails the reservation, if requested.
    """

    confirmation_number = event['confirmation_number']
    email = event['email']

    # Support older check-ins which did not support multiple passengers
    if "passengers" in event:
        passengers = event['passengers']
    else:
        passengers = [{
            "firstName": event['first_name'],
            "lastName": event['last_name']
        }]

    log.info("Checking in {} ({})".format(
        passengers, confirmation_number
    ))

    try:
        resp = swa.check_in(passengers, confirmation_number)
        log.info("Checked in {} passengers!".format(len(passengers)))
        log.debug("Check-in response: {}".format(resp))
    except exceptions.ReservationCancelledError:
        log.error("Reservation {} has been cancelled".format(confirmation_number))
        return False
    except Exception as e:
        log.error("Error checking in: {}".format(e))
        raise

    log.info("Emailing boarding passes to {}".format(email))
    try:
        swa.email_boarding_pass(passengers, confirmation_number, email)
    except Exception as e:
        log.error("Error emailing boarding pass: {}".format(e))

    # Raise exception to schedule the next check-in
    # This is caught by AWS Step and then schedule_check_in is called again
    # TODO(dw): I think there are better looping primitives in AWS Step now
    if len(event['check_in_times']['remaining']) > 0:
        raise exceptions.NotLastCheckIn()

    return True