Exemplo n.º 1
0
def test_get_attachment_no_file():
    """
    Test that an email with no file raises a UserWarning.
    """
    with pytest.raises(UserWarning):
        with open(EMAIL_FILES_ROOT + 'noAttachment', 'r') as infile:
            email_file = email.message_from_file(infile)
        unused_attachemnt = get_email_attachment(email_file, 'unused Key')
Exemplo n.º 2
0
def test_get_attachment_with_multiples():
    """
    Tests that multiple files raises a UserWarning. Emails can only be parsed when they have one
    attachment.
    """
    with pytest.raises(UserWarning):
        with open(EMAIL_FILES_ROOT + 'multipleFiles', 'r') as infile:
            email_file = email.message_from_file(infile)
        unused_attachment = get_email_attachment(email_file, 'unused Key')
Exemplo n.º 3
0
def test_get_attachment_no_content():
    """
    Tests emails that are sent without content. Includes signature and no signature.
    **Note** in testing a completely blank email has the content of `\r\n`.
    """
    for no_content_email in ['noContent', 'noContent2']:
        with open(EMAIL_FILES_ROOT + no_content_email, 'r') as infile:
            email_file = email.message_from_file(infile)
        raw_attachment = get_email_attachment(email_file, 'unused Key')
        assert raw_attachment
        assert isinstance(raw_attachment, email.message.Message)
Exemplo n.º 4
0
def test_emails_with_forwarding():
    """
    Tests emails that have been forwarded have identical payload structures to single recipient
    messages. The following emails have been directly forwarded or forwarded twice.
    """
    for forwarded_email in ['forwarded', 'secondForward']:
        with open(EMAIL_FILES_ROOT + forwarded_email, 'r') as infile:
            email_file = email.message_from_file(infile)
        raw_attachment = get_email_attachment(email_file, 'unused Key')
        assert raw_attachment
        assert isinstance(raw_attachment, email.message.Message)
Exemplo n.º 5
0
def test_get_email_attachment_with_content():
    """
    Asserts that with valid emails we are able to parse out a raw attachment of
    email.message.Message.
    """
    for electronic_mail in VALID_EMAILS:
        with open(electronic_mail, 'r') as infile:
            email_file = email.message_from_file(infile)
        raw_attachment = get_email_attachment(email_file, 'unused Key')
        print raw_attachment.get_filename()
        assert raw_attachment
        assert isinstance(raw_attachment, email.message.Message)
Exemplo n.º 6
0
def test_lambda_handler(token_fixture, talent_pool_fixture, user_fixture):
    """
    Test that after we've validated our inputs we can communicate with the resume parsing service.
    :param token_fixture:
    :param talent_pool_fixture:
    :param user_fixture:
    """
    add_role_to_test_user(user_fixture, [
        Permission.PermissionNames.CAN_ADD_CANDIDATES,
        Permission.PermissionNames.CAN_GET_TALENT_POOLS,
        Permission.PermissionNames.CAN_GET_CANDIDATES
    ])
    with open(EMAIL_FILES_ROOT + 'valid1', 'r') as infile:
        email_file = email.message_from_file(infile)
    raw_attachment = get_email_attachment(email_file, 'unused Key')
    send_resume_to_service(token_fixture.access_token, raw_attachment,
                           talent_pool_fixture.id, 'test')

    with open(EMAIL_FILES_ROOT + 'nestedAttachment', 'r') as infile:
        email_file = email.message_from_file(infile)
    raw_attachment = get_email_attachment(email_file, 'unused Key')
    send_resume_to_service(token_fixture.access_token, raw_attachment,
                           talent_pool_fixture.id, 'test')