示例#1
0
def test_format():
    '''Test formatted log result is as expected.'''
    log = Log(
        timestamp=123456789,
        name='test.log',
        message='A message',
        level='info')
    template = Email('Test', '*****@*****.**', '*****@*****.**')
    data = template.format([log])
    assert len(data) == 1

    datum = data[0]
    assert isinstance(datum, Message)
    assert datum['Subject'] == 'Test'
    assert datum['From'] == '*****@*****.**'
    assert datum['To'] == '*****@*****.**'
    assert datum.is_multipart() is True

    html = datum.get_payload(1)
    assert html.get_payload() == '''
<html>
    <body>
        <h1>Logs</h1>
        <span class='info'>
            123456789:test.log:A message
        </span><br/>
    </body>
</html>
'''

    text = datum.get_payload(0)
    assert text.get_payload() == '''# Logs
示例#2
0
def test_callable(key, value):
    """Test callable"""
    kwargs = {"subject": "Test", "sender": "*****@*****.**", "recipients": "*****@*****.**"}
    kwargs[key] = lambda logs: value

    template = Email(**kwargs)
    log = Log()
    data = template.format([log])
    assert len(data) == 1

    datum = data[0]
    mapping = {"subject": "Subject", "sender": "From", "recipients": "To"}
    assert datum[mapping[key]] == value
示例#3
0
def test_callable(key, value):
    '''Test callable'''
    kwargs = {
        'subject': 'Test',
        'sender': '*****@*****.**',
        'recipients': '*****@*****.**'
    }
    kwargs[key] = lambda logs: value

    template = Email(**kwargs)
    log = Log()
    data = template.format([log])
    assert len(data) == 1

    datum = data[0]
    mapping = {'subject': 'Subject', 'sender': 'From', 'recipients': 'To'}
    assert datum[mapping[key]] == value
示例#4
0
def test_format():
    """Test formatted log result is as expected."""
    log = Log(timestamp=123456789, name="test.log", message="A message", level="info")
    template = Email("Test", "*****@*****.**", "*****@*****.**")
    data = template.format([log])
    assert len(data) == 1

    datum = data[0]
    assert isinstance(datum, Message)
    assert datum["Subject"] == "Test"
    assert datum["From"] == "*****@*****.**"
    assert datum["To"] == "*****@*****.**"
    assert datum.is_multipart() is True

    html = datum.get_payload(1)
    assert (
        html.get_payload()
        == """
<html>
    <body>
        <h1>Logs</h1>
        <span class='info'>
            123456789:test.log:A message
        </span><br/>
    </body>
</html>
"""
    )

    text = datum.get_payload(0)
    assert (
        text.get_payload()
        == """# Logs

123456789:test.log:A message  

"""
    )