def main(event, context): """ This function is triggered when a check-in fails. It emails a notification to the user letting them know that they need to check in manually. """ confirmation_number = event['confirmation_number'] email = event['email'] first_name = event['first_name'] last_name = event['last_name'] subject = "Error checking in to your flight" body = ( "Sorry! There was an error checking in to your flight. " "Please check in to your flight manually to get your boarding passes.\n\n" f"First Name: {first_name}\n" f"Last Name: {last_name}\n" f"Confirmation #{confirmation_number}\n\n" "https://www.southwest.com/air/check-in/index.html" ) mail.send_ses_email(email, subject, body) # TODO(dw): DRY and move this into a separate task instead of duplicating # here and in the check in handler. # Return False to indicate that there are check-ins remaining if len(event['check_in_times']['remaining']) > 0: return False return True
def test_send_ses_email(self, mock_client): ses_mock = mock.Mock() mock_client.return_value = ses_mock expected_msg = { 'Subject': { 'Data': 'fake subject', 'Charset': 'UTF-8' }, 'Body': { 'Text': { 'Data': 'fake body', 'Charset': 'UTF-8' } } } expected_destination = {'ToAddresses': ['*****@*****.**']} mail.send_ses_email("*****@*****.**", "fake subject", "fake body", source="*****@*****.**") assert ses_mock.send_email.call_args[1]['Source'] == "*****@*****.**" assert ses_mock.send_email.call_args[1][ 'Destination'] == expected_destination assert ses_mock.send_email.call_args[1]['Message'] == expected_msg
def test_send_ses_email_bcc_destination(self, mock_client): ses_mock = mock.Mock() mock_client.return_value = ses_mock expected_destination = {'ToAddresses': ['*****@*****.**'], 'BccAddresses': ['*****@*****.**']} mail.send_ses_email("*****@*****.**", "fake subject", "fake body", bcc="*****@*****.**") assert ses_mock.send_email.call_args[1]['Destination'] == expected_destination
def main(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'] first_name = event['first_name'] last_name = event['last_name'] log.info("Checking in {} {} ({})".format(first_name, last_name, confirmation_number)) try: resp = swa.check_in(first_name, last_name, confirmation_number) log.info("Checked in successfully!") log.debug("Check-in response: {}".format(resp)) except exceptions.ReservationNotFoundError: log.error( "Reservation {} not found. It may have been cancelled".format( confirmation_number)) raise except Exception as e: log.error("Error checking in: {}".format(e)) raise # Send success email # TODO(dw): This should probably be a separate task in the step function subject = "You're checked in!" body = "I just checked into your flight! Please login to Southwest to view your boarding passes." try: body = _generate_email_body(resp) except Exception as e: log.warning( "Error parsing flight details from check-in response: {}".format( e)) try: mail.send_ses_email(email, subject, body) except Exception as e: log.warning("Error sending email: {}".format(e)) # Older events use check_in_times.remaining to track remaining check-ins # TODO(dw): Remove this when old events are deprecated if 'remaining' in event['check_in_times'] and len( event['check_in_times']['remaining']) > 0: return False return True