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
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
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
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 """ )