Пример #1
0
 def test_check_in_reservation_cancelled(self):
     responses.add(
         responses.POST,
         'https://api-extensions.southwest.com/v1/mobile/reservations/record-locator/ABC123/boarding-passes',
         json=util.load_fixture('check_in_reservation_cancelled'),
         status=404)
     with self.assertRaises(exceptions.ReservationCancelledError):
         result = swa.check_in(self.names, self.confirmation_number)
Пример #2
0
 def test_check_in_success(self):
     responses.add(
         responses.POST,
         'https://api-extensions.southwest.com/v1/mobile/reservations/record-locator/ABC123/boarding-passes',
         json=util.load_fixture('check_in_success'),
         status=200)
     result = swa.check_in(self.names, self.confirmation_number)
     assert result['passengerCheckInDocuments'][0]['passenger'][
         'firstName'] == "GEORGE"
     assert result['passengerCheckInDocuments'][0]['passenger'][
         'lastName'] == "BUSH"
Пример #3
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
Пример #4
0
 def test_check_in_call(self, mock_make_request):
     swa.check_in(self.names, self.confirmation_number)
     mock_make_request.assert_called_with(
         "/reservations/record-locator/ABC123/boarding-passes", self.data,
         "application/vnd.swacorp.com.mobile.boarding-passes-v1.0+json")