Exemplo n.º 1
0
def mock_email():
    from unittest.mock import patch
    from MailListenerV2 import Email
    with patch.object(Email, '__init__', lambda a, b, c, d, e: None):
        email = Email('data', False, False, 0)
        email.id = 0
        email.date = 0
        return email
Exemplo n.º 2
0
def test_generate_labels():
    """
        Given:
        - Bytes representation of a mail

        When:
        - Generating mail labels

        Then:
        - Validate all expected labels are in the generated labels
    """
    from MailListenerV2 import Email
    email = Email(MAIL_STRING, False, False, 0)
    labels = email._generate_labels()
    for label in EXPECTED_LABELS:
        assert label in labels, f'Label {label} was not found in the generated labels, {labels}'
Exemplo n.º 3
0
def test_convert_to_incident():
    """
    Given:
        - Bytes representation of a mail

        When:
        - Parsing it to incidents

        Then:
        - Validate the 'attachments', 'occurred', 'details' and 'name' fields are parsed as expected
    """
    from MailListenerV2 import Email
    email = Email(MAIL_STRING, False, False, 0)
    incident = email.convert_to_incident()
    assert incident['attachment'] == []
    assert incident['occurred'] == email.date.isoformat()
    assert incident['details'] == email.text or email.html
    assert incident['name'] == email.subject