Пример #1
0
 def test_not_found(self):
     e = FakeEmail('Price alert: review your monthly delivery', 0)
     try:
         mail.find_name_and_confirmation_number(e)
         assert False, "ReservationNotFoundError was not raised"
     except exceptions.ReservationNotFoundError:
         pass
Пример #2
0
 def test_not_found_fwd_name(self):
     # NOTE(dw): This is failing for now because it detects Fwd as the first name
     test_subjects = [
         'Fwd: George\'s 12/25 Burbank trip (ABC123): itinerary.',
         'Fw: George\'s 12/25 Burbank trip (ABC123): itinerary.',
         'fw: George\'s 12/25 Burbank trip (ABC123): itinerary.',
         'fwd: George\'s 12/25 Burbank trip (ABC123): itinerary.'
     ]
     for subject in test_subjects:
         e = FakeEmail(subject, 0)
         try:
             mail.find_name_and_confirmation_number(e)
             assert False, "ReservationNotFoundError was not raised"
         except exceptions.ReservationNotFoundError:
             pass
 def test_find_name_and_confirmation_number_shortcut(self):
     e = FakeEmail('ABC123 George Bush', 0)
     expected = dict(first_name="George",
                     last_name="Bush",
                     confirmation_number="ABC123")
     result = mail.find_name_and_confirmation_number(e)
     assert result == expected
 def test_find_name_with_space_and_confirmation_number(self):
     e = FakeEmail(
         'Fwd: Flight reservation (ABC123) | 25FEB18 | AUS-TUL | Mc Lovin/Steven',
         0)
     expected = dict(first_name="Steven",
                     last_name="Mc Lovin",
                     confirmation_number="ABC123")
     result = mail.find_name_and_confirmation_number(e)
     assert result == expected
 def test_find_name_and_confirmation_number(self):
     e = FakeEmail(
         'Fwd: Flight reservation (ABC123) | 25FEB18 | AUS-TUL | Bush/George',
         0)
     expected = dict(first_name="George",
                     last_name="Bush",
                     confirmation_number="ABC123")
     result = mail.find_name_and_confirmation_number(e)
     assert result == expected
Пример #6
0
def main(event, context):
    """
    This function is triggered when as an SES Action when a new e-mail is
    received. It scrapes the email to find the name and confirmation
    number of the passenger to check-in, and then executes the AWS Step
    state machine provided in the `STATE_MACHINE_ARN` environment variable.
    """

    sfn = boto3.client('stepfunctions')
    ses_notification = event['Records'][0]['ses']
    # ARN of the AWS Step State Machine to execute when an email
    # is successfully parsed and a new check-in should run.
    state_machine_arn = os.getenv('STATE_MACHINE_ARN')

    log.debug("State Machine ARN: {}".format(state_machine_arn))
    log.debug("SES Notification: {}".format(ses_notification))

    ses_msg = mail.SesMailNotification(ses_notification['mail'])

    try:
        reservation = mail.find_name_and_confirmation_number(ses_msg)
        log.info("Found reservation: {}".format(reservation))
    except Exception as e:
        log.error("Error scraping email {}: {}".format(ses_msg.message_id, e))
        if not ses_msg.from_email.endswith('southwest.com'):
            mail.send_failure_notification(ses_msg.from_email)
        return False

    # Don't add the email if it's straight from southwest.com
    if not ses_msg.from_email.endswith('southwest.com'):
        reservation['email'] = ses_msg.from_email

    execution = sfn.start_execution(stateMachineArn=state_machine_arn,
                                    name=_get_sfn_execution_name(reservation),
                                    input=json.dumps(reservation))

    log.debug("State machine started at: {}".format(execution['startDate']))
    log.debug("Execution ARN: {}".format(execution['executionArn']))

    # Remove the startDate from the return value because datetime objects don't
    # easily serialize to JSON.
    del (execution['startDate'])

    return execution
Пример #7
0
    def test_find_new_reservation_email(self):
        test_subjects = [
            'fwd: George Bush\'s 12/25 Boston Logan trip (ABC123): Your reservation is confirmed.',
            'Fwd: George Bush\'s 12/25 Boston Logan trip (ABC123): Your reservation is confirmed.',
            'Fw: George Bush\'s 12/25 Boston Logan trip (ABC123): Your reservation is confirmed.',
            'George Bush\'s 12/25 Boston Logan trip (ABC123): Your change is confirmed.'
            'George Bush\'s 12/25 Detroit trip (ABC123)',
            'George Walker Bush\'s 12/25 Detroit trip (ABC123)',
            'George W Bush\'s 12/25 Detroit trip (ABC123)',
            'George W JR Bush\'s 12/25 Detroit trip (ABC123)',
            'George W. Bush\'s 12/25 Detroit trip (ABC123)',
            'George W Jr. Bush\'s 12/25 Detroit trip (ABC123)',
            'George W. Jr. Bush\'s 12/25 Detroit trip (ABC123)'
        ]

        for subject in test_subjects:
            e = FakeEmail(subject, 0, util.load_fixture('new_reservation_email'))
            expected = dict(first_name="George", last_name="Bush", confirmation_number="ABC123")
            result = mail.find_name_and_confirmation_number(e)
            assert result == expected, "Failed subject: {}".format(subject)